Compare commits
1
Commits
7a5c031b1d
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c69e2cbb97 |
No files matched your search
@@ -164,9 +164,11 @@ function feedPlugin() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
posts.forEach((post) => {
|
posts.forEach((post) => {
|
||||||
|
const postUrl = `https://marcusnoble.co.uk/${post.path}/`;
|
||||||
feed.item({
|
feed.item({
|
||||||
title: post.title,
|
title: post.title,
|
||||||
url: `https://marcusnoble.co.uk/${post.path}/`,
|
url: postUrl,
|
||||||
|
guid: postUrl,
|
||||||
date: post.date.toISOString(),
|
date: post.date.toISOString(),
|
||||||
description: post.summary || "",
|
description: post.summary || "",
|
||||||
categories: (post.tags || "").split(" ").filter(Boolean),
|
categories: (post.tags || "").split(" ").filter(Boolean),
|
||||||
@@ -300,7 +302,7 @@ function handlebarsPreprocessor() {
|
|||||||
compileSass(__dirname, path.join(__dirname, "build"));
|
compileSass(__dirname, path.join(__dirname, "build"));
|
||||||
|
|
||||||
const ms = Metalsmith(__dirname)
|
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)
|
.clean(false) // Don't clean build directory (pre-build SCSS compilation outputs preserved)
|
||||||
.source("src")
|
.source("src")
|
||||||
.use(
|
.use(
|
||||||
@@ -324,13 +326,11 @@ const ms = Metalsmith(__dirname)
|
|||||||
collections({
|
collections({
|
||||||
posts: {
|
posts: {
|
||||||
pattern: "posts/*.{md,markdown}",
|
pattern: "posts/*.{md,markdown}",
|
||||||
sortBy: "date",
|
sort: "date:desc",
|
||||||
reverse: true,
|
|
||||||
},
|
},
|
||||||
drafts: {
|
drafts: {
|
||||||
pattern: "drafts/*.{md,markdown}",
|
pattern: "drafts/*.{md,markdown}",
|
||||||
sortBy: "date",
|
sort: "date:desc",
|
||||||
reverse: true,
|
|
||||||
},
|
},
|
||||||
projects: {
|
projects: {
|
||||||
pattern: "projects/*",
|
pattern: "projects/*",
|
||||||
@@ -379,7 +379,7 @@ const ms = Metalsmith(__dirname)
|
|||||||
.use(function (files, metalsmith, done) {
|
.use(function (files, metalsmith, done) {
|
||||||
// Pre-compute paths for layouts rendering
|
// Pre-compute paths for layouts rendering
|
||||||
// This mirrors the permalinks logic but doesn't rename files
|
// This mirrors the permalinks logic but doesn't rename files
|
||||||
const slugRe = /[<>:"'\|?*]|[^\w\s$_+~.()!\-@\/]+/g;
|
const slugRe = /[<>:"'\|?*]|[^\w\s$_+~.()!\-@]+/g;
|
||||||
const linksets = [
|
const linksets = [
|
||||||
{ match: { collection: "pages" }, pattern: ":title" },
|
{ match: { collection: "pages" }, pattern: ":title" },
|
||||||
{ match: { collection: "drafts" }, pattern: "drafts/:title" },
|
{ match: { collection: "drafts" }, pattern: "drafts/:title" },
|
||||||
@@ -398,6 +398,12 @@ const ms = Metalsmith(__dirname)
|
|||||||
|
|
||||||
// Skip layout files (layout matches filename)
|
// Skip layout files (layout matches filename)
|
||||||
const baseName = path.basename(file, ".html");
|
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;
|
if (data.layout === baseName || data.layout === `${baseName}.html`) continue;
|
||||||
|
|
||||||
// Determine linkset
|
// Determine linkset
|
||||||
@@ -428,30 +434,22 @@ const ms = Metalsmith(__dirname)
|
|||||||
const d = data._filenameDate;
|
const d = data._filenameDate;
|
||||||
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
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) {
|
if (value instanceof Date) {
|
||||||
const d = value;
|
const d = value;
|
||||||
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
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(/\/+$/, "");
|
.replace(/\/+$/, "");
|
||||||
|
|
||||||
// Add directory index
|
// Add directory index - force index.html for permalinks without .html extension
|
||||||
if (path.extname(result) === "" || path.extname(result) === ".html") {
|
// Dots in titles (like T.I.L.) confuse path.extname() so we check the actual extension
|
||||||
if (!path.extname(result)) {
|
if (!result.endsWith(".html")) {
|
||||||
result = path.join(result, "index.html");
|
result = path.join(result, "index.html");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepend source directory prefix
|
// Post files: no prefix - URLs match production format /YYYY-MM-DD-slug/
|
||||||
let sourcePrefix = "";
|
data.permalink = result;
|
||||||
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)
|
// Set path for templates (permalink without index.html)
|
||||||
if (data.permalink.endsWith("/index.html")) {
|
if (data.permalink.endsWith("/index.html")) {
|
||||||
|
|||||||
+3
-14
@@ -69,14 +69,10 @@ function permalinks(options) {
|
|||||||
if (key === 'date' && data._filenameDate) {
|
if (key === 'date' && data._filenameDate) {
|
||||||
return formatDate(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) {
|
if (value instanceof Date) {
|
||||||
return formatDate(value);
|
return formatDate(value);
|
||||||
}
|
}
|
||||||
return slugify(value.toString());
|
return slugify(value.toString()).replace(/-+/, "-");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,14 +127,8 @@ function permalinks(options) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For posts: preserve the "posts/" prefix
|
|
||||||
// For other files: use the pattern as-is
|
|
||||||
let sourcePrefix = "";
|
let sourcePrefix = "";
|
||||||
if (file.startsWith("posts/")) {
|
|
||||||
sourcePrefix = "posts/";
|
|
||||||
} else if (file.startsWith("pages/")) {
|
|
||||||
sourcePrefix = "pages/";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace pattern placeholders
|
// Replace pattern placeholders
|
||||||
let result = replacePattern(pattern, data);
|
let result = replacePattern(pattern, data);
|
||||||
@@ -155,8 +145,7 @@ function permalinks(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepend source directory prefix
|
data.permalink = result;
|
||||||
data.permalink = sourcePrefix + result;
|
|
||||||
|
|
||||||
// Set path metadata for templates (permalink without index.html)
|
// Set path metadata for templates (permalink without index.html)
|
||||||
if (data.permalink.endsWith("/index.html")) {
|
if (data.permalink.endsWith("/index.html")) {
|
||||||
|
|||||||
Reference in new issue
Block a user