feat: clean up filters
Some sorely needed reorganization and pruning
This commit is contained in:
parent
e6cfa88f61
commit
ea6280226a
11 changed files with 159 additions and 176 deletions
31
config/filters/feed.js
Normal file
31
config/filters/feed.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
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,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue