Start to make menu structure hierarchical via _menu.json files
authorNick Downing <nick@ndcode.org>
Mon, 1 Nov 2021 00:38:22 +0000 (11:38 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 1 Nov 2021 00:38:22 +0000 (11:38 +1100)
Site.js
package.json

diff --git a/Site.js b/Site.js
index 2f16cbd..b47dbfc 100644 (file)
--- a/Site.js
+++ b/Site.js
@@ -25,6 +25,7 @@ let JSONCache = require('@ndcode/json_cache')
 let JSONCacheRW = require('@ndcode/json_cache_rw')
 let JSTCache = require('@ndcode/jst_cache')
 let LessCSSCache = require('@ndcode/less_css_cache')
+let MenuCache = require('@ndcode/menu_cache')
 let MinCSSCache = require('@ndcode/min_css_cache')
 let MinJSCache = require('@ndcode/min_js_cache')
 let MinHTMLCache = require('@ndcode/min_html_cache')
@@ -74,6 +75,7 @@ let Site = function(resources, root, options/*, prev_site*/) {
   this.json_cache_rw = undefined
   this.jst_cache = undefined
   this.less_css_cache = undefined
+  this.menu_cache = undefined
   this.min_css_cache = undefined
   this.min_js_cache = undefined
   this.min_html_cache = undefined
@@ -109,6 +111,12 @@ Site.prototype.start = async function() {
     async () => new LessCSSCache(this.root, true)
   )
 
+  assert(this.menu_cache === undefined)
+  this.menu_cache = await this.resources.ref(
+    'menu_cache',
+    async () => new MenuCache(true)
+  )
+
   assert(this.min_css_cache === undefined)
   this.min_css_cache = await this.resources.ref(
     'min_css_cache',
@@ -159,6 +167,9 @@ Site.prototype.stop = async function() {
   assert(this.less_css_cache !== undefined)
   await this.resources.unref(`less_css_cache:${this.root}`)
 
+  assert(this.menu_cache !== undefined)
+  await this.resources.unref('menu_cache')
+
   assert(this.min_css_cache !== undefined)
   await this.resources.unref('min_css_cache')
 
@@ -191,6 +202,9 @@ Site.prototype.kick = async function() {
   assert(this.less_css_cache !== undefined)
   this.less_css_cache.kick()
 
+  assert(this.menu_cache !== undefined)
+  this.menu_cache.kick()
+
   assert(this.min_css_cache !== undefined)
   this.min_css_cache.kick()
 
@@ -301,6 +315,10 @@ Site.prototype.get_less_css = function(pathname) {
   return /*await*/ this.less_css_cache.get(this.root + pathname)
 }
 
+Site.prototype.get_menu = function(pathname) {
+  return /*await*/ this.menu_cache.get(this.root + pathname)
+}
+
 Site.prototype.get_min_css = function(pathname) {
   return /*await*/ this.min_css_cache.get(this.root + pathname)
 }
index 5dc3755..d118ad8 100644 (file)
@@ -30,6 +30,7 @@
     "@ndcode/json_cache_rw": "^0.1.0",
     "@ndcode/jst_cache": "^0.1.0",
     "@ndcode/less_css_cache": "^0.1.0",
+    "@ndcode/menu_cache": "^0.1.0",
     "@ndcode/min_css_cache": "^0.1.0",
     "@ndcode/min_html_cache": "^0.1.0",
     "@ndcode/min_js_cache": "^0.1.0",