forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prerender graphql mutations page (github#23757)
- Loading branch information
Showing
6 changed files
with
7,263 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
import cheerio from 'cheerio' | ||
import { liquid } from '../../../lib/render-content/index.js' | ||
import getMiniTocItems from '../../../lib/get-mini-toc-items.js' | ||
import rewriteLocalLinks from '../../../lib/rewrite-local-links.js' | ||
const includes = path.join(process.cwd(), 'includes') | ||
|
||
export default async function prerender(context, type, includeFilename) { | ||
const htmlArray = [] | ||
|
||
const includeFile = await fs.readFile(path.join(includes, includeFilename), 'utf8') | ||
// render the layout for every object | ||
for (const item of context.graphql.schemaForCurrentVersion[type]) { | ||
context.item = item | ||
const itemHtml = await liquid.parseAndRender(includeFile, context) | ||
const $ = cheerio.load(itemHtml, { xmlMode: true }) | ||
rewriteLocalLinks($, context.currentVersion, context.currentLanguage) | ||
const htmlWithVersionedLinks = $.html() | ||
htmlArray.push(htmlWithVersionedLinks) | ||
} | ||
|
||
const html = htmlArray.join('\n') | ||
|
||
return { | ||
html: html, | ||
miniToc: getMiniTocItems(html), | ||
} | ||
} |