Fix URL usage

This commit is contained in:
kbe
2025-08-18 17:57:53 +02:00
parent a54fa099b7
commit 0089c93afa
264 changed files with 16 additions and 25020 deletions

View File

@@ -46,6 +46,19 @@ function generateContent() {
// Decode HTML entities in the content and clean up HTML tags
let contentHtml = he.decode(post.content.rendered);
// Convert absolute URLs in a href to relative URLs
contentHtml = contentHtml.replace(/<a\s+[^>]*href="([^"]+)"[^>]*>/g, (match, href) => {
// Check if the href is an absolute URL (starts with http:// or https://)
if (href.startsWith('http://') || href.startsWith('https://')) {
// Extract the path part of the URL
const url = new URL(href);
// Return the modified a tag with relative URL
return match.replace(href, url.pathname);
}
return match;
});
contentHtml = contentHtml
.replace(/<p>\s*<\/p>/g, '') // Remove empty paragraphs
.replace(/<\/p>\s*<p>/g, '\n\n') // Replace paragraph breaks with newlines