Skip to content

Commit

Permalink
Tweaks to Generate Markdown Script
Browse files Browse the repository at this point in the history
  • Loading branch information
latenitefilms committed Jun 15, 2023
1 parent 4bf5cdb commit 26f724f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions .github/scripts/generate-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
// Sort files array to guarantee alphabetical order
files.sort();

files.forEach(function (file) {
files.forEach(function (file, index) {
// Ignore if not a markdown file
if(path.extname(file) !== '.md') return;

Expand All @@ -38,11 +38,21 @@ try {
lastInitial = currentInitial;
}

fileContent += `{{ include "${PAGE_NAME}/${fileNameWithoutExtension}" }}\n\n`;
fileContent += `{{ include "${PAGE_NAME}/${fileNameWithoutExtension}" }}\n`;

// Add '---' separator if the next file is not of the same initial
if (index !== files.length - 1) {
const nextFileNameWithoutExtension = path.parse(files[index+1]).name;
const nextInitial = nextFileNameWithoutExtension.charAt(0).toUpperCase();

if (currentInitial === nextInitial) {
fileContent += '\n---\n\n';
}
}
});

// Remove the last extra line and '---'
fileContent = fileContent.slice(0, -2);
// Remove the last extra lines
fileContent = fileContent.replace(/\n$/, '');

// Write to the output file
try {
Expand Down

0 comments on commit 26f724f

Please sign in to comment.