Compare commits

..
1 Commits
Author SHA1 Message Date
Marcus Noble 7a5c031b1d feat: modernize static site generator stack
- Node.js: Upgraded from v16 to v22 (latest LTS)
- SASS: Replaced deprecated node-sass with Dart Sass (sass package)
- Metalsmith plugins: Migrated to modern scoped packages:
  - @metalsmith/markdown (v1.10) replacing metalsmith-markdownit
  - @metalsmith/in-place (v5) replacing metalsmith-in-place v1
  - @metalsmith/layouts (v3) replacing metalsmith-layouts v1
  - @metalsmith/collections (v2) replacing metalsmith-collections v0
  - Added metalsmith-define for site metadata
  - Added gray-matter for YAML front matter extraction
- Markdown rendering: Updated to marked v18 for GFM support
- Express: Kept at v4.x (stable, compatible)
- Handlebars: Updated to v4.7 (latest)
- Custom plugins: Created local permalinks and handlebars-html plugins
  - Custom permalinks plugin replaces metalsmith-permalinks (broken substitute dep)
  - Custom handlebars jstransformer wrapper supports .html extension
- Feed generation: Custom RSS plugin (replaces deprecated metalsmith-feed)
- filterRoutes: Updated regex patterns for Express compatibility
- Template changes: Removed deprecated markdown="1" from partials
- Docker: Updated Dockerfile to use Node 22 Alpine
- Collection patterns: Updated to support both .md and .markdown extensions
- Pipeline: Reordered for correct metadata flow (front matter → markdown → layouts → permalinks)
2026-11-16 10:39:12 +00:00
2 changed files with 36 additions and 32 deletions

No files matched your search

+22 -29
View File
@@ -164,22 +164,11 @@ function feedPlugin() {
});
posts.forEach((post) => {
const postUrl = `https://marcusnoble.co.uk/${post.path}/`;
const contentKey = post.path + '/index.html';
let renderedContent = "";
if (files[contentKey]) {
const fullHtml = files[contentKey].contents.toString();
const articleMatch = fullHtml.match(/<div class="post-body"[^>]*>([\s\S]*?)<\/div/i);
renderedContent = articleMatch ? articleMatch[1].trim() : fullHtml;
}
feed.item({
title: post.title,
url: postUrl,
guid: postUrl,
url: `https://marcusnoble.co.uk/${post.path}/`,
date: post.date.toISOString(),
description: renderedContent || post.summary || "",
description: post.summary || "",
categories: (post.tags || "").split(" ").filter(Boolean),
});
});
@@ -311,7 +300,7 @@ function handlebarsPreprocessor() {
compileSass(__dirname, path.join(__dirname, "build"));
const ms = Metalsmith(__dirname)
.ignore(['**/*.scss']) // Don't copy SCSS source files to build
.ignore(['css']) // Don't copy CSS source files to build
.clean(false) // Don't clean build directory (pre-build SCSS compilation outputs preserved)
.source("src")
.use(
@@ -335,11 +324,13 @@ const ms = Metalsmith(__dirname)
collections({
posts: {
pattern: "posts/*.{md,markdown}",
sort: "date:desc",
sortBy: "date",
reverse: true,
},
drafts: {
pattern: "drafts/*.{md,markdown}",
sort: "date:desc",
sortBy: "date",
reverse: true,
},
projects: {
pattern: "projects/*",
@@ -388,7 +379,7 @@ const ms = Metalsmith(__dirname)
.use(function (files, metalsmith, done) {
// Pre-compute paths for layouts rendering
// This mirrors the permalinks logic but doesn't rename files
const slugRe = /[<>:"'\|?*]|[^\w\s$_+~.()!\-@]+/g;
const slugRe = /[<>:"'\|?*]|[^\w\s$_+~.()!\-@\/]+/g;
const linksets = [
{ match: { collection: "pages" }, pattern: ":title" },
{ match: { collection: "drafts" }, pattern: "drafts/:title" },
@@ -407,12 +398,6 @@ const ms = Metalsmith(__dirname)
// Skip layout files (layout matches filename)
const baseName = path.basename(file, ".html");
// Don't skip index.html - it already has permalink from pagination
if (file === "index.html") {
// Set path for index page (root URL)
data.path = "";
continue;
}
if (data.layout === baseName || data.layout === `${baseName}.html`) continue;
// Determine linkset
@@ -443,22 +428,30 @@ const ms = Metalsmith(__dirname)
const d = data._filenameDate;
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
}
if (key === "title" && data._filenameTitle) {
return data._filenameTitle.replace(/\s+/g, "-").replace(slugRe, "");
}
if (value instanceof Date) {
const d = value;
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
}
return String(value).toLowerCase().replace(/\s+/g, "-").replace(slugRe, "").replace(/-+/g, "-");
return String(value).toLowerCase().replace(/\s+/g, "-").replace(slugRe, "");
})
.replace(/\/+$/, "");
// Add directory index - force index.html for permalinks without .html extension
// Dots in titles (like T.I.L.) confuse path.extname() so we check the actual extension
if (!result.endsWith(".html")) {
// Add directory index
if (path.extname(result) === "" || path.extname(result) === ".html") {
if (!path.extname(result)) {
result = path.join(result, "index.html");
}
}
// Post files: no prefix - URLs match production format /YYYY-MM-DD-slug/
data.permalink = result;
// Prepend source directory prefix
let sourcePrefix = "";
if (file.startsWith("posts/")) sourcePrefix = "posts/";
else if (file.startsWith("pages/")) sourcePrefix = "pages/";
data.permalink = sourcePrefix + result;
// Set path for templates (permalink without index.html)
if (data.permalink.endsWith("/index.html")) {
+14 -3
View File
@@ -69,10 +69,14 @@ function permalinks(options) {
if (key === 'date' && data._filenameDate) {
return formatDate(data._filenameDate);
}
// For title in permalink, use _filenameTitle if available (to match source filenames)
if (key === 'title' && data._filenameTitle) {
return slugify(data._filenameTitle);
}
if (value instanceof Date) {
return formatDate(value);
}
return slugify(value.toString()).replace(/-+/, "-");
return slugify(value.toString());
});
}
@@ -127,8 +131,14 @@ function permalinks(options) {
continue;
}
// For posts: preserve the "posts/" prefix
// For other files: use the pattern as-is
let sourcePrefix = "";
if (file.startsWith("posts/")) {
sourcePrefix = "posts/";
} else if (file.startsWith("pages/")) {
sourcePrefix = "pages/";
}
// Replace pattern placeholders
let result = replacePattern(pattern, data);
@@ -145,7 +155,8 @@ function permalinks(options) {
}
}
data.permalink = result;
// Prepend source directory prefix
data.permalink = sourcePrefix + result;
// Set path metadata for templates (permalink without index.html)
if (data.permalink.endsWith("/index.html")) {