now-updater/utils.js

29 lines
793 B
JavaScript
Raw Normal View History

2025-12-18 01:57:14 +00:00
import sanitizeHtml from "sanitize-html";
export function markdownLinkRegex(url) {
return new RegExp(
`(\\[).*?(\\]\\(https:\\/\\/${url.replaceAll(".", "\\.")}\\))`,
"i",
);
}
export async function getJsonFeedItemTitle(feedUrl) {
const res = await fetch(feedUrl);
const data = await res.json();
const post = data.items[0];
const { title, image } = post;
return image ? `![${title}](${image}) ${title}` : data.items[0].title;
}
export async function getJsonFeedItemContent(feedUrl) {
const res = await fetch(feedUrl);
const data = await res.json();
const post = data.items[0];
const { content_html, image } = post;
const title = sanitizeHtml(content_html, {
allowedTags: [],
allowedAttributes: {},
})?.trim();
return image ? `![${title}](${image}) ${title}` : title;
}