forked from github/docs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender-objects.js
More file actions
Latest commit
40 lines (34 loc) · 1.4 KB
/
Copy pathprerender-objects.js
File metadata and controls
40 lines (34 loc) · 1.4 KB
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
36
37
38
39
40
constfs=require('fs')
constpath=require('path')
constcheerio=require('cheerio')
const{ liquid }=require('../../../lib/render-content')
constgetMiniTocItems=require('../../../lib/get-mini-toc-items')
constrewriteLocalLinks=require('../../../lib/rewrite-local-links')
constincludes=path.join(process.cwd(),'includes')
constobjectIncludeFile=fs.readFileSync(path.join(includes,'graphql-object.html'),'utf8')
// TODO need to localize
constcurrentLanguage='en'
module.exports=asyncfunctionprerenderObjects(schemaJsonPerVersion,version){
constsite=awaitrequire('../../../lib/site-data')()
// create a bare minimum context for rendering the graphql-object.html layout
constcontext={
currentLanguage,
site: site[currentLanguage].site,
graphql: {schemaForCurrentVersion: schemaJsonPerVersion}
}
constobjectsArray=[]
// render the graphql-object.html layout for every object
for(constobjectofschemaJsonPerVersion.objects){
context.item=object
constobjectHtml=awaitliquid.parseAndRender(objectIncludeFile,context)
const$=cheerio.load(objectHtml,{xmlMode: true})
rewriteLocalLinks($,version,currentLanguage)
consthtmlWithVersionedLinks=$.html()
objectsArray.push(htmlWithVersionedLinks)
}
constobjectsHtml=objectsArray.join('\n')
return{
html: objectsHtml,
miniToc: getMiniTocItems(objectsHtml)
}
}