Skip to content

Commit c9761fd

Browse files
upgrade loaders ergonomics
1 parent 9439b7a commit c9761fd

29 files changed

Lines changed: 7839 additions & 649 deletions

astro-atproto-loader/README.md

Lines changed: 271 additions & 55 deletions
Large diffs are not rendered by default.

astro-atproto-loader/__examples__/01-static-loaders/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ npm run dev
2222
```
2323

2424
Then open `http://127.0.0.1:4321`.
25+
26+
If you want to inspect the built static output instead, run `npm run build`
27+
and then `npm run preview`.

astro-atproto-loader/__examples__/02-live-loaders/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ live collections.
55

66
It reads public AtProto badge records from `atmosphereconf.org` and the
77
Streamplace data from `essentialrandom.bsky.social` and shows them
8-
on a page with `getLiveCollection()`. The data is collected at the time of
9-
requested, and re-fetched periodically.
8+
on a page with `getLiveCollection()`. The data is collected at request time
9+
and re-fetched periodically.
10+
11+
> [!IMPORTANT]
12+
>
13+
> Astro live collections are still experimental. This example needs
14+
> `experimental.liveContentCollections: true` in `astro.config.mjs`, plus a
15+
> server-capable adapter such as `@astrojs/node`, because live collections are
16+
> rendered on demand.
1017
1118
The page uses the loader two ways:
1219

astro-atproto-loader/__examples__/03-grouped-reposts/.gitignore

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Grouped reposts example
2+
3+
This example merges records from several repos into one Astro live collection
4+
by reading `app.bsky.feed.repost` from three Bluesky accounts and grouping
5+
by the URI of the post each one reposted.
6+
7+
The result is a live page of posts that all three of
8+
[`@fujocoded.bsky.social`](https://bsky.app/profile/fujocoded.bsky.social),
9+
[`@fujoweb.dev`](https://bsky.app/profile/fujoweb.dev), and
10+
[`@bobaboard.bsky.social`](https://bsky.app/profile/bobaboard.bsky.social)
11+
reposted, with the original post hydrated for display.
12+
13+
> [!IMPORTANT]
14+
>
15+
> Astro live collections are still experimental. This example needs
16+
> `experimental.liveContentCollections: true` in `astro.config.mjs`, plus a
17+
> server-capable adapter such as `@astrojs/node`, because live collections are
18+
> rendered on demand.
19+
20+
## What's going on
21+
22+
- `sources: [...]` declares one source per account, all reading the same
23+
`app.bsky.feed.repost` collection.
24+
- `parseRecord` runs once per record and drops anything that isn't a
25+
well-formed repost. Today this is hand-rolled Zod for `repost`, `post`,
26+
and `profile`; there is a `TODO` at the top of `src/live.config.ts` to
27+
move record validation onto
28+
[`@atproto/lex`](https://www.npmjs.com/package/@atproto/lex) once its
29+
`BlobRef` schema accepts the JSON wire format directly.
30+
- `groupBy` returns the URI of the post being reposted, so reposts of the
31+
same post end up in the same group.
32+
- The `transform` keeps only groups of size 3, then uses `fetchRecord` to:
33+
- add data from the original post (and pull one image off it, if any)
34+
- add data about the original post author's profile for their display name and
35+
avatar
36+
- add data from each reposter's profile (their display name and avatar)
37+
- Each entry exposes the post text, an optional thumbnail, the author's
38+
identity, and a `repostedBy` list with each reposter's `did`, `handle`,
39+
display name, and avatar URL.
40+
41+
`fetchRecord` caches same-URI requests, so fanning out to fetch profiles per
42+
reposter is cheap even when several entries share a participant.
43+
44+
## Run it
45+
46+
```bash
47+
npm install
48+
npm run dev
49+
```
50+
51+
Then open `http://127.0.0.1:4321`.
52+
53+
If the page is empty, the three accounts haven't reposted the same post
54+
within the most recent page of records.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
import { defineConfig } from "astro/config";
3+
import node from "@astrojs/node";
4+
5+
export default defineConfig({
6+
output: "server",
7+
adapter: node({
8+
mode: "standalone",
9+
}),
10+
experimental: {
11+
liveContentCollections: true,
12+
},
13+
});

0 commit comments

Comments
 (0)