Compare commits

..
1 Commits
Author SHA1 Message Date
hermes-agentandMarcus Noble c69e2cbb97 Modernize static site generator stack (Node 22, updated Metalsmith plugins) (#2)
## Changes

### Node.js
- Upgraded from v16 to v22 (latest LTS) via `.nvmrc` and `Dockerfile`

### Sass
- Replaced deprecated `node-sass` with Dart Sass (`sass@^1.108.2`)
- Pre-build compilation of SCSS to CSS before Metalsmith run
- Added `.ignore(["css"])` to prevent source SCSS files being copied to build

### 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
- `@metalsmith/markdown` + `@metalsmith/layouts` configured with custom Handlebars jstransformer supporting `.html` templates
- `metalsmith-pagination` for index page pagination
- `gray-matter` for YAML front matter extraction

### Markdown Rendering
- Updated to `marked` v18 with GFM support
- Custom table renderer adds `role="grid"` for accessibility
- Added `jstransformer-handlebars` for template transforms

### Custom Plugins
- `plugins/permalinks.js` - Replaces `metalsmith-permalinks` (which has broken `substitute` dependency)
- `plugins/handlebars-html.js` - Custom jstransformer wrapper that supports `.html` file extensions for Handlebars templates

### Feed
- Custom RSS feed plugin replaces deprecated `metalsmith-feed`
- Generates `feed.xml` with all 56 posts

### Routing
- `filterRoutes.js` - Updated regex patterns for Express 4.x compatibility

### Templates
- Removed deprecated `markdown="1"` from `picture.html` and `tweet.html`

### Docker
- Base image: `node:22-alpine`
- Build dependencies: python3, make, gcc, g++
- Engine: 22

## Build Verification
- 69 HTML files generated successfully
- 56 posts
- 12 pagination pages
- RSS feed (feed.xml) generated
- Sitemap (sitemap.xml) generated
- SCSS compilation working (style.css)

All build output is in the `build/` directory.

---------

Co-authored-by: Marcus Noble <marcus@averagemarcus.com>
Reviewed-on: #2
Reviewed-by: Marcus Noble <1+averagemarcus@noreply.git.cluster.fun>
Co-authored-by: hermes-agent <hermes-agent@cluster.fun>
2026-11-16 14:10:51 +00:00
2 changed files with 23 additions and 36 deletions

No files matched your search

+20 -22
View File
@@ -164,9 +164,11 @@ function feedPlugin() {
});
posts.forEach((post) => {
const postUrl = `https://marcusnoble.co.uk/${post.path}/`;
feed.item({
title: post.title,
url: `https://marcusnoble.co.uk/${post.path}/`,
url: postUrl,
guid: postUrl,
date: post.date.toISOString(),
description: post.summary || "",
categories: (post.tags || "").split(" ").filter(Boolean),
@@ -300,7 +302,7 @@ function handlebarsPreprocessor() {
compileSass(__dirname, path.join(__dirname, "build"));
const ms = Metalsmith(__dirname)
.ignore(['css']) // Don't copy CSS source files to build
.ignore(['**/*.scss']) // Don't copy SCSS source files to build
.clean(false) // Don't clean build directory (pre-build SCSS compilation outputs preserved)
.source("src")
.use(
@@ -324,13 +326,11 @@ const ms = Metalsmith(__dirname)
collections({
posts: {
pattern: "posts/*.{md,markdown}",
sortBy: "date",
reverse: true,
sort: "date:desc",
},
drafts: {
pattern: "drafts/*.{md,markdown}",
sortBy: "date",
reverse: true,
sort: "date:desc",
},
projects: {
pattern: "projects/*",
@@ -379,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" },
@@ -398,6 +398,12 @@ 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
@@ -428,30 +434,22 @@ 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, "");
return String(value).toLowerCase().replace(/\s+/g, "-").replace(slugRe, "").replace(/-+/g, "-");
})
.replace(/\/+$/, "");
// Add directory index
if (path.extname(result) === "" || path.extname(result) === ".html") {
if (!path.extname(result)) {
result = path.join(result, "index.html");
}
// 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")) {
result = path.join(result, "index.html");
}
// Prepend source directory prefix
let sourcePrefix = "";
if (file.startsWith("posts/")) sourcePrefix = "posts/";
else if (file.startsWith("pages/")) sourcePrefix = "pages/";
data.permalink = sourcePrefix + result;
// Post files: no prefix - URLs match production format /YYYY-MM-DD-slug/
data.permalink = result;
// Set path for templates (permalink without index.html)
if (data.permalink.endsWith("/index.html")) {
+3 -14
View File
@@ -69,14 +69,10 @@ 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());
return slugify(value.toString()).replace(/-+/, "-");
});
}
@@ -131,14 +127,8 @@ 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);
@@ -155,8 +145,7 @@ function permalinks(options) {
}
}
// Prepend source directory prefix
data.permalink = sourcePrefix + result;
data.permalink = result;
// Set path metadata for templates (permalink without index.html)
if (data.permalink.endsWith("/index.html")) {