Update CSS Pipeline #4
3 changed files with 8 additions and 1208 deletions
|
@ -1,29 +1,15 @@
|
||||||
import { JSDOM } from "jsdom";
|
|
||||||
|
|
||||||
// From coryd.dev
|
|
||||||
// https://www.coryd.dev/posts/2025/generating-absolute-urls-in-my-rss-feeds/
|
|
||||||
const convertRelativeLinks = (htmlContent, url) => {
|
const convertRelativeLinks = (htmlContent, url) => {
|
||||||
if (!htmlContent || !url) return htmlContent;
|
if (!htmlContent || !url) return htmlContent;
|
||||||
|
|
||||||
const dom = new JSDOM(htmlContent);
|
const baseUrl = url.replace(/\/$/, "");
|
||||||
const document = dom.window.document;
|
|
||||||
|
|
||||||
document.querySelectorAll("a[href]").forEach((link) => {
|
return htmlContent.replace(
|
||||||
let href = link.getAttribute("href");
|
/(href|src)=(['"])(?![a-z][a-z0-9+.-]*:|\/\/)([^'"]+)\2/gi,
|
||||||
|
(_, attr, quote, relUrl) => {
|
||||||
if (href.startsWith("#")) {
|
const clean = relUrl.replace(/^\//, "");
|
||||||
link.remove();
|
return `${attr}=${quote}${baseUrl}/${clean}${quote}`;
|
||||||
return;
|
},
|
||||||
}
|
|
||||||
|
|
||||||
if (!href.startsWith("http://") && !href.startsWith("https://"))
|
|
||||||
link.setAttribute(
|
|
||||||
"href",
|
|
||||||
`${url.replace(/\/$/, "")}/${href.replace(/^\/+/, "")}`,
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
return document.body.innerHTML;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
1185
package-lock.json
generated
1185
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -23,7 +23,6 @@
|
||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"html-minifier-terser": "^7.2.0",
|
"html-minifier-terser": "^7.2.0",
|
||||||
"jsdom": "^26.0.0",
|
|
||||||
"markdown-it": "^14.0.0",
|
"markdown-it": "^14.0.0",
|
||||||
"markdown-it-abbr": "^2.0.0",
|
"markdown-it-abbr": "^2.0.0",
|
||||||
"markdown-it-anchor": "^8.6.7",
|
"markdown-it-anchor": "^8.6.7",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue