From a3708dd8f0c3822ac997434a2583221a2f0f40e7 Mon Sep 17 00:00:00 2001 From: Nick Gerakines <12125+ngerakines@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:06:37 -0500 Subject: [PATCH] documentation: Added popular feed example Signed-off-by: Nick Gerakines <12125+ngerakines@users.noreply.github.com> --- examples/popular/README.md | 8 ++++++ examples/popular/config.yml | 7 ++++++ examples/popular/popular.rhai | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 examples/popular/README.md create mode 100644 examples/popular/config.yml create mode 100644 examples/popular/popular.rhai diff --git a/examples/popular/README.md b/examples/popular/README.md new file mode 100644 index 0000000..17d21a4 --- /dev/null +++ b/examples/popular/README.md @@ -0,0 +1,8 @@ +# Example: Popular + +This configuration file includes a feed that watches for posts with a tag. The feed is then sorted by a simple "popular" algorithm that takes into account the number of likes, replies, and quotes. + +## Instructions + +1. Create the feed and replace `ATURI` with the full record AT-URI. Should look like `at://YOUR_DID/app.bsky.feed.generator/some_rkey` +2. Review the `popular.rhai` file to see how the algorithm works. diff --git a/examples/popular/config.yml b/examples/popular/config.yml new file mode 100644 index 0000000..569d312 --- /dev/null +++ b/examples/popular/config.yml @@ -0,0 +1,7 @@ +feeds: +- uri: "ATURI" + name: "Popular" + description: "Popular posts with the tag #Supercell." + matchers: + - type: rhai + script: "/path/to/popular.rhai" diff --git a/examples/popular/popular.rhai b/examples/popular/popular.rhai new file mode 100644 index 0000000..f890217 --- /dev/null +++ b/examples/popular/popular.rhai @@ -0,0 +1,47 @@ +let rtype = event?.commit?.record?["$type"]; + +// If the event is for a like, use the AT-URI in the record subject to +// increment the score of any existing feed_content records. +if rtype == "app.bsky.feed.like" { + return update_match(build_aturi(event)); +} + +// Ignore any record types that aren't posts. +if rtype != "app.bsky.feed.post" { + return false; +} + +// Reject posts where the created at is more than 8 days ago. +// See https://docs.rs/duration-str/latest/duration_str/ +if matcher_before_duration("-8d", event?.commit?.record?.createdAt ?? "") { + return false; +} + +// This feed only includes posts that are not replies themselves, but does +// look at replies to adjust the score of root posts. +let parent_uri = event?.commit?.record?.reply?.root?.uri ?? ""; +if !parent_uri.is_empty() { + return parent_uri; +} + +for facet in event?.commit?.record?.facets ?? [] { + for feature in facet?.features ?? [] { + switch feature?["$type"] { + "app.bsky.richtext.facet#tag" => { + let tag = feature?["tag"] ?? ""; + let tag_normalized = tag.to_lower(); + if tag_normalized == "supercell" { + + // If the post is not a reply and has the "#supercell" tag then add + // it to the feed. + + return build_aturi(event); + + } + } + _ => {} + } + } +} + +false -- 2.51.2