generated from tonytrangmail/docs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prerender-objects.js
35 lines (29 loc) · 1.13 KB
/
prerender-objects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs')
const path = require('path')
const { liquid } = require('../../../lib/render-content')
const getMiniTocItems = require('../../../lib/get-mini-toc-items')
const includes = path.join(process.cwd(), 'includes')
const objectIncludeFile = fs.readFileSync(path.join(includes, 'graphql-object.html'), 'utf8')
// TODO need to localize
const currentLanguage = 'en'
module.exports = async function prerenderObjects (schemaJsonPerVersion) {
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 objectsArray = []
// render the graphql-object.html layout for every object
for (const object of schemaJsonPerVersion.objects) {
context.item = object
const objectHtml = await liquid.parseAndRender(objectIncludeFile, context)
objectsArray.push(objectHtml)
}
const objectsHtml = objectsArray.join('\n')
return {
html: objectsHtml,
miniToc: getMiniTocItems(objectsHtml)
}
}