Skip to content

Commit ec36f95

Browse files
committed
export navigation to site-navigation-data.js in preview site
1 parent 8748ef3 commit ec36f95

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

gulp.d/tasks/build-preview-pages.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Error.call = (self, ...args) => {
77
}
88

99
const asciidoctor = require('asciidoctor.js')()
10+
const File = require('vinyl')
1011
const fs = require('fs-extra')
1112
const handlebars = require('handlebars')
1213
const iconPacks = {
@@ -31,6 +32,7 @@ const iconShims = require('@fortawesome/fontawesome-free/js/v4-shims').reduce((a
3132
accum['fa-' + it[0]] = [it[1] || 'fas', 'fa-' + (it[2] || it[0])]
3233
return accum
3334
}, {})
35+
const { inspect } = require('util')
3436
const { obj: map } = require('through2')
3537
const merge = require('merge-stream')
3638
const ospath = require('path')
@@ -129,6 +131,7 @@ module.exports = (src, previewSrc, previewDest, sink = () => map()) => (done) =>
129131
}
130132
},
131133
function (done) {
134+
this.push(exportSiteNavigationData(baseUiModel.site.components))
132135
vfs
133136
.src('js/vendor/fontawesome-icon-defs.js', { base: src, cwd: src })
134137
.pipe(
@@ -229,6 +232,23 @@ function copyImages (src, dest) {
229232
return vfs.src('**/*.{png,svg}', { base: src, cwd: src }).pipe(vfs.dest(dest))
230233
}
231234

235+
function exportSiteNavigationData (components) {
236+
const navigationData = Object.values(components).map(({ name, title, versions }) => ({
237+
name,
238+
title,
239+
versions: versions.map(({ version, displayVersion, navigation: sets = [] }) =>
240+
version === displayVersion ? { version, sets } : { version, displayVersion, sets }
241+
),
242+
}))
243+
return new File({
244+
contents: Buffer.from(
245+
'window.siteNavigationData = ' +
246+
inspect(navigationData, { depth: null, maxArrayLength: null, breakLength: 250 })
247+
),
248+
path: 'site-navigation-data.js',
249+
})
250+
}
251+
232252
function findNavPath (currentUrl, node = [], current_path = [], root = true) {
233253
for (const item of node) {
234254
const { url, items } = item

src/partials/footer-scripts.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{!-- may pass this path to site.js and have it load the navigation data --}}
2+
<script src="{{siteRootPath}}/site-navigation-data.js"></script>
13
<script src="{{{uiRootPath}}}/js/site.js"></script>
24
{{#with page.attributes.content-scripts}}
35
{{{this}}}

0 commit comments

Comments
 (0)