Skip to content

Commit

Permalink
apply nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Dec 16, 2024
1 parent 96f821b commit 893ac66
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/build-post-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function buildPostList(postDirectories, basePath, writeFilePath) {
const missing = [];
if (!basePath) missing.push('basePath');
if (!writeFilePath) missing.push('writeFilePath');
throw new Error(`${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} required`);
throw new Error(`Error while building post list: ${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} required`);
}

if (postDirectories.length === 0) {
Expand All @@ -57,7 +57,15 @@ async function buildPostList(postDirectories, basePath, writeFilePath) {
}
}

async function walkDirectories(directories, resultObj, basePath, sectionTitle, sectionId, rootSectionId, sectionWeight = 0) {
async function walkDirectories(
directories,
resultObj,
basePath,
sectionTitle,
sectionId,
rootSectionId,
sectionWeight = 0
) {
for (let dir of directories) {
let directory = posix.normalize(dir[0]);
let sectionSlug = dir[1] || '';
Expand Down Expand Up @@ -163,12 +171,12 @@ function slugifyToC(str) {

// Match heading IDs like {# myHeadingId}
const headingIdMatch = str.match(/[\s]*\{#([a-zA-Z0-9\-_]+)\}/);
if (headingIdMatch && headingIdMatch[1].trim()) {
if (headingIdMatch?.[1]?.trim()) {
slug = headingIdMatch[1];
} else {
// Match heading IDs like {<a name="myHeadingId"/>}
const anchorTagMatch = str.match(/[\s]*<a[\s]+name="([a-zA-Z0-9\-_]+)"/);
if (anchorTagMatch && anchorTagMatch[1].trim()) {
if (anchorTagMatch?.[1]?.trim()) {
slug = anchorTagMatch[1];
}
}
Expand Down

0 comments on commit 893ac66

Please sign in to comment.