Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/validate-site-docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const root = fileURLToPath(new URL('..', import.meta.url));
const contentDir = join(root, 'docs/site');

const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/;
const FIELD = /^([A-Za-z_][A-Za-z0-9_]*):\s*(.*?)\s*$/;
const FIELD = /^([A-Za-z_]\w*):(.*)$/;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: (.*)$ is not quite equivalent to the old \s*(.*?)\s*$, because . excludes \r, 
 and 
 while \s includes the first two. On a line ending in one of those (title:a\r), the old pattern matched and stored a; the new one cannot match at all, so the field silently disappears and validation reports a missing title.

Not reachable through the current call path, as far as I can tell: the block is split on /\r?\n/, and a CR-only file never matches FRONTMATTER in the first place, so it takes something like a doubled \r\r\n to get there. Still, [\s\S] costs nothing and is just as linear (greedy, runs straight to the end, $ matches in one step):

Suggested change
const FIELD = /^([A-Za-z_]\w*):(.*)$/;
const FIELD = /^([A-Za-z_]\w*):([\s\S]*)$/;


function walk(dir) {
return readdirSync(dir).flatMap((name) => {
Expand All @@ -24,7 +24,7 @@ function frontmatter(raw) {
for (const line of block[1].split(/\r?\n/)) {
const field = FIELD.exec(line);
if (field) {
fields.set(field[1], field[2].replace(/^['"]|['"]$/g, ''));
fields.set(field[1], field[2].trim().replace(/^['"]|['"]$/g, ''));
}
}
return fields;
Expand Down
Loading