11const fs = require ( 'fs' )
22const path = require ( 'path' )
3+ const cheerio = require ( 'cheerio' )
34const { liquid } = require ( '../../../lib/render-content' )
45const getMiniTocItems = require ( '../../../lib/get-mini-toc-items' )
6+ const rewriteLocalLinks = require ( '../../../lib/rewrite-local-links' )
57const includes = path . join ( process . cwd ( ) , 'includes' )
68const objectIncludeFile = fs . readFileSync ( path . join ( includes , 'graphql-object.html' ) , 'utf8' )
79// TODO need to localize
810const currentLanguage = 'en'
911
10- module . exports = async function prerenderObjects ( schemaJsonPerVersion ) {
12+ module . exports = async function prerenderObjects ( schemaJsonPerVersion , version ) {
1113 const site = await require ( '../../../lib/site-data' ) ( )
1214
1315 // create a bare minimum context for rendering the graphql-object.html layout
@@ -23,7 +25,10 @@ module.exports = async function prerenderObjects (schemaJsonPerVersion) {
2325 for ( const object of schemaJsonPerVersion . objects ) {
2426 context . item = object
2527 const objectHtml = await liquid . parseAndRender ( objectIncludeFile , context )
26- objectsArray . push ( objectHtml )
28+ const $ = cheerio . load ( objectHtml )
29+ rewriteLocalLinks ( $ , version , currentLanguage )
30+ const htmlWithVersionedLinks = $ . html ( )
31+ objectsArray . push ( htmlWithVersionedLinks )
2732 }
2833
2934 const objectsHtml = objectsArray . join ( '\n' )
0 commit comments