Skip to content

Commit

Permalink
Fixed Generate Markdown Script
Browse files Browse the repository at this point in the history
  • Loading branch information
latenitefilms committed Jun 19, 2023
1 parent 349298f commit fc6aa6c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/scripts/generate-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@ try {
}

const filePath = path.join(directoryPath, file);
const fileContent = fs.readFileSync(filePath, 'utf-8');
let fileContent = fs.readFileSync(filePath, 'utf-8');

// Check if the first line is an include command
const includeCommandRegex = /^\s*\{\{\s*include\s*"([^"]+)"\s*\}\}\s*$/;
const match = fileContent.match(includeCommandRegex);

if (match) {
// If so, read the included file instead
const includedFilePath = path.join(process.env.GITHUB_WORKSPACE, `docs/_includes/${match[1]}.md`);
if (fs.existsSync(includedFilePath)) {
fileContent = fs.readFileSync(includedFilePath, 'utf-8');
} else {
console.error(`The included file ${includedFilePath} doesn't exist.`);
continue;
}
}

const firstLineWithoutHashes = fileContent.split('\n')[0].replace(/^[#]*\s*/, ''); // remove hashes and leading space
fileList.push({file, firstLine: firstLineWithoutHashes});
}
Expand Down

0 comments on commit fc6aa6c

Please sign in to comment.