Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Multiple feed support, resolves #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsalterego committed Jun 8, 2023
1 parent 4bf1885 commit 2a83d1c
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/02-deploy-to-cloudflare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- name: Render Config
run: |
python render-config.py
python render-configs.py
- name: Deploy Cloudflare Worker
uses: cloudflare/wrangler-action@2.0.0
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 3. Publish Feed Generator
run-name: Publish Feed Generator
name: 3. Publish Feed Generators
run-name: Publish Feed Generators

on:
workflow_dispatch:
Expand All @@ -13,9 +13,9 @@ env:
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}

jobs:
publish_feed_generator:
publish_feed_generators:
runs-on: ubuntu-latest
name: Publish Feed Generator
name: Publish Feed Generators
steps:
- name: Get Cloudflare Worker Subdomain
run: |
Expand All @@ -32,11 +32,11 @@ jobs:
- uses: actions/checkout@v3
- name: Render Config
run: |
python render-config.py
python render-configs.py
- uses: actions/setup-node@v3
- name: Publish Feed Generator
- name: Publish Feed Generators
run: |
cd feed-generator/
npm install
env | grep -E 'FEEDGEN'
yarn publishFeedGenerator
yarn publishFeedGenerators
100 changes: 81 additions & 19 deletions cloudflare-worker/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// let's be nice
const MAX_SEARCH_TERMS = 5;
const DEFAULT_LIMIT = 40;

