Move navigation from _menu.json files in each navigation-parent directory to a naviga...
[ndcode_site.git] / _lib / breadcrumbs.jst
index a9d9ae1..754a211 100644 (file)
@@ -1,27 +1,24 @@
 let assert = require('assert')
 
 return async (env, _out) => {
-  let pathname = env.parsed_url.pathname
-  assert(pathname.slice(0, 1) === '/')
+  // the breadcrumbs have already been determined by navbar.jst, as
+  // the HTML title is similar to the breadcrumbs (but without links)
+  let component_names = env.component_names
+  let component_titles = env.component_titles
 
-  // find number of path components, their positions, and names
-  let components = [{index: 0, name: 'Home'}]
-  for (let i = 1, j; (j = pathname.indexOf('/', i)) !== -1; i = j + 1) {
-    let menu = await env.site.get_menu(`${pathname.slice(0, i)}_menu.json`)
-    let dir = pathname.slice(i, j)
-    components.push({index: j, name: menu.entries[menu.index[dir]].name})
-  }
-
-  // present components as breadcrumbs, except last one as text
+  // present component_titles as breadcrumbs, except last one as text
   h2.mt-3 {
-    for (let i = 0; i < components.length - 1; ++i) {
+    for (let i = 0; i < component_names.length; ++i) {
       a.h4(
-        href=`${pathname.slice(0, components[i].index)}/index.html`
-      ) {`${components[i].name}`}
+        href=
+          `${
+            component_names.slice(0, i).map(name => '/' + name).join('')
+          }/index.html`
+      ) {`${component_titles[i]}`}
       ' '
       span.h5 {'>'}
       ' '
     }
-    `${components[components.length - 1].name}`
+    `${component_titles[component_names.length]}`
   }
 }