Skip to content

Commit e9f75e7

Browse files
committed
compile nav groups
1 parent ec36f95 commit e9f75e7

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

preview-src/ui-model.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ site:
33
title: Couchbase Docs
44
url: http://localhost:5252
55
homeUrl: &home_url /home.html
6+
keys:
7+
navGroups: |
8+
- title: Server
9+
startPage: home::server.adoc
10+
components: [server, '*-connector']
11+
- title: Mobile
12+
startPage: home::mobile.adoc
13+
components: [couchbase-lite, sync-gateway]
14+
- title: Cloud
15+
startPage: home::cloud.adoc
16+
components: [operator]
617
components:
718
server:
819
versions:

src/helpers/compile-nav-groups.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
const { inspect } = require('util')
4+
const yaml = require('js-yaml')
5+
6+
module.exports = ({ data: { root: { contentCatalog, site } } }) => {
7+
let navGroups = site.keys.navGroups
8+
if (!navGroups) return '[]'
9+
if (navGroups._compiled) return navGroups
10+
const components = site.components
11+
const componentNames = Object.keys(components)
12+
navGroups = yaml.load(navGroups).reduce((accum, navGroup) => {
13+
const componentsInGroup = navGroup.components.reduce((matched, componentName) => {
14+
if (~componentName.indexOf('*')) {
15+
const rx = new RegExp(`^${componentName.replace(/[*]/g, '.*?')}$`)
16+
return matched.concat(componentNames.filter((candidate) => rx.test(candidate)))
17+
} else if (componentName in components) {
18+
return matched.concat(componentName)
19+
}
20+
return matched
21+
}, [])
22+
if (!componentsInGroup.length) return accum
23+
let startPage = navGroup.startPage
24+
if (startPage) {
25+
startPage = contentCatalog ? contentCatalog.resolvePage(startPage) : { url: '/index.html' }
26+
if (startPage) navGroup.url = startPage.url
27+
delete navGroup.startPage
28+
}
29+
navGroup.components = componentsInGroup
30+
return accum.concat(navGroup)
31+
}, [])
32+
navGroups._compiled = true
33+
return (site.keys.navGroups = navGroups)
34+
}

src/helpers/stringify.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
module.exports = (object) => JSON.stringify(object)

src/js/01-nav.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
;(function () {
22
'use strict'
33

4+
var siteNavigationData = window.siteNavigationData.reduce(function (accum, entry) {
5+
accum[entry.name] = entry
6+
return accum
7+
}, {})
8+
window.siteNavigationGroups.forEach(function (group) {
9+
group.components.forEach(function (componentName) {
10+
var componentNavData = siteNavigationData[componentName]
11+
})
12+
})
13+
414
var nav = document.querySelector('nav.nav')
515
var menuExpandToggle = document.querySelector('.menu-expand-toggle')
616
var versionToggle = document.querySelector('.clickable')

src/partials/footer-scripts.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{{!-- may pass this path to site.js and have it load the navigation data --}}
22
<script src="{{siteRootPath}}/site-navigation-data.js"></script>
3+
<script>
4+
window.siteNavigationGroups = {{{stringify (compile-nav-groups)}}}
5+
</script>
36
<script src="{{{uiRootPath}}}/js/site.js"></script>
47
{{#with page.attributes.content-scripts}}
58
{{{this}}}

0 commit comments

Comments
 (0)