wonderfulfrog.com/config/filters/feed.js
Devin Haska ea6280226a feat: clean up filters
Some sorely needed reorganization and pruning
2025-04-04 13:50:46 -07:00

31 lines
758 B
JavaScript

import { JSDOM } from "jsdom";
// From coryd.dev
// https://www.coryd.dev/posts/2025/generating-absolute-urls-in-my-rss-feeds/
const convertRelativeLinks = (htmlContent, url) => {
if (!htmlContent || !url) return htmlContent;
const dom = new JSDOM(htmlContent);
const document = dom.window.document;
document.querySelectorAll("a[href]").forEach((link) => {
let href = link.getAttribute("href");
if (href.startsWith("#")) {
link.remove();
return;
}
if (!href.startsWith("http://") && !href.startsWith("https://"))
link.setAttribute(
"href",
`${url.replace(/\/$/, "")}/${href.replace(/^\/+/, "")}`,
);
});
return document.body.innerHTML;
};
export default {
convertRelativeLinks,
};