mirror of
https://github.com/pezkuwichain/pezkuwi-fellows.git
synced 2026-04-25 03:27:59 +00:00
Introduce RFC mdBook web page (#60)
- Closes https://github.com/polkadot-fellows/RFCs/issues/53 - Preview available [here](https://paritytech.github.io/RFCs/).  --- ### What it does - The workflow gathers the source markdown files of RFCs - approved ones, and proposed ones (from open PRs). - The proposed RFCs are separated into new (<7 days since PR created) and stale (>30 days since PR updated). - The RFCs are extended with a table of contents, and a link to the source. - The RFCs are build into a web page using [mdBook](https://github.com/rust-lang/mdBook). - The built web page gets pushed to `gh-pages` branch - to be published in Github Pages. - The workflow is triggered on merge to `main`, and periodically once a day.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* mdBook relies on the creation of a special SUMMARY.md file
|
||||
* https://rust-lang.github.io/mdBook/format/summary.html
|
||||
* This script constructs the summary out of the available source files.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const summaryPath = "mdbook/src/SUMMARY.md"
|
||||
|
||||
module.exports = async ({github, context}) => {
|
||||
fs.writeFileSync(summaryPath, "# Summary\n\n[Introduction](introduction.md)\n") // Starting point.
|
||||
|
||||
const appendRfcsToSummary = (dirPath) => {
|
||||
for (const filename of fs.readdirSync(dirPath)) {
|
||||
if (!filename.endsWith(".md")) continue;
|
||||
const filePath = dirPath + filename
|
||||
const text = fs.readFileSync(filePath)
|
||||
const title = text.toString().split(/\n/)
|
||||
.find(line => line.startsWith("# ") || line.startsWith(" # "))
|
||||
.replace("# ", "")
|
||||
// Relative path, without the src prefix (format required by mdbook)
|
||||
const relativePath = filePath.replace("mdbook/src/", "")
|
||||
fs.appendFileSync(summaryPath, `- [${title}](${relativePath})\n`)
|
||||
}
|
||||
}
|
||||
|
||||
fs.appendFileSync(summaryPath, "\n---\n\n# Approved\n\n")
|
||||
appendRfcsToSummary("mdbook/src/approved/")
|
||||
|
||||
fs.appendFileSync(summaryPath, "\n---\n\n# Newly Proposed\n\n")
|
||||
appendRfcsToSummary("mdbook/src/new/")
|
||||
|
||||
fs.appendFileSync(summaryPath, "\n---\n\n# Proposed\n\n")
|
||||
appendRfcsToSummary("mdbook/src/proposed/")
|
||||
|
||||
fs.appendFileSync(summaryPath, "\n---\n\n# Stale\n\n")
|
||||
appendRfcsToSummary("mdbook/src/stale/")
|
||||
}
|
||||
Reference in New Issue
Block a user