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

Commit 2a83d1c

Browse files
committed
Multiple feed support, resolves #3
1 parent 4bf1885 commit 2a83d1c

13 files changed

+351
-73
lines changed

.github/workflows/02-deploy-to-cloudflare.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- name: Render Config
2020
run: |
21-
python render-config.py
21+
python render-configs.py
2222
- name: Deploy Cloudflare Worker
2323
uses: cloudflare/[email protected]
2424
with:

.github/workflows/03-publish-feed-generator.yml renamed to .github/workflows/03-publish-feed-generators.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 3. Publish Feed Generator
2-
run-name: Publish Feed Generator
1+
name: 3. Publish Feed Generators
2+
run-name: Publish Feed Generators
33

44
on:
55
workflow_dispatch:
@@ -13,9 +13,9 @@ env:
1313
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}
1414

1515
jobs:
16-
publish_feed_generator:
16+
publish_feed_generators:
1717
runs-on: ubuntu-latest
18-
name: Publish Feed Generator
18+
name: Publish Feed Generators
1919
steps:
2020
- name: Get Cloudflare Worker Subdomain
2121
run: |
@@ -32,11 +32,11 @@ jobs:
3232
- uses: actions/checkout@v3
3333
- name: Render Config
3434
run: |
35-
python render-config.py
35+
python render-configs.py
3636
- uses: actions/setup-node@v3
37-
- name: Publish Feed Generator
37+
- name: Publish Feed Generators
3838
run: |
3939
cd feed-generator/
4040
npm install
4141
env | grep -E 'FEEDGEN'
42-
yarn publishFeedGenerator
42+
yarn publishFeedGenerators

cloudflare-worker/worker.js

+81-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
// let's be nice
33
const MAX_SEARCH_TERMS = 5;
4+
const DEFAULT_LIMIT = 40;
45

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

