From 178e091aa11ac440fd563a5082ca0268ff29e17b Mon Sep 17 00:00:00 2001 From: gravel Date: Thu, 1 Jun 2023 16:00:21 +0000 Subject: [PATCH] Implement basic listings --- .gitignore | 3 +++ .phpenv | 3 +++ Makefile | 4 ++++ php/listing-providers/generate-listings.php | 5 ----- php/utils/servers-rooms.php | 13 +++++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) delete mode 100644 php/listing-providers/generate-listings.php diff --git a/.gitignore b/.gitignore index 7bb4750..75327c4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ output/qr-codes # Served icons output/icons +# Served listings +listings/lp-output + # Server-side cache cache diff --git a/.phpenv b/.phpenv index 0ee1220..ea74889 100644 --- a/.phpenv +++ b/.phpenv @@ -12,7 +12,10 @@ $ROOM_ICONS_RELATIVE="icons"; $LISTING_PROVIDER_ROOT="$PROJECT_ROOT/listings"; + $LISTINGS_INI="$LISTING_PROVIDER_ROOT/listings.ini"; $LISTING_PROVIDER_OUTPUT="$LISTING_PROVIDER_ROOT/lp-output"; + $LISTING_PROVIDER_LISTING_SUMMARY="$LISTING_PROVIDER_OUTPUT/listings"; + $LISTING_PROVIDER_LISTINGS="$LISTING_PROVIDER_OUTPUT/listing"; $REPOSITORY_CANONICAL_URL="https://codeberg.org/gravel/sessioncommunities.online"; diff --git a/Makefile b/Makefile index 627653e..87a57dd 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,10 @@ fetch: html: /bin/php php/generate-html.php $(FLAGS) +# Generate listing provider endpoints from data. +listing: + /bin/php php/generate-listings.php $(FLAGS) + # Serve a local copy which responds to file changes. dev: FLAGS = --verbose dev: open diff --git a/php/listing-providers/generate-listings.php b/php/listing-providers/generate-listings.php deleted file mode 100644 index 6fef4ab..0000000 --- a/php/listing-providers/generate-listings.php +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index cf96858..7edf421 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -113,6 +113,19 @@ return $details; } + /** + * Return information for JSON serialization in listing. + */ + function to_listing_data(): array { + $details = get_object_vars($this); + $details['join_url'] = $this->get_join_url(); + $details['tags'] = array_map(function(\CommunityTag $tag) { + return $tag->text; + }, $this->tags); + unset($details['message_sequence']); + return $details; + } + /** * Create a CommunityRoom instance from loaded data. * @param CommunityServer $server