Skip to content

Commit 5d9dd09

Browse files
committed
Add custom collections cookbook
Add an in-repository custom collections example that keeps the bookmark domain small and focuses on dispatcher patterns. The example shows cursor-based pagination, URI template filtering, actor collection links, and requester-aware followers-only collections. Link the manual's custom collections section to the runnable example and add a changelog entry for the accepted issue. #694 Assisted-by: Codex:gpt-5.5
1 parent 2ba4d27 commit 5d9dd09

4 files changed

Lines changed: 376 additions & 105 deletions

File tree

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,23 @@ To be released.
225225
redistribution that threadiverse software (Lemmy, Mbin, NodeBB) uses to fan
226226
activity out to every subscriber. [[#704], [#710]]
227227

228+
- Added a custom collections cookbook example for bookmark-like data,
229+
demonstrating cursor pagination, URI-template filtering, collection
230+
counters, actor collection links, and requester-aware collections using
231+
`ctx.getSignedKeyOwner()`. [[#694], [#722]]
232+
228233
[*Building a federated blog* tutorial]: https://fedify.dev/tutorial/astro-blog
229234
[Astro]: https://astro.build/
230235
[Bun]: https://bun.sh/
231236
[*Building a threadiverse community platform*]: https://fedify.dev/tutorial/threadiverse
232237
[*Creating your own federated microblog*]: https://fedify.dev/tutorial/microblog
233238
[#691]: https://github.com/fedify-dev/fedify/issues/691
239+
[#694]: https://github.com/fedify-dev/fedify/issues/694
234240
[#695]: https://github.com/fedify-dev/fedify/pull/695
235241
[#704]: https://github.com/fedify-dev/fedify/issues/704
236242
[#706]: https://github.com/fedify-dev/fedify/issues/706
237243
[#715]: https://github.com/fedify-dev/fedify/pull/715
244+
[#722]: https://github.com/fedify-dev/fedify/pull/722
238245

239246

240247
Version 2.1.10

docs/manual/collections.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,17 @@ followers, Fedify allows you to create custom collections for your specific
13961396
needs. Custom collections can be used to expose any type of ActivityPub
13971397
objects in a paginated manner.
13981398

1399+
For runnable code that compares several custom collection patterns, see the
1400+
[custom collections example].
1401+
13991402
There are two types of custom collections you can create:
14001403

14011404
- **Collection**: An unordered collection of objects
14021405
- **Ordered Collection**: An ordered collection of objects where the order
14031406
matters
14041407

1408+
[custom collections example]: https://github.com/fedify-dev/fedify/tree/main/examples/custom-collections
1409+
14051410
### Setting up a custom collection
14061411

14071412
To create a custom collection, you use either `setCollectionDispatcher()` for
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
Custom collections example
22
==========================
33

4-
This example demonstrates how to implement custom collections in Fedify.
5-
Custom collections allow you to define your own ActivityPub collections with
6-
custom logic for dispatching items and counting collection sizes.
4+
This example is a small cookbook for custom ActivityPub collections in Fedify.
5+
It uses a single-user bookmark log as the domain, but the important part is
6+
how each collection dispatcher maps server-side data to an ActivityPub
7+
collection.
8+
9+
The script demonstrates three patterns:
10+
11+
- `/users/alice/collections/public`: a public `OrderedCollection` with
12+
cursor-based pages, `setCounter()`, `setFirstCursor()`, and
13+
`setLastCursor()`.
14+
- `/users/alice/collections/tags/{tag}`: a parameterized collection that
15+
filters bookmarks using a URI template value.
16+
- `/users/alice/collections/followers-only`: a collection whose result
17+
depends on the signed requester. It calls `ctx.getSignedKeyOwner()` and
18+
returns an empty collection to unsigned or non-follower requests.
19+
20+
Run it from this directory:
721

822
~~~~ sh
923
deno task codegen # At very first time only
1024
deno run -A ./main.ts
1125
~~~~
26+
27+
The output prints the actor document, collection metadata responses, and page
28+
responses for the example routes.

0 commit comments

Comments
 (0)