mirror of
https://github.com/andwati/andwati.com.git
synced 2026-10-27 05:12:16 +00:00
Apply Biome formatting across the workspace
Fixes the formatting deltas from the initial Astro/Strapi scaffold and brings the legacy generate-og-images/generate-llms/validate-post scripts in line with Biome's style. No behavioral changes.
This commit is contained in:
+41
-35
@@ -1,13 +1,15 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const root = process.cwd();
|
||||
const config = fs.readFileSync(path.join(root, 'zola.toml'), 'utf8');
|
||||
const postsDir = path.join(root, 'content', 'posts');
|
||||
const output = path.join(root, 'static', 'llms.txt');
|
||||
const config = fs.readFileSync(path.join(root, "zola.toml"), "utf8");
|
||||
const postsDir = path.join(root, "content", "posts");
|
||||
const output = path.join(root, "static", "llms.txt");
|
||||
|
||||
function tomlString(source, key) {
|
||||
const match = source.match(new RegExp(`^${key}\\s*=\\s*("(?:[^"\\\\]|\\\\.)*")`, 'm'));
|
||||
const match = source.match(
|
||||
new RegExp(`^${key}\\s*=\\s*("(?:[^"\\\\]|\\\\.)*")`, "m"),
|
||||
);
|
||||
return match ? JSON.parse(match[1]) : undefined;
|
||||
}
|
||||
|
||||
@@ -19,31 +21,32 @@ function markdownFiles(directory) {
|
||||
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
||||
const location = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) return markdownFiles(location);
|
||||
return entry.isFile() && entry.name.endsWith('.md') ? [location] : [];
|
||||
return entry.isFile() && entry.name.endsWith(".md") ? [location] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function postUrl(file, metadata, baseUrl) {
|
||||
const relative = path.relative(postsDir, file).replaceAll(path.sep, '/');
|
||||
const defaultSlug = relative.endsWith('/index.md')
|
||||
? relative.slice(0, -'/index.md'.length)
|
||||
: relative.slice(0, -'.md'.length);
|
||||
const slug = tomlString(metadata, 'slug') ?? defaultSlug;
|
||||
const relative = path.relative(postsDir, file).replaceAll(path.sep, "/");
|
||||
const defaultSlug = relative.endsWith("/index.md")
|
||||
? relative.slice(0, -"/index.md".length)
|
||||
: relative.slice(0, -".md".length);
|
||||
const slug = tomlString(metadata, "slug") ?? defaultSlug;
|
||||
return `${baseUrl}/posts/${slug}/`;
|
||||
}
|
||||
|
||||
const baseUrl = tomlString(config, 'base_url')?.replace(/\/$/, '');
|
||||
const baseUrl = tomlString(config, "base_url")?.replace(/\/$/, "");
|
||||
const siteTitle = new URL(baseUrl).hostname;
|
||||
const summary = tomlString(config, 'llms_description') ?? tomlString(config, 'description');
|
||||
const summary =
|
||||
tomlString(config, "llms_description") ?? tomlString(config, "description");
|
||||
|
||||
const posts = markdownFiles(postsDir)
|
||||
.filter((file) => path.basename(file) !== '_index.md')
|
||||
.filter((file) => path.basename(file) !== "_index.md")
|
||||
.map((file) => {
|
||||
const metadata = frontMatter(fs.readFileSync(file, 'utf8'));
|
||||
const metadata = frontMatter(fs.readFileSync(file, "utf8"));
|
||||
if (!metadata || /^draft\s*=\s*true$/m.test(metadata)) return null;
|
||||
|
||||
const title = tomlString(metadata, 'title');
|
||||
const description = tomlString(metadata, 'description');
|
||||
const title = tomlString(metadata, "title");
|
||||
const description = tomlString(metadata, "description");
|
||||
const date = metadata.match(/^date\s*=\s*(\d{4}-\d{2}-\d{2})/m)?.[1];
|
||||
if (!title || !date) return null;
|
||||
|
||||
@@ -54,32 +57,35 @@ const posts = markdownFiles(postsDir)
|
||||
|
||||
const lines = [
|
||||
`# ${siteTitle}`,
|
||||
'',
|
||||
"",
|
||||
`> ${summary}`,
|
||||
'',
|
||||
'This site contains articles in English, often with commands, code samples, worked explanations, and material aimed at readers learning by doing.',
|
||||
'',
|
||||
'## Main pages',
|
||||
'',
|
||||
"",
|
||||
"This site contains articles in English, often with commands, code samples, worked explanations, and material aimed at readers learning by doing.",
|
||||
"",
|
||||
"## Main pages",
|
||||
"",
|
||||
`- [Home](${baseUrl}/): Introduction and latest articles.`,
|
||||
`- [About](${baseUrl}/about/): About the author and contact information.`,
|
||||
`- [Posts](${baseUrl}/posts/): All published articles.`,
|
||||
`- [Tags](${baseUrl}/tags/): Articles grouped by topic.`,
|
||||
`- [Archive](${baseUrl}/archive/): Chronological article archive.`,
|
||||
'',
|
||||
'## Published articles',
|
||||
'',
|
||||
...posts.map(({ title, description, url }) =>
|
||||
`- [${title}](${url})${description ? `: ${description.replace(/\s+/g, ' ').trim()}` : ''}`,
|
||||
"",
|
||||
"## Published articles",
|
||||
"",
|
||||
...posts.map(
|
||||
({ title, description, url }) =>
|
||||
`- [${title}](${url})${description ? `: ${description.replace(/\s+/g, " ").trim()}` : ""}`,
|
||||
),
|
||||
'',
|
||||
'## Feeds and discovery',
|
||||
'',
|
||||
"",
|
||||
"## Feeds and discovery",
|
||||
"",
|
||||
`- [RSS feed](${baseUrl}/rss.xml): Full site feed in RSS format.`,
|
||||
`- [JSON feed](${baseUrl}/feed.json): Full site feed in JSON format.`,
|
||||
`- [Sitemap](${baseUrl}/sitemap.xml): Machine-readable index of public pages.`,
|
||||
'',
|
||||
"",
|
||||
];
|
||||
|
||||
fs.writeFileSync(output, lines.join('\n'));
|
||||
console.log(`Generated ${path.relative(root, output)} with ${posts.length} published articles.`);
|
||||
fs.writeFileSync(output, lines.join("\n"));
|
||||
console.log(
|
||||
`Generated ${path.relative(root, output)} with ${posts.length} published articles.`,
|
||||
);
|
||||
|
||||
+136
-89
@@ -1,30 +1,36 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import satori from 'satori';
|
||||
import { Resvg } from '@resvg/resvg-js';
|
||||
import { decompress } from 'wawoff2';
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { Resvg } from "@resvg/resvg-js";
|
||||
import satori from "satori";
|
||||
import { decompress } from "wawoff2";
|
||||
|
||||
const root = process.cwd();
|
||||
const postsDir = path.join(root, 'content', 'posts');
|
||||
const outDir = path.join(root, 'static', 'images', 'og');
|
||||
const postsDir = path.join(root, "content", "posts");
|
||||
const outDir = path.join(root, "static", "images", "og");
|
||||
|
||||
const COLORS = {
|
||||
bg: '#131311',
|
||||
text: '#e9e7de',
|
||||
muted: '#8b8a80',
|
||||
accent: '#ff5a46',
|
||||
border: 'rgba(233, 231, 222, 0.16)',
|
||||
bg: "#131311",
|
||||
text: "#e9e7de",
|
||||
muted: "#8b8a80",
|
||||
accent: "#ff5a46",
|
||||
border: "rgba(233, 231, 222, 0.16)",
|
||||
};
|
||||
|
||||
function tomlString(source, key) {
|
||||
const match = source.match(new RegExp(`^${key}\\s*=\\s*("(?:[^"\\\\]|\\\\.)*")`, 'm'));
|
||||
const match = source.match(
|
||||
new RegExp(`^${key}\\s*=\\s*("(?:[^"\\\\]|\\\\.)*")`, "m"),
|
||||
);
|
||||
return match ? JSON.parse(match[1]) : undefined;
|
||||
}
|
||||
|
||||
function tomlStringArray(source, key) {
|
||||
const match = source.match(new RegExp(`^${key}\\s*=\\s*\\[([^\\]]*)\\]`, 'm'));
|
||||
const match = source.match(
|
||||
new RegExp(`^${key}\\s*=\\s*\\[([^\\]]*)\\]`, "m"),
|
||||
);
|
||||
if (!match) return [];
|
||||
return [...match[1].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => JSON.parse(`"${m[1]}"`));
|
||||
return [...match[1].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) =>
|
||||
JSON.parse(`"${m[1]}"`),
|
||||
);
|
||||
}
|
||||
|
||||
function frontMatter(source) {
|
||||
@@ -32,7 +38,9 @@ function frontMatter(source) {
|
||||
}
|
||||
|
||||
function taxonomies(source) {
|
||||
return source.match(/^\[taxonomies\]\s*\n([\s\S]*?)(?:\n\[|\n?$)/m)?.[1] ?? '';
|
||||
return (
|
||||
source.match(/^\[taxonomies\]\s*\n([\s\S]*?)(?:\n\[|\n?$)/m)?.[1] ?? ""
|
||||
);
|
||||
}
|
||||
|
||||
function markdownFiles(directory) {
|
||||
@@ -41,103 +49,117 @@ function markdownFiles(directory) {
|
||||
entries.map((entry) => {
|
||||
const location = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) return markdownFiles(location);
|
||||
return entry.isFile() && entry.name.endsWith('.md') ? [location] : [];
|
||||
return entry.isFile() && entry.name.endsWith(".md") ? [location] : [];
|
||||
}),
|
||||
).then((lists) => lists.flat()),
|
||||
);
|
||||
}
|
||||
|
||||
function slugFor(file, metadata) {
|
||||
const relative = path.relative(postsDir, file).replaceAll(path.sep, '/');
|
||||
const defaultSlug = relative.endsWith('/index.md')
|
||||
? relative.slice(0, -'/index.md'.length)
|
||||
: relative.slice(0, -'.md'.length);
|
||||
return tomlString(metadata, 'slug') ?? defaultSlug;
|
||||
const relative = path.relative(postsDir, file).replaceAll(path.sep, "/");
|
||||
const defaultSlug = relative.endsWith("/index.md")
|
||||
? relative.slice(0, -"/index.md".length)
|
||||
: relative.slice(0, -".md".length);
|
||||
return tomlString(metadata, "slug") ?? defaultSlug;
|
||||
}
|
||||
|
||||
async function loadFont(relPath) {
|
||||
const woff2 = await fs.readFile(path.join(root, 'static', relPath));
|
||||
const woff2 = await fs.readFile(path.join(root, "static", relPath));
|
||||
const ttf = await decompress(woff2);
|
||||
return Buffer.from(ttf);
|
||||
}
|
||||
|
||||
function h(type, props, ...children) {
|
||||
return { type, props: { ...props, children: children.flat().filter((c) => c !== null && c !== undefined) } };
|
||||
return {
|
||||
type,
|
||||
props: {
|
||||
...props,
|
||||
children: children.flat().filter((c) => c !== null && c !== undefined),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function formatDate(date) {
|
||||
return new Date(`${date}T00:00:00Z`).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
return new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
}
|
||||
|
||||
function card({ title, date, tags }) {
|
||||
const stampTag = tags[0];
|
||||
const footerTags = tags.length > 4 ? `${tags.slice(0, 4).join(' · ')} ⋯` : tags.join(' · ');
|
||||
const footerTags =
|
||||
tags.length > 4 ? `${tags.slice(0, 4).join(" · ")} ⋯` : tags.join(" · ");
|
||||
const titleSize = title.length > 70 ? 46 : title.length > 45 ? 54 : 64;
|
||||
|
||||
return h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
width: '1200px',
|
||||
height: '630px',
|
||||
display: 'flex',
|
||||
width: "1200px",
|
||||
height: "630px",
|
||||
display: "flex",
|
||||
backgroundColor: COLORS.bg,
|
||||
color: COLORS.text,
|
||||
fontFamily: 'IBM Plex Serif',
|
||||
fontFamily: "IBM Plex Serif",
|
||||
},
|
||||
},
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
flex: 1,
|
||||
margin: '40px',
|
||||
margin: "40px",
|
||||
border: `1px solid ${COLORS.border}`,
|
||||
borderRadius: '6px',
|
||||
padding: '48px 56px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'space-between',
|
||||
borderRadius: "6px",
|
||||
padding: "48px 56px",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
},
|
||||
h(
|
||||
'div',
|
||||
{ style: { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start' } },
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
},
|
||||
},
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
display: "flex",
|
||||
fontFamily: "JetBrains Mono",
|
||||
fontWeight: 400,
|
||||
fontSize: '22px',
|
||||
fontSize: "22px",
|
||||
color: COLORS.muted,
|
||||
letterSpacing: '2px',
|
||||
letterSpacing: "2px",
|
||||
},
|
||||
},
|
||||
'ANDWATI.COM · CASE FILE',
|
||||
"ANDWATI.COM · CASE FILE",
|
||||
),
|
||||
stampTag
|
||||
? h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
display: "flex",
|
||||
border: `2px solid ${COLORS.accent}`,
|
||||
borderRadius: '4px',
|
||||
padding: '8px 16px',
|
||||
borderRadius: "4px",
|
||||
padding: "8px 16px",
|
||||
color: COLORS.accent,
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fontFamily: "JetBrains Mono",
|
||||
fontWeight: 700,
|
||||
fontSize: '20px',
|
||||
letterSpacing: '2px',
|
||||
textTransform: 'uppercase',
|
||||
transform: 'rotate(3deg)',
|
||||
fontSize: "20px",
|
||||
letterSpacing: "2px",
|
||||
textTransform: "uppercase",
|
||||
transform: "rotate(3deg)",
|
||||
},
|
||||
},
|
||||
stampTag,
|
||||
@@ -145,57 +167,57 @@ function card({ title, date, tags }) {
|
||||
: null,
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
fontFamily: 'IBM Plex Serif',
|
||||
display: "flex",
|
||||
fontFamily: "IBM Plex Serif",
|
||||
fontWeight: 700,
|
||||
fontSize: `${titleSize}px`,
|
||||
lineHeight: 1.15,
|
||||
letterSpacing: '-1px',
|
||||
letterSpacing: "-1px",
|
||||
color: COLORS.text,
|
||||
overflow: 'hidden',
|
||||
overflow: "hidden",
|
||||
},
|
||||
},
|
||||
title,
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
borderTop: `1px solid ${COLORS.border}`,
|
||||
paddingTop: '24px',
|
||||
paddingTop: "24px",
|
||||
},
|
||||
},
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
display: "flex",
|
||||
fontFamily: "JetBrains Mono",
|
||||
fontWeight: 400,
|
||||
fontSize: '20px',
|
||||
fontSize: "20px",
|
||||
color: COLORS.muted,
|
||||
letterSpacing: '1px',
|
||||
letterSpacing: "1px",
|
||||
},
|
||||
},
|
||||
formatDate(date),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
"div",
|
||||
{
|
||||
style: {
|
||||
display: 'flex',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
display: "flex",
|
||||
fontFamily: "JetBrains Mono",
|
||||
fontWeight: 400,
|
||||
fontSize: '20px',
|
||||
fontSize: "20px",
|
||||
color: COLORS.muted,
|
||||
letterSpacing: '1px',
|
||||
letterSpacing: "1px",
|
||||
},
|
||||
},
|
||||
footerTags,
|
||||
@@ -206,32 +228,57 @@ function card({ title, date, tags }) {
|
||||
}
|
||||
|
||||
const fonts = [
|
||||
{ name: 'IBM Plex Serif', data: await loadFont('fonts/ibm-plex-serif/ibm-plex-serif-v20-latin-700.woff2'), weight: 700, style: 'normal' },
|
||||
{ name: 'JetBrains Mono', data: await loadFont('fonts/jetbrains-mono/JetBrainsMono-Regular.woff2'), weight: 400, style: 'normal' },
|
||||
{ name: 'JetBrains Mono', data: await loadFont('fonts/jetbrains-mono/JetBrainsMono-Bold.woff2'), weight: 700, style: 'normal' },
|
||||
{
|
||||
name: "IBM Plex Serif",
|
||||
data: await loadFont(
|
||||
"fonts/ibm-plex-serif/ibm-plex-serif-v20-latin-700.woff2",
|
||||
),
|
||||
weight: 700,
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
name: "JetBrains Mono",
|
||||
data: await loadFont("fonts/jetbrains-mono/JetBrainsMono-Regular.woff2"),
|
||||
weight: 400,
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
name: "JetBrains Mono",
|
||||
data: await loadFont("fonts/jetbrains-mono/JetBrainsMono-Bold.woff2"),
|
||||
weight: 700,
|
||||
style: "normal",
|
||||
},
|
||||
];
|
||||
|
||||
const files = (await markdownFiles(postsDir)).filter((file) => path.basename(file) !== '_index.md');
|
||||
const files = (await markdownFiles(postsDir)).filter(
|
||||
(file) => path.basename(file) !== "_index.md",
|
||||
);
|
||||
|
||||
await fs.mkdir(outDir, { recursive: true });
|
||||
|
||||
let count = 0;
|
||||
for (const file of files) {
|
||||
const source = await fs.readFile(file, 'utf8');
|
||||
const source = await fs.readFile(file, "utf8");
|
||||
const metadata = frontMatter(source);
|
||||
if (!metadata || /^draft\s*=\s*true$/m.test(metadata)) continue;
|
||||
|
||||
const title = tomlString(metadata, 'title');
|
||||
const title = tomlString(metadata, "title");
|
||||
const date = metadata.match(/^date\s*=\s*(\d{4}-\d{2}-\d{2})/m)?.[1];
|
||||
if (!title || !date) continue;
|
||||
|
||||
const tags = tomlStringArray(taxonomies(metadata), 'tags');
|
||||
const tags = tomlStringArray(taxonomies(metadata), "tags");
|
||||
const slug = slugFor(file, metadata);
|
||||
|
||||
const svg = await satori(card({ title, date, tags }), { width: 1200, height: 630, fonts });
|
||||
const svg = await satori(card({ title, date, tags }), {
|
||||
width: 1200,
|
||||
height: 630,
|
||||
fonts,
|
||||
});
|
||||
const png = new Resvg(svg).render().asPng();
|
||||
await fs.writeFile(path.join(outDir, `${slug}.png`), png);
|
||||
count += 1;
|
||||
}
|
||||
|
||||
console.log(`Generated ${count} OG image${count === 1 ? '' : 's'} in ${path.relative(root, outDir)}/`);
|
||||
console.log(
|
||||
`Generated ${count} OG image${count === 1 ? "" : "s"} in ${path.relative(root, outDir)}/`,
|
||||
);
|
||||
|
||||
+27
-18
@@ -1,16 +1,19 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { execSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
// Get staged files from git
|
||||
const stagedFiles = execSync('git diff --cached --name-only --diff-filter=ACMR')
|
||||
const stagedFiles = execSync("git diff --cached --name-only --diff-filter=ACMR")
|
||||
.toString()
|
||||
.split('\n')
|
||||
.split("\n")
|
||||
.filter(Boolean);
|
||||
|
||||
// Filter to only new or modified posts
|
||||
const postFiles = stagedFiles.filter(
|
||||
(file) => file.startsWith('content/posts/') && file.endsWith('.md') && !file.endsWith('_index.md'),
|
||||
(file) =>
|
||||
file.startsWith("content/posts/") &&
|
||||
file.endsWith(".md") &&
|
||||
!file.endsWith("_index.md"),
|
||||
);
|
||||
|
||||
if (postFiles.length === 0) {
|
||||
@@ -20,21 +23,21 @@ if (postFiles.length === 0) {
|
||||
let hasError = false;
|
||||
|
||||
for (const file of postFiles) {
|
||||
const basename = path.basename(file, '.md');
|
||||
|
||||
const basename = path.basename(file, ".md");
|
||||
|
||||
// 1. Slug validation (kebab-case: lowercase letters, numbers, and hyphens)
|
||||
if (!/^[a-z0-9\-]+$/.test(basename)) {
|
||||
if (!/^[a-z0-9-]+$/.test(basename)) {
|
||||
console.error(`[ERROR] in ${file}:`);
|
||||
console.error(` Filename must be kebab-case (e.g. 'my-cool-post.md').`);
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
// 2. Front-matter validation
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
|
||||
const content = fs.readFileSync(file, "utf8");
|
||||
|
||||
// Zola uses +++ for TOML front-matter
|
||||
const frontMatterMatch = content.match(/^\+\+\+([\s\S]*?)\+\+\+/);
|
||||
|
||||
|
||||
if (!frontMatterMatch) {
|
||||
console.error(`[ERROR] in ${file}:`);
|
||||
console.error(` Missing TOML front-matter (must be enclosed in +++).`);
|
||||
@@ -43,26 +46,32 @@ for (const file of postFiles) {
|
||||
}
|
||||
|
||||
const frontMatter = frontMatterMatch[1];
|
||||
|
||||
|
||||
const hasTitle = /^title\s*=\s*".+"/m.test(frontMatter);
|
||||
const hasDate = /^date\s*=\s*\d{4}-\d{2}-\d{2}/m.test(frontMatter);
|
||||
|
||||
if (!hasTitle) {
|
||||
console.error(`[ERROR] in ${file}:`);
|
||||
console.error(` Missing 'title' field in front-matter (e.g. title = "My Post").`);
|
||||
console.error(
|
||||
` Missing 'title' field in front-matter (e.g. title = "My Post").`,
|
||||
);
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
|
||||
if (!hasDate) {
|
||||
console.error(`[ERROR] in ${file}:`);
|
||||
console.error(` Missing 'date' field in front-matter (e.g. date = 2024-01-01).`);
|
||||
console.error(
|
||||
` Missing 'date' field in front-matter (e.g. date = 2024-01-01).`,
|
||||
);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
console.error('\n[FATAL] Commit rejected due to validation errors. Please fix the issues above and try again.\n');
|
||||
console.error(
|
||||
"\n[FATAL] Commit rejected due to validation errors. Please fix the issues above and try again.\n",
|
||||
);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('[SUCCESS] Post validation passed!');
|
||||
console.log("[SUCCESS] Post validation passed!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user