Leaflet Blog in Deno Fresh
1import { AppBskyFeedPost, type AppBskyFeedDefs } from 'npm:@atproto/api';
2
3const MinLikeCountFilter = (
4 min: number
5): ((comment: AppBskyFeedDefs.ThreadViewPost) => boolean) => {
6 return (comment: AppBskyFeedDefs.ThreadViewPost) => {
7 return (comment.post.likeCount ?? 0) < min;
8 };
9};
10
11const MinCharacterCountFilter = (
12 min: number
13): ((comment: AppBskyFeedDefs.ThreadViewPost) => boolean) => {
14 return (comment: AppBskyFeedDefs.ThreadViewPost) => {
15 if (!AppBskyFeedPost.isRecord(comment.post.record)) {
16 return false;
17 }
18 const record = comment.post.record as AppBskyFeedPost.Record;
19 return record.text.length < min;
20 };
21};
22
23const TextContainsFilter = (
24 text: string
25): ((comment: AppBskyFeedDefs.ThreadViewPost) => boolean) => {
26 return (comment: AppBskyFeedDefs.ThreadViewPost) => {
27 if (!AppBskyFeedPost.isRecord(comment.post.record)) {
28 return false;
29 }
30 const record = comment.post.record as AppBskyFeedPost.Record;
31 return record.text.toLowerCase().includes(text.toLowerCase());
32 };
33};
34
35const ExactMatchFilter = (
36 text: string
37): ((comment: AppBskyFeedDefs.ThreadViewPost) => boolean) => {
38 return (comment: AppBskyFeedDefs.ThreadViewPost) => {
39 if (!AppBskyFeedPost.isRecord(comment.post.record)) {
40 return false;
41 }
42 const record = comment.post.record as AppBskyFeedPost.Record;
43 return record.text.toLowerCase() === text.toLowerCase();
44 };
45};
46
47/*
48* This function allows you to filter out comments based on likes,
49* characters, text, pins, or exact matches.
50*/
51export const Filters: {
52 MinLikeCountFilter: (min: number) => (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
53 MinCharacterCountFilter: (min: number) => (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
54 TextContainsFilter: (text: string) => (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
55 ExactMatchFilter: (text: string) => (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
56 NoLikes: (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
57 NoPins: (comment: AppBskyFeedDefs.ThreadViewPost) => boolean;
58} = {
59 MinLikeCountFilter,
60 MinCharacterCountFilter,
61 TextContainsFilter,
62 ExactMatchFilter,
63 NoLikes: MinLikeCountFilter(0),
64 NoPins: ExactMatchFilter('📌'),
65};
66
67export default Filters;