const DID_JSON = {
"@context": ["https://www.w3.org/ns/did/v1"],
Expand Down Expand Up @@ -36,7 +37,27 @@ function jsonResponse(obj) {
}

async function getFeedSkeleton(request) {
let searchTerms = CONFIG.searchTerms.slice(0, MAX_SEARCH_TERMS);
let url = new URL(request.url);
let feedAtUrl = url.searchParams.get("feed");
if (feedAtUrl === null) {
console.warn(`feed parameter missing from query string`);
return feedJsonResponse([]);
}
let words = feedAtUrl.split("/");
let feedId = words[words.length - 1];
let config = CONFIGS[feedId];

if (config === undefined) {
console.warn(`Could not find Feed ID ${feedId}`);
return feedJsonResponse([]);
}

let limit = parseInt(url.searchParams.get("limit"));
if (limit === null || limit === undefined || limit < 1) {
limit = DEFAULT_LIMIT;
}

let searchTerms = config.searchTerms.slice(0, MAX_SEARCH_TERMS);
let responsePromises = [];

for (let searchTerm of searchTerms) {
Expand Down Expand Up @@ -64,14 +85,18 @@ async function getFeedSkeleton(request) {
}

timestampURLs = timestampURLs.toSorted((b, a) => (a === b) ? 0 : (a < b) ? -1 : 1);

let rv = { feed: [] };
var feed = [];
for (let timestampUrl of timestampURLs) {
let atUrl = timestampUrl[1];
rv.feed.push({ post : atUrl });
feed.push({ post : atUrl });
}
// TODO apply this after adding pagination support
// feed = feed.slice(0, limit);
return feedJsonResponse(feed);
}

return jsonResponse(rv);
function feedJsonResponse(items) {
return jsonResponse({ feed: items });
}

export default {
Expand All @@ -88,18 +113,55 @@ export default {
},
};

// CONFIG

const CONFIG = {
"recordName": "emotional-suppo",
"displayName": "Emotional Support Pets",
"description": "Cute animals feed",
"searchTerms": [
"cats",
"dogs",
"penguins",
"red pandas",
"quokkas"
],
"avatar": "avatar.png"
// CONFIGS

const CONFIGS = {
"emotional-suppo": {
"recordName": "emotional-suppo",
"displayName": "Emotional Support Pets",
"description": "Cute animals feed",
"searchTerms": [
"cats",
"dogs",
"penguins",
"red pandas",
"quokkas"
],
"avatar": "avatar.png",
"isEnabled": true
},
"science-emojis": {
"recordName": "science-emojis",
"isEnabled": false,
"displayName": "Science Emojis",
"description": "Posts with \ud83e\uddea\ud83e\udd7c\ud83d\udd2d",
"searchTerms": [
"\ud83e\uddea",
"\ud83e\udd7c",
"\ud83d\udd2d"
],
"avatar": "configs/avatar2.png"
},
"gaming-emojis": {
"recordName": "gaming-emojis",
"isEnabled": false,
"displayName": "Gaming Emojis",
"description": "Posts with \ud83d\udc7e\ud83c\udfae\ud83d\udd79\ufe0f",
"searchTerms": [
"\ud83d\udc7e",
"\ud83c\udfae",
"\ud83d\udd79\ufe0f"
],
"avatar": "configs/avatar2.png"
},
"basketball-emoj": {
"recordName": "basketball-emoj",
"isEnabled": false,
"displayName": "Basketball Emojis",
"description": "Posts with \ud83c\udfc0",
"searchTerms": [
"\ud83c\udfc0"
],
"avatar": "configs/avatar2.png"
}
}
36 changes: 36 additions & 0 deletions configs/BASKETBALL_EMOJIS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# recordName

> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
basketball-emojis

# isEnabled

> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
false

# displayName

> This is the title of the custom feed. Maximum length is 24 characters.
Basketball Emojis

# description

> This is the description of the feed.
Posts with 🏀

# searchTerms

> Maximum of five search terms. Test these in [https://bsky.app/search](https://bsky.app/search). `AND` is implicit, so `cat dog` on one line will require both `cat` and `dog`. You can use quotes as well `"hot dog"`.
- 🏀

# avatar

> This must link to an image (PNG or JPEG) in the same directory as this CONFIG.md. It doesn't have to be called `avatar2.png`, but just be sure this CONFIG.md points to the correct file.
![](avatar2.png)
38 changes: 38 additions & 0 deletions configs/GAMING_EMOJIS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# recordName

> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
gaming-emojis

# isEnabled

> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
false

# displayName

> This is the title of the custom feed. Maximum length is 24 characters.
Gaming Emojis

# description

> This is the description of the feed.
Posts with 👾🎮🕹️

# searchTerms

> Maximum of five search terms. Test these in [https://bsky.app/search](https://bsky.app/search). `AND` is implicit, so `cat dog` on one line will require both `cat` and `dog`. You can use quotes as well `"hot dog"`.
- 👾
- 🎮
- 🕹️

# avatar

> This must link to an image (PNG or JPEG) in the same directory as this CONFIG.md. It doesn't have to be called `avatar2.png`, but just be sure this CONFIG.md points to the correct file.
![](avatar2.png)
38 changes: 38 additions & 0 deletions configs/SCIENCE_EMOJIS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# recordName

> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
science-emojis

# isEnabled

> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
false

# displayName

> This is the title of the custom feed. Maximum length is 24 characters.
Science Emojis

# description

> This is the description of the feed.
Posts with 🧪🥼🔭

# searchTerms

> Maximum of five search terms. Test these in [https://bsky.app/search](https://bsky.app/search). `AND` is implicit, so `cat dog` on one line will require both `cat` and `dog`. You can use quotes as well `"hot dog"`.
- 🧪
- 🥼
- 🔭

# avatar

> This must link to an image (PNG or JPEG) in the same directory as this CONFIG.md. It doesn't have to be called `avatar2.png`, but just be sure this CONFIG.md points to the correct file.
![](avatar2.png)
Binary file added configs/avatar2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion feed-generator/avatar.png

This file was deleted.

55 changes: 44 additions & 11 deletions feed-generator/config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
{
"recordName": "emotional-suppo",
"displayName": "Emotional Support Pets",
"description": "Cute animals feed",
"searchTerms": [
"cats",
"dogs",
"penguins",
"red pandas",
"quokkas"
],
"avatar": "avatar.png"
"emotional-suppo": {
"recordName": "emotional-suppo",
"displayName": "Emotional Support Pets",
"description": "Cute animals feed",
"searchTerms": [
"cats",
"dogs",
"penguins",
"red pandas",
"quokkas"
],
"avatar": "avatar.png"
},
"science-emojis": {
"recordName": "science-emojis",
"displayName": "Science Emojis",
"description": "Posts with \ud83e\uddea\ud83e\udd7c\ud83d\udd2d",
"searchTerms": [
"\ud83e\uddea",
"\ud83e\udd7c",
"\ud83d\udd2d"
],
"avatar": "avatar.png"
},
"gaming-emojis": {
"recordName": "gaming-emojis",
"displayName": "Gaming Emojis",
"description": "Posts with \ud83d\udc7e\ud83c\udfae\ud83d\udd79\ufe0f",
"searchTerms": [
"\ud83d\udc7e",
"\ud83c\udfae",
"\ud83d\udd79\ufe0f"
],
"avatar": "avatar.png"
},
"basketball-emoj": {
"recordName": "basketball-emoj",
"displayName": "Basketball Emojis",
"description": "Posts with \ud83c\udfc0",
"searchTerms": [
"\ud83c\udfc0"
],
"avatar": "avatar.png"
}
}
Loading

0 comments on commit 2a83d1c

Please sign in to comment.