Make latest posts show first, fix special chars in URL and add new article

This commit is contained in:
Raven Scott
2024-09-18 18:46:51 -04:00
parent 838dc4c706
commit 4c97b608ee
3 changed files with 1385 additions and 4 deletions

8
app.js
View File

@ -53,9 +53,12 @@ function loadMarkdownWithLead(file) {
return { contentHtml, lead };
}
// Function to convert a title (with spaces) into a URL-friendly slug (with dashes)
// Function to convert a title (with spaces and special characters) into a URL-friendly slug (with dashes)
function titleToSlug(title) {
return title.replace(/\s+/g, '-').toLowerCase(); // Always lowercase the slug
return title
.toLowerCase() // Convert to lowercase
.replace(/[^a-z0-9\s-]/g, '') // Remove all non-alphanumeric characters except spaces and dashes
.replace(/\s+/g, '-'); // Replace spaces with dashes
}
// Function to convert a slug (with dashes) back into a readable title (with spaces)
@ -208,7 +211,6 @@ app.get('/blog/:slug', (req, res) => {
}
});
// Sitemap Route
app.get('/sitemap.xml', (req, res) => {
const hostname = req.headers.host || 'http://localhost'; // Ensure this is your site URL in production