forked from requarks/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configurable ToC Heading Levels (requarks#5101)
Co-authored-by: Regev Brody <[email protected]>
- Loading branch information
Showing
22 changed files
with
355 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template lang='pug'> | ||
v-dialog( | ||
v-dialog( | ||
v-model='isShown' | ||
persistent | ||
width='1000' | ||
|
@@ -67,6 +67,23 @@ | |
:rules='[rules.required, rules.path]' | ||
) | ||
v-divider | ||
v-card-text.grey.pt-5(:class='$vuetify.theme.dark ? `darken-3-d3` : `lighten-5`') | ||
.overline.pb-5 Theme Options | ||
v-switch( | ||
label='Use Site Defaults' | ||
v-model='doUseTocDefault' | ||
) | ||
v-range-slider( | ||
:disabled='doUseTocDefault' | ||
prepend-icon='mdi-serial-port' | ||
label='Heading Levels in ToC' | ||
hint='The table of contents will show headings from and up to the selected levels.' | ||
v-model='tocRange' | ||
:min='1' | ||
:max='6' | ||
:tick-labels='["H1", "H2", "H3", "H4", "H5", "H6"]' | ||
) | ||
v-divider | ||
v-card-text.grey.pt-5(:class='$vuetify.theme.dark ? `darken-3-d5` : `lighten-4`') | ||
.overline.pb-5 {{$t('editor:props.categorization')}} | ||
v-chip-group.radius-5.mb-5(column, v-if='tags && tags.length > 0') | ||
|
@@ -255,6 +272,7 @@ import 'codemirror/mode/htmlmixed/htmlmixed.js' | |
import 'codemirror/mode/css/css.js' | ||
/* global siteLangs, siteConfig */ | ||
// eslint-disable-next-line no-useless-escape | ||
const filenamePattern = /^(?![\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s])(?!.*[\#\/\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]$)[^\#\.\$\^\=\*\;\:\&\?\(\)\[\]\{\}\"\'\>\<\,\@\!\%\`\~\s]*$/ | ||
export default { | ||
|
@@ -276,10 +294,10 @@ export default { | |
currentTab: 0, | ||
cm: null, | ||
rules: { | ||
required: value => !!value || 'This field is required.', | ||
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.' | ||
} | ||
required: value => !!value || 'This field is required.', | ||
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.' | ||
} | ||
} | ||
} | ||
}, | ||
|
@@ -297,6 +315,19 @@ export default { | |
isPublished: sync('page/isPublished'), | ||
publishStartDate: sync('page/publishStartDate'), | ||
publishEndDate: sync('page/publishEndDate'), | ||
tocRange: { | ||
get() { | ||
var range = [this.$store.get('page/minTocLevel'), this.$store.get('page/tocLevel')] | ||
return range | ||
// return [get('page/minTocLevel'), get('page/tocLevel')] | ||
}, | ||
set(value) { | ||
this.$store.set('page/minTocLevel', value[0]) | ||
this.$store.set('page/tocLevel', value[1]) | ||
this.$store.set('page/tocCollapseLevel', value[1]) | ||
} | ||
}, | ||
doUseTocDefault: sync('page/doUseTocDefault'), | ||
scriptJs: sync('page/scriptJs'), | ||
scriptCss: sync('page/scriptCss'), | ||
hasScriptPermission: get('page/[email protected]'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ query { | |
theme | ||
iconset | ||
darkMode | ||
minTocLevel | ||
tocLevel | ||
tocCollapseLevel | ||
injectCSS | ||
injectHead | ||
injectBody | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template lang="pug"> | ||
div | ||
template(v-if='level >= minTocLevel') | ||
v-list-item(@click='click(item.anchor)', v-if='(item.children.length === 0 && tocCollapseLevel > level) || tocCollapseLevel > level', | ||
:key='item.anchor', :class='isNestedLevel ? `pl-9` : `pl-6`') | ||
v-icon.pl-0(small, color='grey lighten-1') {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }} | ||
v-list-item-title.pl-4(v-bind:class='titleClasses') {{item.title}} | ||
v-list-group(sub-group, v-else, v-bind:class='{"pl-3": 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}} | ||
template(v-if='item.children.length !== 0', v-for='subItem in item.children') | ||
page-toc-item(:item='subItem', :level='level + 1', :tocLevel='tocLevel', :minTocLevel='minTocLevel', :tocCollapseLevel='tocCollapseLevel') | ||
template(v-if='tocCollapseLevel > level', v-for='subItem in item.children') | ||
page-toc-item(:item='subItem', :level='level + 1', :tocLevel='tocLevel', :minTocLevel='minTocLevel', :tocCollapseLevel='tocCollapseLevel') | ||
template(v-else, v-for='subItem in item.children') | ||
page-toc-item(:item='subItem', :level='level + 1', :tocLevel='tocLevel', :minTocLevel='minTocLevel', :tocCollapseLevel='tocCollapseLevel') | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'PageTocItem', | ||
props: { | ||
item: { | ||
type: Object, | ||
default: () => {} | ||
}, | ||
minTocLevel: { | ||
type: Number, | ||
default: 0 | ||
}, | ||
tocLevel: { | ||
type: Number, | ||
default: 2 | ||
}, | ||
tocCollapseLevel: { | ||
type: Number, | ||
default: 2 | ||
}, | ||
level: { | ||
type: Number, | ||
default: 1 | ||
} | ||
}, | ||
data() { | ||
return { | ||
scrollOpts: { | ||
duration: 1500, | ||
offset: 0, | ||
easing: 'easeInOutCubic' | ||
} | ||
} | ||
}, | ||
computed: { | ||
isNestedLevel() { | ||
return this.level > this.minTocLevel | ||
}, | ||
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 | ||
.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> |
Oops, something went wrong.