Skip to content

Commit

Permalink
Allow marking feeds NSFW
Browse files Browse the repository at this point in the history
resolves #3
  • Loading branch information
kensand committed Mar 9, 2024
1 parent 5b19fff commit 11250ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"communityName": "the_news",
"instanceUrl": "https://Some.Fake.Lemmy.Instance.URL.abcd1234567890"
}
]
],
"nsfw": true
}
],
"defaultSchedule": {
Expand Down
1 change: 1 addition & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Feed {
readonly linkPrefix?: string;
readonly lemmyCommunities: Community[];
readonly schedule?: SimpleIntervalSchedule;
readonly nsfw?: boolean;
}
export interface Lemmy {
readonly login: Login;
Expand Down
13 changes: 11 additions & 2 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export async function postItem(
c: Community,
item: Parser.Item,
urlPrefix: string | undefined,
title: string
title: string,
nsfw: boolean | undefined
) {
const communityId = (await client.getCommunity({ name: c.communityName }))
.community_view.community.id;
Expand All @@ -52,6 +53,7 @@ export async function postItem(
community_id: communityId,
url: link,
name: title,
nsfw: nsfw,
body: `${titleLink}${NodeHtmlMarkdown.translate(
item.content ?? item.contentSnippet ?? item.summary ?? "",
{},
Expand Down Expand Up @@ -100,7 +102,14 @@ export function mkFeedTask(
);
await Promise.all(
feed.lemmyCommunities.map(async (community) => {
await postItem(client, community, item, feed.linkPrefix, title);
await postItem(
client,
community,
item,
feed.linkPrefix,
title,
feed.nsfw
);
})
);
return true;
Expand Down

0 comments on commit 11250ce

Please sign in to comment.