Merge pull request #1 from TimoKruth/feat-toc

Feat toc
pull/7307/head
Timo Kruth 1 year ago committed by GitHub
commit b2208ac350
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,7 +8,7 @@
"vue" "vue"
], ],
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": "explicit"
}, },
"i18n-ally.localesPaths": [ "i18n-ally.localesPaths": [
"server/locales" "server/locales"

@ -51,7 +51,6 @@
persistent-hint persistent-hint
:hint='$t(`admin:theme.darkModeHint`)' :hint='$t(`admin:theme.darkModeHint`)'
) )
v-card.mt-3.animated.fadeInUp.wait-p1s v-card.mt-3.animated.fadeInUp.wait-p1s
v-toolbar(color='primary', dark, dense, flat) v-toolbar(color='primary', dark, dense, flat)
v-toolbar-title.subtitle-1 {{$t(`admin:theme.options`)}} v-toolbar-title.subtitle-1 {{$t(`admin:theme.options`)}}
@ -65,32 +64,16 @@
persistent-hint persistent-hint
hint='Select whether the table of contents is shown on the left, right or not at all.' hint='Select whether the table of contents is shown on the left, right or not at all.'
) )
v-range-slider(
prepend-icon='mdi-menu-open'
label='Heading Levels in ToC'
v-model='tocRange'
:min='1'
:max='6'
:tick-labels='["H1", "H2", "H3", "H4", "H5", "H6"]'
hint='Select which levels of the toc are displayed.'
)
v-flex(lg6 xs12) v-flex(lg6 xs12)
//- v-card.animated.fadeInUp.wait-p2s
//- v-toolbar(color='teal', dark, dense, flat)
//- v-toolbar-title.subtitle-1 {{$t('admin:theme.downloadThemes')}}
//- v-spacer
//- v-chip(label, color='white', small).teal--text coming soon
//- v-data-table(
//- :headers='headers',
//- :items='themes',
//- hide-default-footer,
//- item-key='value',
//- :items-per-page='1000'
//- )
//- template(v-slot:item='thm')
//- td
//- strong {{thm.item.text}}
//- td
//- span {{ thm.item.author }}
//- td.text-xs-center
//- v-progress-circular(v-if='thm.item.isDownloading', indeterminate, color='blue', size='20', :width='2')
//- v-btn(v-else-if='thm.item.isInstalled && thm.item.installDate < thm.item.updatedAt', icon)
//- v-icon.blue--text mdi-cached
//- v-btn(v-else-if='thm.item.isInstalled', icon)
//- v-icon.green--text mdi-check-bold
//- v-btn(v-else, icon)
//- v-icon.grey--text mdi-cloud-download
v-card.animated.fadeInUp.wait-p2s v-card.animated.fadeInUp.wait-p2s
v-toolbar(color='primary', dark, dense, flat) v-toolbar(color='primary', dark, dense, flat)
@ -150,6 +133,10 @@ export default {
config: { config: {
theme: 'default', theme: 'default',
darkMode: false, darkMode: false,
tocDepth: {
min: 1,
max: 2
},
iconset: '', iconset: '',
tocPosition: 'left', tocPosition: 'left',
injectCSS: '', injectCSS: '',
@ -160,6 +147,18 @@ export default {
} }
}, },
computed: { computed: {
tocRange: {
get() {
var range = [this.config.tocDepth.min, this.config.tocDepth.max]
return range
},
set(value) {
this.config.tocDepth = {
min: parseInt(value[0]),
max: parseInt(value[1])
}
}
},
darkMode: sync('site/dark'), darkMode: sync('site/dark'),
headers() { headers() {
return [ return [
@ -213,6 +212,7 @@ export default {
theme: this.config.theme, theme: this.config.theme,
iconset: this.config.iconset, iconset: this.config.iconset,
darkMode: this.darkMode, darkMode: this.darkMode,
tocDepth: this.config.tocDepth,
tocPosition: this.config.tocPosition, tocPosition: this.config.tocPosition,
injectCSS: this.config.injectCSS, injectCSS: this.config.injectCSS,
injectHead: this.config.injectHead, injectHead: this.config.injectHead,

@ -145,6 +145,10 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
tocOptions: {
type: String,
default: ''
},
checkoutDate: { checkoutDate: {
type: String, type: String,
default: new Date().toISOString() default: new Date().toISOString()
@ -172,7 +176,9 @@ export default {
tags: '', tags: '',
title: '', title: '',
css: '', css: '',
js: '' js: '',
tocDepth: 0,
useDefaultTocDepth: false
} }
} }
}, },
@ -191,6 +197,8 @@ export default {
this.path !== this.$store.get('page/path'), this.path !== this.$store.get('page/path'),
this.savedState.title !== this.$store.get('page/title'), this.savedState.title !== this.$store.get('page/title'),
this.savedState.description !== this.$store.get('page/description'), this.savedState.description !== this.$store.get('page/description'),
this.savedState.tocDepth !== this.$store.get('page/tocDepth@min') + (this.$store.get('page/tocDepth@max') * 10),
this.savedState.useDefaultTocDepth !== this.$store.get('page/useDefaultTocDepth'),
this.savedState.tags !== this.$store.get('page/tags'), this.savedState.tags !== this.$store.get('page/tags'),
this.savedState.isPublished !== this.$store.get('page/isPublished'), this.savedState.isPublished !== this.$store.get('page/isPublished'),
this.savedState.publishStartDate !== this.$store.get('page/publishStartDate'), this.savedState.publishStartDate !== this.$store.get('page/publishStartDate'),
@ -224,9 +232,15 @@ export default {
this.$store.set('page/title', this.title) this.$store.set('page/title', this.title)
this.$store.set('page/scriptCss', this.scriptCss) this.$store.set('page/scriptCss', this.scriptCss)
this.$store.set('page/scriptJs', this.scriptJs) this.$store.set('page/scriptJs', this.scriptJs)
this.$store.set('page/mode', 'edit') this.$store.set('page/mode', 'edit')
const tocOptions = JSON.parse(Buffer.from(this.tocOptions, 'base64').toString())
this.$store.set('page/tocDepth', {
min: tocOptions.min,
max: tocOptions.max
})
this.$store.set('page/useDefaultTocDepth', tocOptions.useDefault)
this.setCurrentSavedState() this.setCurrentSavedState()
this.checkoutDateActive = this.checkoutDate this.checkoutDateActive = this.checkoutDate
@ -304,6 +318,8 @@ export default {
$publishStartDate: Date $publishStartDate: Date
$scriptCss: String $scriptCss: String
$scriptJs: String $scriptJs: String
$tocDepth: RangeInput
$useDefaultTocDepth: Boolean
$tags: [String]! $tags: [String]!
$title: String! $title: String!
) { ) {
@ -320,6 +336,8 @@ export default {
publishStartDate: $publishStartDate publishStartDate: $publishStartDate
scriptCss: $scriptCss scriptCss: $scriptCss
scriptJs: $scriptJs scriptJs: $scriptJs
tocDepth: $tocDepth
useDefaultTocDepth: $useDefaultTocDepth
tags: $tags tags: $tags
title: $title title: $title
) { ) {
@ -349,6 +367,8 @@ export default {
publishStartDate: this.$store.get('page/publishStartDate') || '', publishStartDate: this.$store.get('page/publishStartDate') || '',
scriptCss: this.$store.get('page/scriptCss'), scriptCss: this.$store.get('page/scriptCss'),
scriptJs: this.$store.get('page/scriptJs'), scriptJs: this.$store.get('page/scriptJs'),
tocDepth: this.$store.get('page/tocDepth'),
useDefaultTocDepth: this.$store.get('page/useDefaultTocDepth'),
tags: this.$store.get('page/tags'), tags: this.$store.get('page/tags'),
title: this.$store.get('page/title') title: this.$store.get('page/title')
} }
@ -392,7 +412,6 @@ export default {
this.$root.$emit('saveConflict') this.$root.$emit('saveConflict')
throw new Error(this.$t('editor:conflict.warning')) throw new Error(this.$t('editor:conflict.warning'))
} }
let resp = await this.$apollo.mutate({ let resp = await this.$apollo.mutate({
mutation: gql` mutation: gql`
mutation ( mutation (
@ -408,6 +427,8 @@ export default {
$publishStartDate: Date $publishStartDate: Date
$scriptCss: String $scriptCss: String
$scriptJs: String $scriptJs: String
$tocDepth: RangeInput
$useDefaultTocDepth: Boolean
$tags: [String] $tags: [String]
$title: String $title: String
) { ) {
@ -425,6 +446,8 @@ export default {
publishStartDate: $publishStartDate publishStartDate: $publishStartDate
scriptCss: $scriptCss scriptCss: $scriptCss
scriptJs: $scriptJs scriptJs: $scriptJs
tocDepth: $tocDepth
useDefaultTocDepth: $useDefaultTocDepth
tags: $tags tags: $tags
title: $title title: $title
) { ) {
@ -454,6 +477,8 @@ export default {
publishStartDate: this.$store.get('page/publishStartDate') || '', publishStartDate: this.$store.get('page/publishStartDate') || '',
scriptCss: this.$store.get('page/scriptCss'), scriptCss: this.$store.get('page/scriptCss'),
scriptJs: this.$store.get('page/scriptJs'), scriptJs: this.$store.get('page/scriptJs'),
tocDepth: this.$store.get('page/tocDepth'),
useDefaultTocDepth: this.$store.get('page/useDefaultTocDepth'),
tags: this.$store.get('page/tags'), tags: this.$store.get('page/tags'),
title: this.$store.get('page/title') title: this.$store.get('page/title')
} }
@ -536,7 +561,9 @@ export default {
tags: this.$store.get('page/tags'), tags: this.$store.get('page/tags'),
title: this.$store.get('page/title'), title: this.$store.get('page/title'),
css: this.$store.get('page/scriptCss'), css: this.$store.get('page/scriptCss'),
js: this.$store.get('page/scriptJs') js: this.$store.get('page/scriptJs'),
tocDepth: this.$store.get('page/tocDepth@min') + (this.$store.get('page/tocDepth@max') * 10),
useDefaultTocDepth: this.$store.get('page/useDefaultTocDepth')
} }
}, },
injectCustomCss: _.debounce(css => { injectCustomCss: _.debounce(css => {

@ -1,5 +1,5 @@
<template lang='pug'> <template lang='pug'>
v-dialog( v-dialog(
v-model='isShown' v-model='isShown'
persistent persistent
width='1000' width='1000'
@ -19,9 +19,9 @@
v-card(tile) v-card(tile)
v-tabs(color='white', background-color='blue darken-1', dark, centered, v-model='currentTab') v-tabs(color='white', background-color='blue darken-1', dark, centered, v-model='currentTab')
v-tab {{$t('editor:props.info')}} v-tab {{$t('editor:props.info')}}
v-tab {{$t('editor:props.toc')}}
v-tab {{$t('editor:props.scheduling')}} v-tab {{$t('editor:props.scheduling')}}
v-tab(:disabled='!hasScriptPermission') {{$t('editor:props.scripts')}} v-tab(:disabled='!hasScriptPermission') {{$t('editor:props.scripts')}}
v-tab(disabled) {{$t('editor:props.social')}}
v-tab(:disabled='!hasStylePermission') {{$t('editor:props.styles')}} v-tab(:disabled='!hasStylePermission') {{$t('editor:props.styles')}}
v-tab-item(transition='fade-transition', reverse-transition='fade-transition') v-tab-item(transition='fade-transition', reverse-transition='fade-transition')
v-card-text.pt-5 v-card-text.pt-5
@ -90,6 +90,24 @@
hide-no-data hide-no-data
:search-input.sync='newTagSearch' :search-input.sync='newTagSearch'
) )
v-tab-item(transition='fade-transition', reverse-transition='fade-transition')
v-card-text
.overline.pb-5 {{$t('editor:props.tocTitle')}}
v-switch(
:label='$t(`editor:props.tocUseDefault`)'
v-model='useDefaultTocDepth'
)
v-range-slider(
:disabled='useDefaultTocDepth'
prepend-icon='mdi-menu-open'
:label='$t(`editor:props.tocHeadingLevels`)'
v-model='tocDepth'
:min='1'
:max='6'
:tick-labels='["H1", "H2", "H3", "H4", "H5", "H6"]'
)
.text-caption.pl-8.grey--text {{$t('editor:props.tocHeadingLevelsHint')}}
v-tab-item(transition='fade-transition', reverse-transition='fade-transition') v-tab-item(transition='fade-transition', reverse-transition='fade-transition')
v-card-text v-card-text
.overline {{$t('editor:props.publishState')}} .overline {{$t('editor:props.publishState')}}
@ -196,43 +214,6 @@
.editor-props-codeeditor-hint .editor-props-codeeditor-hint
.caption {{$t('editor:props.htmlHint')}} .caption {{$t('editor:props.htmlHint')}}
v-tab-item(transition='fade-transition', reverse-transition='fade-transition')
v-card-text
.overline {{$t('editor:props.socialFeatures')}}
v-switch(
:label='$t(`editor:props.allowComments`)'
v-model='isPublished'
color='primary'
:hint='$t(`editor:props.allowCommentsHint`)'
persistent-hint
inset
)
v-switch(
:label='$t(`editor:props.allowRatings`)'
v-model='isPublished'
color='primary'
:hint='$t(`editor:props.allowRatingsHint`)'
persistent-hint
disabled
inset
)
v-switch(
:label='$t(`editor:props.displayAuthor`)'
v-model='isPublished'
color='primary'
:hint='$t(`editor:props.displayAuthorHint`)'
persistent-hint
inset
)
v-switch(
:label='$t(`editor:props.displaySharingBar`)'
v-model='isPublished'
color='primary'
:hint='$t(`editor:props.displaySharingBarHint`)'
persistent-hint
inset
)
v-tab-item(:transition='false', :reverse-transition='false') v-tab-item(:transition='false', :reverse-transition='false')
.editor-props-codeeditor-title .editor-props-codeeditor-title
.overline {{$t('editor:props.css')}} .overline {{$t('editor:props.css')}}
@ -255,6 +236,7 @@ import 'codemirror/mode/htmlmixed/htmlmixed.js'
import 'codemirror/mode/css/css.js' import 'codemirror/mode/css/css.js'
/* global siteLangs, siteConfig */ /* global siteLangs, siteConfig */
// eslint-disable-next-line no-useless-escape
const filenamePattern = /^(?![\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s])(?!.*[\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]$)[^\#\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]*$/ const filenamePattern = /^(?![\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s])(?!.*[\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]$)[^\#\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]*$/
export default { export default {
@ -276,10 +258,10 @@ export default {
currentTab: 0, currentTab: 0,
cm: null, cm: null,
rules: { rules: {
required: value => !!value || 'This field is required.', required: value => !!value || 'This field is required.',
path: value => { path: value => {
return filenamePattern.test(value) || 'Invalid path. Please ensure it does not contain special characters, or begin/end in a slash or hashtag string.' return filenamePattern.test(value) || 'Invalid path. Please ensure it does not contain special characters, or begin/end in a slash or hashtag string.'
} }
} }
} }
}, },
@ -297,6 +279,19 @@ export default {
isPublished: sync('page/isPublished'), isPublished: sync('page/isPublished'),
publishStartDate: sync('page/publishStartDate'), publishStartDate: sync('page/publishStartDate'),
publishEndDate: sync('page/publishEndDate'), publishEndDate: sync('page/publishEndDate'),
tocDepth: {
get() {
const tocDepth = this.$store.get('page/tocDepth')
return [tocDepth.min, tocDepth.max]
},
set(value) {
this.$store.set('page/tocDepth', {
min: parseInt(value[0]),
max: parseInt(value[1])
})
}
},
useDefaultTocDepth: sync('page/useDefaultTocDepth'),
scriptJs: sync('page/scriptJs'), scriptJs: sync('page/scriptJs'),
scriptCss: sync('page/scriptCss'), scriptCss: sync('page/scriptCss'),
hasScriptPermission: get('page/effectivePermissions@pages.script'), hasScriptPermission: get('page/effectivePermissions@pages.script'),
@ -328,7 +323,7 @@ export default {
if (this.cm) { if (this.cm) {
this.cm.toTextArea() this.cm.toTextArea()
} }
if (newValue === 2) { if (newValue === 3) {
this.$nextTick(() => { this.$nextTick(() => {
setTimeout(() => { setTimeout(() => {
this.loadEditor(this.$refs.codejs, 'html') this.loadEditor(this.$refs.codejs, 'html')

@ -1,6 +1,6 @@
mutation($theme: String!, $iconset: String!, $darkMode: Boolean!, $tocPosition: String, $injectCSS: String, $injectHead: String, $injectBody: String) { mutation($theme: String!, $iconset: String!, $darkMode: Boolean!, $tocPosition: String, $tocDepth: RangeInput!, $injectCSS: String, $injectHead: String, $injectBody: String) {
theming { theming {
setConfig(theme: $theme, iconset: $iconset, darkMode: $darkMode, tocPosition: $tocPosition, injectCSS: $injectCSS, injectHead: $injectHead, injectBody: $injectBody) { setConfig(theme: $theme, iconset: $iconset, darkMode: $darkMode, tocPosition: $tocPosition, tocDepth: $tocDepth, injectCSS: $injectCSS, injectHead: $injectHead, injectBody: $injectBody) {
responseResult { responseResult {
succeeded succeeded
errorCode errorCode

@ -4,6 +4,10 @@ query {
theme theme
iconset iconset
darkMode darkMode
tocDepth {
min
max
}
tocPosition tocPosition
injectCSS injectCSS
injectHead injectHead

@ -17,6 +17,11 @@ const state = {
editor: '', editor: '',
mode: '', mode: '',
scriptJs: '', scriptJs: '',
tocDepth: {
min: 1,
max: 2
},
useDefaultTocDepth: true,
scriptCss: '', scriptCss: '',
effectivePermissions: { effectivePermissions: {
comments: { comments: {

@ -0,0 +1,72 @@
<template lang="pug">
.page-toc-item
template(v-if='level >= min')
v-list-item(@click='click(item.anchor)', v-if='max > level', :key='item.anchor', :class='[isNestedLevel ? "pl-9" : "pl-6"]')
v-icon.pl-0(small, color='grey lighten-1', v-if='item.children.length > 0') {{ $vuetify.rtl ? `mdi-menu-up` : `mdi-menu-up` }}
v-list-item-title.pl-4(v-bind:class='titleClasses') {{item.title}}
v-list-group(v-else, sub-group, v-bind:class='{"pl-6": isNestedLevel}')
template(v-slot:activator)
v-list-item.pl-0(@click='click(item.anchor)', :key='item.anchor')
v-list-item-title(v-bind:class='titleClasses') {{item.title}}
page-toc-item(v-if='item.children.length > 0', v-for='subItem in item.children', :key='subItem.anchor', :item='subItem', :level='level + 1', :min='min', :max='max')
page-toc-item(v-show='max > level && item.children.length > 0', v-for='subItem in item.children', :key='subItem.anchor', :item='subItem', :level='level + 1', :min='min', :max='max')
</template>
<script>
export default {
name: 'PageTocItem',
props: {
item: {
type: Object,
default: () => {}
},
min: {
type: Number,
default: 1
},
max: {
type: Number,
default: 2
},
level: {
type: Number,
default: 1
}
},
data() {
return {
scrollOpts: {
duration: 1500,
offset: 0,
easing: 'easeInOutCubic'
}
}
},
computed: {
isNestedLevel() {
return this.level > this.min
},
titleClasses() {
return {
'caption': this.isNestedLevel,
'grey--text': this.isNestedLevel,
'text--lighten-1': this.$vuetify.theme.dark && this.isNestedLevel,
'text--darken-1': !this.$vuetify.theme.dark && this.isNestedLevel
}
}
},
methods: {
click (anchor) {
this.$vuetify.goTo(anchor, this.scrollOpts)
}
}
}
</script>
<style lang='scss'>
// Hack to fix animations of multi level nesting v-list-group
.page-toc-item .v-list-group--sub-group.v-list-group--active .v-list-item:not(.v-list-item--active) .v-list-item__icon.v-list-group__header__prepend-icon .v-icon {
transform: rotate(0deg)!important;
}
</style>

@ -94,18 +94,14 @@
) )
v-card.page-toc-card.mb-5(v-if='tocDecoded.length') v-card.page-toc-card.mb-5(v-if='tocDecoded.length')
.overline.pa-5.pb-0(:class='$vuetify.theme.dark ? `blue--text text--lighten-2` : `primary--text`') {{$t('common:page.toc')}} .overline.pa-5.pb-0(:class='$vuetify.theme.dark ? `blue--text text--lighten-2` : `primary--text`') {{$t('common:page.toc')}}
v-list.pb-3(dense, nav, :class='$vuetify.theme.dark ? `darken-3-d3` : ``') v-list.py-2(dense, nav, :class='$vuetify.theme.dark ? `darken-3-d3` : ``')
template(v-for='(tocItem, tocIdx) in tocDecoded') page-toc-item(
v-list-item(@click='$vuetify.goTo(tocItem.anchor, scrollOpts)') v-for='(item, idx) in tocDecoded'
v-icon(color='grey', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }} :key='`tocitem-` + idx'
v-list-item-title.px-3 {{tocItem.title}} :item='item'
//- v-divider(v-if='tocIdx < toc.length - 1 || tocItem.children.length') :min='tocOptionsDecoded.min'
template(v-for='tocSubItem in tocItem.children') :max='tocOptionsDecoded.max'
v-list-item(@click='$vuetify.goTo(tocSubItem.anchor, scrollOpts)') )
v-icon.px-3(color='grey lighten-1', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
v-list-item-title.px-3.caption.grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-1`') {{tocSubItem.title}}
//- v-divider(inset, v-if='tocIdx < toc.length - 1')
v-card.page-tags-card.mb-5(v-if='tags.length > 0') v-card.page-tags-card.mb-5(v-if='tags.length > 0')
.pa-5 .pa-5
.overline.teal--text.pb-2(:class='$vuetify.theme.dark ? `text--lighten-3` : ``') {{$t('common:page.tags')}} .overline.teal--text.pb-2(:class='$vuetify.theme.dark ? `text--lighten-3` : ``') {{$t('common:page.tags')}}
@ -360,6 +356,7 @@
import { StatusIndicator } from 'vue-status-indicator' import { StatusIndicator } from 'vue-status-indicator'
import Tabset from './tabset.vue' import Tabset from './tabset.vue'
import NavSidebar from './nav-sidebar.vue' import NavSidebar from './nav-sidebar.vue'
import PageTocItem from './page-toc-item.vue'
import Prism from 'prismjs' import Prism from 'prismjs'
import mermaid from 'mermaid' import mermaid from 'mermaid'
import { get, sync } from 'vuex-pathify' import { get, sync } from 'vuex-pathify'
@ -407,6 +404,7 @@ Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
export default { export default {
components: { components: {
NavSidebar, NavSidebar,
PageTocItem,
StatusIndicator StatusIndicator
}, },
props: { props: {
@ -489,6 +487,10 @@ export default {
filename: { filename: {
type: String, type: String,
default: '' default: ''
},
tocOptions: {
type: String,
default: ''
} }
}, },
data() { data() {
@ -560,12 +562,16 @@ export default {
return JSON.parse(Buffer.from(this.toc, 'base64').toString()) return JSON.parse(Buffer.from(this.toc, 'base64').toString())
}, },
tocPosition: get('site/tocPosition'), tocPosition: get('site/tocPosition'),
tocOptionsDecoded () {
return JSON.parse(Buffer.from(this.tocOptions, 'base64').toString())
},
hasAdminPermission: get('page/effectivePermissions@system.manage'), hasAdminPermission: get('page/effectivePermissions@system.manage'),
hasWritePagesPermission: get('page/effectivePermissions@pages.write'), hasWritePagesPermission: get('page/effectivePermissions@pages.write'),
hasManagePagesPermission: get('page/effectivePermissions@pages.manage'), hasManagePagesPermission: get('page/effectivePermissions@pages.manage'),
hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'), hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'),
hasReadSourcePermission: get('page/effectivePermissions@source.read'), hasReadSourcePermission: get('page/effectivePermissions@source.read'),
hasReadHistoryPermission: get('page/effectivePermissions@history.read'), hasReadHistoryPermission: get('page/effectivePermissions@history.read'),
hasAnyPagePermissions () { hasAnyPagePermissions () {
return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission || return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission ||
this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission

@ -60,6 +60,9 @@ defaults:
theme: 'default' theme: 'default'
iconset: 'md' iconset: 'md'
darkMode: false darkMode: false
tocDepth:
min: 1
max: 2
tocPosition: 'left' tocPosition: 'left'
auth: auth:
autoLogin: false autoLogin: false

@ -179,6 +179,11 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
title: null, title: null,
description: null, description: null,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
tocOptions: {
min: 1,
max: 2,
useDefault: true
},
extra: { extra: {
css: '', css: '',
js: '' js: ''
@ -507,6 +512,13 @@ router.get('/*', async (req, res, next) => {
injectCode.body = `${injectCode.body}\n${page.extra.js}` injectCode.body = `${injectCode.body}\n${page.extra.js}`
} }
// -> Set TOC display options
const tocOptions = _.get(page, 'tocOptions.useDefault', true) ?
WIKI.config.theming.tocDepth : {
min: page.tocOptions.min,
max: page.tocOptions.max
}
if (req.query.legacy || req.get('user-agent').indexOf('Trident') >= 0) { if (req.query.legacy || req.get('user-agent').indexOf('Trident') >= 0) {
// -> Convert page TOC // -> Convert page TOC
if (_.isString(page.toc)) { if (_.isString(page.toc)) {
@ -552,6 +564,7 @@ router.get('/*', async (req, res, next) => {
res.render('page', { res.render('page', {
page, page,
sidebar, sidebar,
tocOptions,
injectCode, injectCode,
comments: commentTmpl, comments: commentTmpl,
effectivePermissions, effectivePermissions,

@ -0,0 +1,12 @@
exports.up = async knex => {
await knex.schema
.alterTable('pages', table => {
table.json('tocOptions').notNullable().defaultTo(JSON.stringify({
min: 1,
max: 2,
useDefault: true
}))
})
}
exports.down = knex => { }

@ -0,0 +1,12 @@
exports.up = async knex => {
await knex.schema
.alterTable('pages', table => {
table.json('tocOptions').notNullable().defaultTo(JSON.stringify({
min: 1,
max: 2,
useDefault: true
}))
})
}
exports.down = knex => { }

@ -24,6 +24,7 @@ module.exports = {
theme: WIKI.config.theming.theme, theme: WIKI.config.theming.theme,
iconset: WIKI.config.theming.iconset, iconset: WIKI.config.theming.iconset,
darkMode: WIKI.config.theming.darkMode, darkMode: WIKI.config.theming.darkMode,
tocDepth: WIKI.config.theming.tocDepth,
tocPosition: WIKI.config.theming.tocPosition || 'left', tocPosition: WIKI.config.theming.tocPosition || 'left',
injectCSS: new CleanCSS({ format: 'beautify' }).minify(WIKI.config.theming.injectCSS).styles, injectCSS: new CleanCSS({ format: 'beautify' }).minify(WIKI.config.theming.injectCSS).styles,
injectHead: WIKI.config.theming.injectHead, injectHead: WIKI.config.theming.injectHead,
@ -45,6 +46,7 @@ module.exports = {
theme: args.theme, theme: args.theme,
iconset: args.iconset, iconset: args.iconset,
darkMode: args.darkMode, darkMode: args.darkMode,
tocDepth: args.tocDepth,
tocPosition: args.tocPosition || 'left', tocPosition: args.tocPosition || 'left',
injectCSS: args.injectCSS || '', injectCSS: args.injectCSS || '',
injectHead: args.injectHead || '', injectHead: args.injectHead || '',

@ -21,6 +21,17 @@ input KeyValuePairInput {
value: String! value: String!
} }
# Generic Range Value
type Range {
min: Int
max: Int
}
input RangeInput {
min: Int!
max: Int!
}
# Generic Mutation Response # Generic Mutation Response
type DefaultResponse { type DefaultResponse {
responseResult: ResponseStatus responseResult: ResponseStatus

@ -98,6 +98,8 @@ type PageMutation {
scriptJs: String scriptJs: String
tags: [String]! tags: [String]!
title: String! title: String!
tocDepth: RangeInput
useDefaultTocDepth: Boolean
): PageResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"]) ): PageResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"])
update( update(
@ -115,6 +117,8 @@ type PageMutation {
scriptJs: String scriptJs: String
tags: [String] tags: [String]
title: String title: String
tocDepth: RangeInput
useDefaultTocDepth: Boolean
): PageResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"]) ): PageResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"])
convert( convert(
@ -180,33 +184,35 @@ type PageMigrationResponse {
} }
type Page { type Page {
id: Int! id: Int
path: String! path: String
hash: String! hash: String
title: String! title: String
description: String! description: String
isPrivate: Boolean! @auth(requires: ["write:pages", "manage:system"]) isPrivate: Boolean @auth(requires: ["write:pages", "manage:system"])
isPublished: Boolean! @auth(requires: ["write:pages", "manage:system"]) isPublished: Boolean @auth(requires: ["write:pages", "manage:system"])
privateNS: String @auth(requires: ["write:pages", "manage:system"]) privateNS: String @auth(requires: ["write:pages", "manage:system"])
publishStartDate: Date! @auth(requires: ["write:pages", "manage:system"]) publishStartDate: Date @auth(requires: ["write:pages", "manage:system"])
publishEndDate: Date! @auth(requires: ["write:pages", "manage:system"]) publishEndDate: Date @auth(requires: ["write:pages", "manage:system"])
tags: [PageTag]! tags: [PageTag]
content: String! @auth(requires: ["read:source", "write:pages", "manage:system"]) content: String @auth(requires: ["read:source", "write:pages", "manage:system"])
render: String render: String
toc: String toc: String
contentType: String! tocDepth: Range
createdAt: Date! useDefaultTocDepth: Boolean
updatedAt: Date! contentType: String
editor: String! @auth(requires: ["write:pages", "manage:system"]) createdAt: Date
locale: String! updatedAt: Date
editor: String @auth(requires: ["write:pages", "manage:system"])
locale: String
scriptCss: String scriptCss: String
scriptJs: String scriptJs: String
authorId: Int! @auth(requires: ["write:pages", "manage:system"]) authorId: Int @auth(requires: ["write:pages", "manage:system"])
authorName: String! @auth(requires: ["write:pages", "manage:system"]) authorName: String @auth(requires: ["write:pages", "manage:system"])
authorEmail: String! @auth(requires: ["write:pages", "manage:system"]) authorEmail: String @auth(requires: ["write:pages", "manage:system"])
creatorId: Int! @auth(requires: ["write:pages", "manage:system"]) creatorId: Int @auth(requires: ["write:pages", "manage:system"])
creatorName: String! @auth(requires: ["write:pages", "manage:system"]) creatorName: String @auth(requires: ["write:pages", "manage:system"])
creatorEmail: String! @auth(requires: ["write:pages", "manage:system"]) creatorEmail: String @auth(requires: ["write:pages", "manage:system"])
} }
type PageTag { type PageTag {

@ -28,6 +28,7 @@ type ThemingMutation {
theme: String! theme: String!
iconset: String! iconset: String!
darkMode: Boolean! darkMode: Boolean!
tocDepth: RangeInput!
tocPosition: String tocPosition: String
injectCSS: String injectCSS: String
injectHead: String injectHead: String
@ -44,6 +45,7 @@ type ThemingConfig {
iconset: String! iconset: String!
darkMode: Boolean! darkMode: Boolean!
tocPosition: String tocPosition: String
tocDepth: Range
injectCSS: String injectCSS: String
injectHead: String injectHead: String
injectBody: String injectBody: String

@ -82,8 +82,18 @@ module.exports = {
['date', page.updatedAt], ['date', page.updatedAt],
['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''], ['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''],
['editor', page.editorKey], ['editor', page.editorKey],
['dateCreated', page.createdAt] ['dateCreated', page.createdAt],
['doUseTocDefault', page.doUseTocDefault]
] ]
if (page.minTocLevel) {
meta.push(['minTocLevel', page.minTocLevel])
}
if (page.tocLevel) {
meta.push(['tocLevel', page.tocLevel])
}
if (page.tocCollapseLevel) {
meta.push(['tocCollapseLevel', page.tocCollapseLevel])
}
switch (page.contentType) { switch (page.contentType) {
case 'markdown': case 'markdown':
return '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + page.content return '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + page.content

@ -47,7 +47,6 @@ module.exports = class Page extends Model {
publishEndDate: {type: 'string'}, publishEndDate: {type: 'string'},
content: {type: 'string'}, content: {type: 'string'},
contentType: {type: 'string'}, contentType: {type: 'string'},
createdAt: {type: 'string'}, createdAt: {type: 'string'},
updatedAt: {type: 'string'} updatedAt: {type: 'string'}
} }
@ -55,7 +54,7 @@ module.exports = class Page extends Model {
} }
static get jsonAttributes() { static get jsonAttributes() {
return ['extra'] return ['extra', 'tocOptions']
} }
static get relationMappings() { static get relationMappings() {
@ -162,6 +161,11 @@ module.exports = class Page extends Model {
}, },
title: 'string', title: 'string',
toc: 'string', toc: 'string',
tocOptions: {
min: 'uint',
max: 'uint',
useDefault: 'boolean'
},
updatedAt: 'string' updatedAt: 'string'
}) })
} }
@ -312,6 +316,11 @@ module.exports = class Page extends Model {
publishStartDate: opts.publishStartDate || '', publishStartDate: opts.publishStartDate || '',
title: opts.title, title: opts.title,
toc: '[]', toc: '[]',
tocOptions: JSON.stringify({
min: _.get(opts, 'tocDepth.min', 1),
max: _.get(opts, 'tocDepth.max', 2),
useDefault: opts.useDefaultTocDepth !== false
}),
extra: JSON.stringify({ extra: JSON.stringify({
js: scriptJs, js: scriptJs,
css: scriptCss css: scriptCss
@ -431,6 +440,11 @@ module.exports = class Page extends Model {
publishEndDate: opts.publishEndDate || '', publishEndDate: opts.publishEndDate || '',
publishStartDate: opts.publishStartDate || '', publishStartDate: opts.publishStartDate || '',
title: opts.title, title: opts.title,
tocOptions: JSON.stringify({
min: _.get(opts, 'tocDepth.min', ogPage.tocOptions.min || 1),
max: _.get(opts, 'tocDepth.max', ogPage.tocOptions.max || 2),
useDefault: _.get(opts, 'useDefaultTocDepth', ogPage.tocOptions.useDefault !== false)
}),
extra: JSON.stringify({ extra: JSON.stringify({
...ogPage.extra, ...ogPage.extra,
js: scriptJs, js: scriptJs,
@ -992,6 +1006,7 @@ module.exports = class Page extends Model {
'pages.content', 'pages.content',
'pages.render', 'pages.render',
'pages.toc', 'pages.toc',
'pages.tocOptions',
'pages.contentType', 'pages.contentType',
'pages.createdAt', 'pages.createdAt',
'pages.updatedAt', 'pages.updatedAt',
@ -1073,6 +1088,7 @@ module.exports = class Page extends Model {
tags: page.tags.map(t => _.pick(t, ['tag', 'title'])), tags: page.tags.map(t => _.pick(t, ['tag', 'title'])),
title: page.title, title: page.title,
toc: _.isString(page.toc) ? page.toc : JSON.stringify(page.toc), toc: _.isString(page.toc) ? page.toc : JSON.stringify(page.toc),
tocOptions: page.tocOptions,
updatedAt: page.updatedAt updatedAt: page.updatedAt
})) }))
} }

@ -128,6 +128,10 @@ module.exports = () => {
theme: 'default', theme: 'default',
darkMode: false, darkMode: false,
iconset: 'mdi', iconset: 'mdi',
tocDepth: {
min: 1,
max: 2
},
injectCSS: '', injectCSS: '',
injectHead: '', injectHead: '',
injectBody: '' injectBody: ''

@ -19,6 +19,7 @@ block body
script-css=page.extra.css script-css=page.extra.css
script-js=page.extra.js script-js=page.extra.js
init-mode=page.mode init-mode=page.mode
toc-options=Buffer.from(JSON.stringify(page.tocOptions)).toString('base64')
init-editor=page.editorKey init-editor=page.editorKey
init-content=page.content init-content=page.content
checkout-date=page.updatedAt checkout-date=page.updatedAt

@ -25,6 +25,7 @@ block body
toc=Buffer.from(page.toc).toString('base64') toc=Buffer.from(page.toc).toString('base64')
:page-id=page.id :page-id=page.id
sidebar=Buffer.from(JSON.stringify(sidebar)).toString('base64') sidebar=Buffer.from(JSON.stringify(sidebar)).toString('base64')
toc-options=Buffer.from(JSON.stringify(tocOptions)).toString('base64')
nav-mode=config.nav.mode nav-mode=config.nav.mode
comments-enabled=config.features.featurePageComments comments-enabled=config.features.featurePageComments
effective-permissions=Buffer.from(JSON.stringify(effectivePermissions)).toString('base64') effective-permissions=Buffer.from(JSON.stringify(effectivePermissions)).toString('base64')

Loading…
Cancel
Save