3839
async function getFeedSkeleton(request) {
39-
let searchTerms = CONFIG.searchTerms.slice(0, MAX_SEARCH_TERMS);
40+
let url = new URL(request.url);
41+
let feedAtUrl = url.searchParams.get("feed");
42+
if (feedAtUrl === null) {
43+
console.warn(`feed parameter missing from query string`);
44+
return feedJsonResponse([]);
45+
}
46+
let words = feedAtUrl.split("/");
47+
let feedId = words[words.length - 1];
48+
let config = CONFIGS[feedId];
49+
50+
if (config === undefined) {
51+
console.warn(`Could not find Feed ID ${feedId}`);
52+
return feedJsonResponse([]);
53+
}
54+
55+
let limit = parseInt(url.searchParams.get("limit"));
56+
if (limit === null || limit === undefined || limit < 1) {
57+
limit = DEFAULT_LIMIT;
58+
}
59+
60+
let searchTerms = config.searchTerms.slice(0, MAX_SEARCH_TERMS);
4061
let responsePromises = [];
4162

4263
for (let searchTerm of searchTerms) {
@@ -64,14 +85,18 @@ async function getFeedSkeleton(request) {
6485
}
6586

6687
timestampURLs = timestampURLs.toSorted((b, a) => (a === b) ? 0 : (a < b) ? -1 : 1);
67-
68-
let rv = { feed: [] };
88+
var feed = [];
6989
for (let timestampUrl of timestampURLs) {
7090
let atUrl = timestampUrl[1];
71-
rv.feed.push({ post : atUrl });
91+
feed.push({ post : atUrl });
7292
}
93+
// TODO apply this after adding pagination support
94+
// feed = feed.slice(0, limit);
95+
return feedJsonResponse(feed);
96+
}
7397

74-
return jsonResponse(rv);
98+
function feedJsonResponse(items) {
99+
return jsonResponse({ feed: items });
75100
}
76101

77102
export default {
@@ -88,18 +113,55 @@ export default {
88113
},
89114
};
90115

91-
// CONFIG
92-
93-
const CONFIG = {
94-
"recordName": "emotional-suppo",
95-
"displayName": "Emotional Support Pets",
96-
"description": "Cute animals feed",
97-
"searchTerms": [
98-
"cats",
99-
"dogs",
100-
"penguins",
101-
"red pandas",
102-
"quokkas"
103-
],
104-
"avatar": "avatar.png"
116+
// CONFIGS
117+
118+
const CONFIGS = {
119+
"emotional-suppo": {
120+
"recordName": "emotional-suppo",
121+
"displayName": "Emotional Support Pets",
122+
"description": "Cute animals feed",
123+
"searchTerms": [
124+
"cats",
125+
"dogs",
126+
"penguins",
127+
"red pandas",
128+
"quokkas"
129+
],
130+
"avatar": "avatar.png",
131+
"isEnabled": true
132+
},
133+
"science-emojis": {
134+
"recordName": "science-emojis",
135+
"isEnabled": false,
136+
"displayName": "Science Emojis",
137+
"description": "Posts with \ud83e\uddea\ud83e\udd7c\ud83d\udd2d",
138+
"searchTerms": [
139+
"\ud83e\uddea",
140+
"\ud83e\udd7c",
141+
"\ud83d\udd2d"
142+
],
143+
"avatar": "configs/avatar2.png"
144+
},
145+
"gaming-emojis": {
146+
"recordName": "gaming-emojis",
147+
"isEnabled": false,
148+
"displayName": "Gaming Emojis",
149+
"description": "Posts with \ud83d\udc7e\ud83c\udfae\ud83d\udd79\ufe0f",
150+
"searchTerms": [
151+
"\ud83d\udc7e",
152+
"\ud83c\udfae",
153+
"\ud83d\udd79\ufe0f"
154+
],
155+
"avatar": "configs/avatar2.png"
156+
},
157+
"basketball-emoj": {
158+
"recordName": "basketball-emoj",
159+
"isEnabled": false,
160+
"displayName": "Basketball Emojis",
161+
"description": "Posts with \ud83c\udfc0",
162+
"searchTerms": [
163+
"\ud83c\udfc0"
164+
],
165+
"avatar": "configs/avatar2.png"
166+
}
105167
}

configs/BASKETBALL_EMOJIS.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# recordName
3+
4+
> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
5+
6+
basketball-emojis
7+
8+
# isEnabled
9+
10+
> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
11+
12+
false
13+
14+
# displayName
15+
16+
> This is the title of the custom feed. Maximum length is 24 characters.
17+
18+
Basketball Emojis
19+
20+
# description
21+
22+
> This is the description of the feed.
23+
24+
Posts with 🏀
25+
26+
# searchTerms
27+
28+
> 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"`.
29+
30+
- 🏀
31+
32+
# avatar
33+
34+
> 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.
35+
36+
![](avatar2.png)

configs/GAMING_EMOJIS.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# recordName
3+
4+
> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
5+
6+
gaming-emojis
7+
8+
# isEnabled
9+
10+
> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
11+
12+
false
13+
14+
# displayName
15+
16+
> This is the title of the custom feed. Maximum length is 24 characters.
17+
18+
Gaming Emojis
19+
20+
# description
21+
22+
> This is the description of the feed.
23+
24+
Posts with 👾🎮🕹️
25+
26+
# searchTerms
27+
28+
> 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"`.
29+
30+
- 👾
31+
- 🎮
32+
- 🕹️
33+
34+
# avatar
35+
36+
> 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.
37+
38+
![](avatar2.png)

configs/SCIENCE_EMOJIS.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# recordName
3+
4+
> This is the feed's ID which can be letters, numbers, or dashes. Spaces are not allowed. Maximum length is 15 characters.
5+
6+
science-emojis
7+
8+
# isEnabled
9+
10+
> Whether this feed should be published by the "Publish Feed Generators" step. Set to `true` or `false`.
11+
12+
false
13+
14+
# displayName
15+
16+
> This is the title of the custom feed. Maximum length is 24 characters.
17+
18+
Science Emojis
19+
20+
# description
21+
22+
> This is the description of the feed.
23+
24+
Posts with 🧪🥼🔭
25+
26+
# searchTerms
27+
28+
> 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"`.
29+
30+
- 🧪
31+
- 🥼
32+
- 🔭
33+
34+
# avatar
35+
36+
> 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.
37+
38+
![](avatar2.png)

configs/avatar2.png

201 KB
Loading

feed-generator/avatar.png

-1
This file was deleted.

feed-generator/config.json

+44-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
{
2-
"recordName": "emotional-suppo",
3-
"displayName": "Emotional Support Pets",
4-
"description": "Cute animals feed",
5-
"searchTerms": [
6-
"cats",
7-
"dogs",
8-
"penguins",
9-
"red pandas",
10-
"quokkas"
11-
],
12-
"avatar": "avatar.png"
2+
"emotional-suppo": {
3+
"recordName": "emotional-suppo",
4+
"displayName": "Emotional Support Pets",
5+
"description": "Cute animals feed",
6+
"searchTerms": [
7+
"cats",
8+
"dogs",
9+
"penguins",
10+
"red pandas",
11+
"quokkas"
12+
],
13+
"avatar": "avatar.png"
14+
},
15+
"science-emojis": {
16+
"recordName": "science-emojis",
17+
"displayName": "Science Emojis",
18+
"description": "Posts with \ud83e\uddea\ud83e\udd7c\ud83d\udd2d",
19+
"searchTerms": [
20+
"\ud83e\uddea",
21+
"\ud83e\udd7c",
22+
"\ud83d\udd2d"
23+
],
24+
"avatar": "avatar.png"
25+
},
26+
"gaming-emojis": {
27+
"recordName": "gaming-emojis",
28+
"displayName": "Gaming Emojis",
29+
"description": "Posts with \ud83d\udc7e\ud83c\udfae\ud83d\udd79\ufe0f",
30+
"searchTerms": [
31+
"\ud83d\udc7e",
32+
"\ud83c\udfae",
33+
"\ud83d\udd79\ufe0f"
34+
],
35+
"avatar": "avatar.png"
36+
},
37+
"basketball-emoj": {
38+
"recordName": "basketball-emoj",
39+
"displayName": "Basketball Emojis",
40+
"description": "Posts with \ud83c\udfc0",
41+
"searchTerms": [
42+
"\ud83c\udfc0"
43+
],
44+
"avatar": "avatar.png"
45+
}
1346
}

0 commit comments

Comments
 (0)