()
| 32 | main() |
| 33 | |
| 34 | async function main() { |
| 35 | const next = () => {} |
| 36 | const res = {} |
| 37 | const req = { language: 'en', cookies: {} } |
| 38 | |
| 39 | async function recurse(tree) { |
| 40 | const { page } = tree |
| 41 | tree.renderedFullTitle = page.rawTitle.includes('{') |
| 42 | ? await await liquid.parseAndRender(page.rawTitle, req.context) |
| 43 | : page.rawTitle |
| 44 | for (const node of tree.childPages || []) { |
| 45 | await recurse(node) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | for (const version of allVersionKeys) { |
| 50 | req.pagePath = version === fpt ? '/' : `/${version}` |
| 51 | |
| 52 | // Create a subdir for the version if one doesn't exist yet. |
| 53 | const versionStaticDir = path.posix.join(staticDir, version) |
| 54 | if (!fs.existsSync(versionStaticDir)) fs.mkdirSync(versionStaticDir) |
| 55 | |
| 56 | // Create a versioned filename. |
| 57 | const filename = path.posix.join(versionStaticDir, 'index.html') |
| 58 | |
| 59 | // Create a minimal context object. |
| 60 | await contextualize(req, res, next) |
| 61 | |
| 62 | // Add the tree to the req.context. |
| 63 | req.context.currentEnglishTree = req.context.siteTree.en[req.context.currentVersion] |
| 64 | |
| 65 | await recurse(req.context.currentEnglishTree) |
| 66 | |
| 67 | // Add any defaultOpenSections to the context. |
| 68 | req.context.defaultOpenSections = defaultOpenSections |
| 69 | |
| 70 | // Parse the layout in script/dev-toc/layout.html with the context we created above. |
| 71 | const outputHtml = await liquid.parseAndRender(layout, Object.assign({}, req.context)) |
| 72 | |
| 73 | // Write a static file for each version. |
| 74 | fs.writeFileSync(filename, outputHtml) |
| 75 | } |
| 76 | |
| 77 | // Default to FPT for the file to open. |
| 78 | const fptFile = path.posix.join(staticDirName, fpt, 'index.html') |
| 79 | |
| 80 | execSync(`open ${fptFile}`) |
| 81 | |
| 82 | console.log(`\nCreated the TOC! If it doesn't open automatically, open the following file in your browser to view it:\n |
| 83 | ${fptFile}`) |
| 84 | } |
no test coverage detected