Skip to content

Commit

Permalink
mdBook: Strip down links in RFCs titles (#72)
Browse files Browse the repository at this point in the history
- Closes #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)
  • Loading branch information
rzadp authored Feb 12, 2024
1 parent 94f434e commit 5710c49
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/scripts/build-mdbook-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit 5710c49

Please sign in to comment.