···11+# Example: Popular
22+33+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.
44+55+## Instructions
66+77+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`
88+2. Review the `popular.rhai` file to see how the algorithm works.
+7
examples/popular/config.yml
···11+feeds:
22+- uri: "ATURI"
33+ name: "Popular"
44+ description: "Popular posts with the tag #Supercell."
55+ matchers:
66+ - type: rhai
77+ script: "/path/to/popular.rhai"
+47
examples/popular/popular.rhai
···11+let rtype = event?.commit?.record?["$type"];
22+33+// If the event is for a like, use the AT-URI in the record subject to
44+// increment the score of any existing feed_content records.
55+if rtype == "app.bsky.feed.like" {
66+ return update_match(build_aturi(event));
77+}
88+99+// Ignore any record types that aren't posts.
1010+if rtype != "app.bsky.feed.post" {
1111+ return false;
1212+}
1313+1414+// Reject posts where the created at is more than 8 days ago.
1515+// See https://docs.rs/duration-str/latest/duration_str/
1616+if matcher_before_duration("-8d", event?.commit?.record?.createdAt ?? "") {
1717+ return false;
1818+}
1919+2020+// This feed only includes posts that are not replies themselves, but does
2121+// look at replies to adjust the score of root posts.
2222+let parent_uri = event?.commit?.record?.reply?.root?.uri ?? "";
2323+if !parent_uri.is_empty() {
2424+ return parent_uri;
2525+}
2626+2727+for facet in event?.commit?.record?.facets ?? [] {
2828+ for feature in facet?.features ?? [] {
2929+ switch feature?["$type"] {
3030+ "app.bsky.richtext.facet#tag" => {
3131+ let tag = feature?["tag"] ?? "";
3232+ let tag_normalized = tag.to_lower();
3333+ if tag_normalized == "supercell" {
3434+3535+ // If the post is not a reply and has the "#supercell" tag then add
3636+ // it to the feed.
3737+3838+ return build_aturi(event);
3939+4040+ }
4141+ }
4242+ _ => {}
4343+ }
4444+ }
4545+}
4646+4747+false