mdBook: Strip down links in RFCs titles (#72)

- Closes https://github.com/polkadot-fellows/RFCs/issues/71
- This affects only the sidebar of the mdBook.

![Screenshot 2024-01-31 at 12 39
38](https://github.com/polkadot-fellows/RFCs/assets/12039224/715f1856-1bf4-48be-9669-e3487c732658)
This commit is contained in:
Przemek Rzad
2024-02-12 16:28:41 +01:00
committed by GitHub
parent 94f434e07b
commit 5710c49dc9
+7 -1
View File
@@ -15,9 +15,15 @@ module.exports = async ({github, context}) => {
if (!filename.endsWith(".md")) continue;
const filePath = dirPath + filename
const text = fs.readFileSync(filePath)
const title = text.toString().split(/\n/)
let title = text.toString().split(/\n/)
.find(line => line.startsWith("# ") || line.startsWith(" # "))
.replace("# ", "")
for (const markdownLink of title.matchAll(/\[(.*?)\]\((.*?)\)/g)) {
// Replace any [label](destination) markdown links in the title with just the label.
// This is because the titles are turned into links themselves,
// and we cannot have a link inside of a link - it breaks markdown and mdBook is not able to build.
title = title.replace(markdownLink[0], markdownLink[1])
}
// Relative path, without the src prefix (format required by mdbook)
const relativePath = filePath.replace("mdbook/src/", "")
fs.appendFileSync(summaryPath, `- [${title}](${relativePath})\n`)