forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
4,546 additions
and
4 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
4,487 changes: 4,487 additions & 0 deletions
4,487
lib/graphql/static/prerendered-input-objects.json
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,40 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const cheerio = require('cheerio') | ||
const { liquid } = require('../../../lib/render-content') | ||
const getMiniTocItems = require('../../../lib/get-mini-toc-items') | ||
const rewriteLocalLinks = require('../../../lib/rewrite-local-links') | ||
const includes = path.join(process.cwd(), 'includes') | ||
const inputObjectIncludeFile = fs.readFileSync(path.join(includes, 'graphql-input-object.html'), 'utf8') | ||
// TODO need to localize | ||
const currentLanguage = 'en' | ||
|
||
module.exports = async function prerenderInputObjects (schemaJsonPerVersion, version) { | ||
const site = await require('../../../lib/site-data')() | ||
|
||
// create a bare minimum context for rendering the graphql-object.html layout | ||
const context = { | ||
currentLanguage, | ||
site: site[currentLanguage].site, | ||
graphql: { schemaForCurrentVersion: schemaJsonPerVersion } | ||
} | ||
|
||
const inputObjectsArray = [] | ||
|
||
// render the graphql-object.html layout for every object | ||
for (const inputObject of schemaJsonPerVersion.inputObjects) { | ||
context.item = inputObject | ||
const inputObjectHtml = await liquid.parseAndRender(inputObjectIncludeFile, context) | ||
const $ = cheerio.load(inputObjectHtml, { xmlMode: true }) | ||
rewriteLocalLinks($, version, currentLanguage) | ||
const htmlWithVersionedLinks = $.html() | ||
inputObjectsArray.push(htmlWithVersionedLinks) | ||
} | ||
|
||
const inputObjectsHtml = inputObjectsArray.join('\n') | ||
|
||
return { | ||
html: inputObjectsHtml, | ||
miniToc: getMiniTocItems(inputObjectsHtml) | ||
} | ||
} |