Make latest posts show first, fix special chars in URL and add new article
This commit is contained in:
parent
838dc4c706
commit
4c97b608ee
8
app.js
8
app.js
@ -53,9 +53,12 @@ function loadMarkdownWithLead(file) {
|
|||||||
return { contentHtml, lead };
|
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) {
|
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)
|
// 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
|
// Sitemap Route
|
||||||
app.get('/sitemap.xml', (req, res) => {
|
app.get('/sitemap.xml', (req, res) => {
|
||||||
const hostname = req.headers.host || 'http://localhost'; // Ensure this is your site URL in production
|
const hostname = req.headers.host || 'http://localhost'; // Ensure this is your site URL in production
|
||||||
|
1379
markdown/Deep Dive: Discord-Linux Automated Container Platform.md
Normal file
1379
markdown/Deep Dive: Discord-Linux Automated Container Platform.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Recent Posts</h2>
|
<h2>Recent Posts</h2>
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
<% blogPosts.forEach(post => { %>
|
<% blogPosts.sort((a, b) => new Date(b.date) - new Date(a.date)).forEach(post => { %>
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center py-4">
|
<li class="list-group-item d-flex justify-content-between align-items-center py-4">
|
||||||
<div>
|
<div>
|
||||||
<h5 class="mb-1"><a href="/blog/<%= post.slug %>"> <%= post.title %> </a></h5>
|
<h5 class="mb-1"><a href="/blog/<%= post.slug %>"> <%= post.title %> </a></h5>
|
||||||
|
Loading…
Reference in New Issue
Block a user