Skip to content

Commit

Permalink
Merge pull request #18 from emperorofmars/main
Browse files Browse the repository at this point in the history
Add ability to exclude reblogs/boosts
  • Loading branch information
sampsyo committed Jul 7, 2024
2 parents 9c8a7af + 9bf54c5 commit 3755275
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You can customize the feed with `data-` attributes:
* `data-toot-limit`: The maximum number of toots to display.
* `data-toot-account-id`: Emfed needs to make an extra API request to translate your human-readable username (like `@Mastodon`) into an internal ID (like 13179) before it can look up your toots. If you have [empathy for the machine][eftm], you can make everything faster by specifying the ID directly here.
* `data-exclude-replies`: "true" or "false" according to whether or not you'd like to exclude replies. The default behavior is that replies are included.
* `data-exclude-reblogs`: "true" or "false" according to whether or not you'd like to exclude reblogs/boosts. The default behavior is that reblogs/boosts are included.

Emfed sanitizes the HTML contents of toots using [DOMPurify][] to avoid malicious markup and XSS attacks.

Expand Down
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function getToots(
accountId?: string,
limit?: number,
excludeReplies?: boolean,
excludeReblogs?: boolean
): Promise<Toot[]> {
const url = new URL(userURL);

Expand All @@ -56,7 +57,7 @@ export async function getToots(
// Fetch toots.
const tootURL = Object.assign(new URL(url), {
pathname: `/api/v1/accounts/${userId}/statuses`,
search: `?limit=${limit ?? 5}&exclude_replies=${!!excludeReplies}`,
search: `?limit=${limit ?? 5}&exclude_replies=${!!excludeReplies}&exclude_reblogs=${!!excludeReblogs}`,
});

return await (await fetch(tootURL)).json();
Expand Down
6 changes: 3 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export async function loadToots(element: Element) {
el.dataset.tootAccountId,
Number(el.dataset.tootLimit ?? 5),
el.dataset.excludeReplies === "true",
el.dataset.excludeReblogs === "true",
);

// Construct the HTML content.
Expand Down Expand Up @@ -162,7 +163,6 @@ export async function loadTootPostAndReplies(element: Element) {
*/
export function loadAll() {
document.querySelectorAll("a.mastodon-feed").forEach(loadToots);
/* inspired by https://carlschwan.eu/2020/12/29/adding-comments-to-your-static-blog-with-mastodon/ */
document.querySelectorAll("a.mastodon-thread").forEach(loadTootPostAndReplies)

/* inspired by https://carlschwan.eu/2020/12/29/adding-comments-to-your-static-blog-with-mastodon/ */
document.querySelectorAll("a.mastodon-thread").forEach(loadTootPostAndReplies)
}

0 comments on commit 3755275

Please sign in to comment.