feat: sidebar rendering
This commit is contained in:
parent
0b5a4e0c63
commit
763bf4b903
@ -1,19 +1,6 @@
|
||||
<template lang="pug">
|
||||
v-list(dense, :class='color', :dark='dark')
|
||||
v-list-tile.pt-2(href='/')
|
||||
v-list-tile-avatar: v-icon home
|
||||
v-list-tile-title Home
|
||||
v-divider.my-2
|
||||
v-subheader.pl-4 Navigation
|
||||
v-list-tile
|
||||
v-list-tile-avatar: v-icon stars
|
||||
v-list-tile-title The Universe
|
||||
v-list-tile
|
||||
v-list-tile-avatar: v-icon directions_boat
|
||||
v-list-tile-title Ships
|
||||
v-list-tile
|
||||
v-list-tile-avatar: v-icon local_airport
|
||||
v-list-tile-title Airports
|
||||
v-list.py-2(dense, :class='color', :dark='dark')
|
||||
slot
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -12,6 +12,7 @@
|
||||
v-model='navShown'
|
||||
)
|
||||
nav-sidebar
|
||||
slot(name='sidebar')
|
||||
|
||||
v-content
|
||||
v-toolbar(color='grey lighten-3', flat, dense)
|
||||
|
@ -75,7 +75,8 @@ router.get('/*', async (req, res, next) => {
|
||||
isPrivate: false
|
||||
})
|
||||
if (page) {
|
||||
res.render('page', { page })
|
||||
const sidebar = await WIKI.models.navigation.getTree({ cache: true })
|
||||
res.render('page', { page, sidebar })
|
||||
} else if (pageArgs.path === 'home') {
|
||||
res.render('welcome')
|
||||
} else {
|
||||
|
@ -21,6 +21,7 @@ module.exports = {
|
||||
await WIKI.models.navigation.query().patch({
|
||||
config: args.tree
|
||||
}).where('key', 'site')
|
||||
await WIKI.redis.set('nav:sidebar', JSON.stringify(args.tree), 'EX', 300)
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
|
||||
|
@ -21,9 +21,18 @@ module.exports = class Navigation extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static async getTree() {
|
||||
static async getTree({ cache = false } = {}) {
|
||||
if (cache) {
|
||||
const navTreeCached = await WIKI.redis.get('nav:sidebar')
|
||||
if (navTreeCached) {
|
||||
return JSON.parse(navTreeCached)
|
||||
}
|
||||
}
|
||||
const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
|
||||
if (navTree) {
|
||||
if (cache) {
|
||||
await WIKI.redis.set('nav:sidebar', JSON.stringify(navTree.config), 'EX', 300)
|
||||
}
|
||||
return navTree.config
|
||||
} else {
|
||||
WIKI.logger.warn('Site Navigation is missing or corrupted.')
|
||||
|
@ -1,4 +1,5 @@
|
||||
const path = require('path')
|
||||
const uuid = require('uuid/v4')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@ -209,6 +210,7 @@ module.exports = () => {
|
||||
key: 'site',
|
||||
config: [
|
||||
{
|
||||
id: uuid(),
|
||||
icon: 'home',
|
||||
kind: 'link',
|
||||
label: 'Home',
|
||||
|
@ -16,4 +16,17 @@ block body
|
||||
:author-id=page.authorId
|
||||
:is-published=page.isPublished
|
||||
)
|
||||
template(slot='sidebar')
|
||||
each navItem in sidebar
|
||||
if navItem.kind === 'link'
|
||||
v-list-tile(
|
||||
href=navItem.target
|
||||
)
|
||||
v-list-tile-avatar
|
||||
v-icon= navItem.icon
|
||||
v-list-tile-title= navItem.label
|
||||
else if navItem.kind === 'divider'
|
||||
v-divider.my-2
|
||||
else if navItem.kind === 'header'
|
||||
v-subheader.pl-4= navItem.label
|
||||
template(slot='contents')!= page.render
|
||||
|
Loading…
Reference in New Issue
Block a user