Fix URL usage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user