123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685 |
- <template lang="pug">
- v-app(v-scroll='upBtnScroll', :dark='$vuetify.theme.dark', :class='$vuetify.rtl ? `is-rtl` : `is-ltr`')
- nav-header(v-if='!printView')
- v-navigation-drawer(
- v-if='navMode !== `NONE` && !printView'
- :class='$vuetify.theme.dark ? `grey darken-4-d4` : `primary`'
- dark
- app
- clipped
- mobile-breakpoint='600'
- :temporary='$vuetify.breakpoint.smAndDown'
- v-model='navShown'
- :right='$vuetify.rtl'
- )
- vue-scroll(:ops='scrollStyle')
- nav-sidebar(:color='$vuetify.theme.dark ? `grey darken-4-d4` : `primary`', :items='sidebarDecoded', :nav-mode='navMode')
- v-fab-transition(v-if='navMode !== `NONE`')
- v-btn(
- fab
- color='primary'
- fixed
- bottom
- :right='$vuetify.rtl'
- :left='!$vuetify.rtl'
- small
- @click='navShown = !navShown'
- v-if='$vuetify.breakpoint.mdAndDown'
- v-show='!navShown'
- )
- v-icon mdi-menu
- v-main(ref='content')
- template(v-if='path !== `home`')
- v-toolbar(:color='$vuetify.theme.dark ? `grey darken-4-d3` : `grey lighten-3`', flat, dense, v-if='$vuetify.breakpoint.smAndUp')
- //- v-btn.pl-0(v-if='$vuetify.breakpoint.xsOnly', flat, @click='toggleNavigation')
- //- v-icon(color='grey darken-2', left) menu
- //- span Navigation
- v-breadcrumbs.breadcrumbs-nav.pl-0(
- :items='breadcrumbs'
- divider='/'
- )
- template(slot='item', slot-scope='props')
- v-icon(v-if='props.item.path === "/"', small, @click='goHome') mdi-home
- v-btn.ma-0(v-else, :href='props.item.path', small, text) {{props.item.name}}
- template(v-if='!isPublished')
- v-spacer
- .caption.red--text {{$t('common:page.unpublished')}}
- status-indicator.ml-3(negative, pulse)
- v-divider
- v-container.grey.pa-0(fluid, :class='$vuetify.theme.dark ? `darken-4-l3` : `lighten-4`')
- v-row(no-gutters, align-content='center', style='height: 90px;')
- v-col.page-col-content.is-page-header(offset-xl='2', offset-lg='3', style='margin-top: auto; margin-bottom: auto;', :class='$vuetify.rtl ? `pr-4` : `pl-4`')
- .headline.grey--text(:class='$vuetify.theme.dark ? `text--lighten-2` : `text--darken-3`') {{title}}
- .caption.grey--text.text--darken-1 {{description}}
- v-divider
- v-container.pl-5.pt-4(fluid, grid-list-xl)
- v-layout(row)
- v-flex.page-col-sd(lg3, xl2, v-if='$vuetify.breakpoint.lgAndUp')
- v-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')}}
- v-list.py-2(dense, nav, :class='$vuetify.theme.dark ? `darken-3-d3` : ``')
- page-toc-item(
- v-for='(item, idx) in tocDecoded'
- :key='`tocitem-` + idx'
- :item='item'
- :min='tocOptionsDecoded.min'
- :max='tocOptionsDecoded.max'
- )
- v-card.mb-5(v-if='tags.length > 0')
- .pa-5
- .overline.teal--text.pb-2(:class='$vuetify.theme.dark ? `text--lighten-3` : ``') {{$t('common:page.tags')}}
- v-chip.mr-1.mb-1(
- label
- :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
- v-for='(tag, idx) in tags'
- :href='`/t/` + tag.tag'
- :key='`tag-` + tag.tag'
- )
- v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', left, small) mdi-tag
- span(:class='$vuetify.theme.dark ? `teal--text text--lighten-5` : `teal--text text--darken-2`') {{tag.title}}
- v-chip.mr-1.mb-1(
- label
- :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
- :href='`/t/` + tags.map(t => t.tag).join(`/`)'
- :aria-label='$t(`common:page.tagsMatching`)'
- )
- v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', size='20') mdi-tag-multiple
- v-card.mb-5(v-if='commentsEnabled && commentsPerms.read')
- .pa-5
- .overline.pb-2.blue-grey--text.d-flex.align-center(:class='$vuetify.theme.dark ? `text--lighten-3` : `text--darken-2`')
- span {{$t('common:comments.sdTitle')}}
- //- v-spacer
- //- v-chip.text-center(
- //- v-if='!commentsExternal'
- //- label
- //- x-small
- //- :color='$vuetify.theme.dark ? `blue-grey darken-3` : `blue-grey darken-2`'
- //- dark
- //- style='min-width: 50px; justify-content: center;'
- //- )
- //- span {{commentsCount}}
- .d-flex
- v-btn.text-none(
- @click='goToComments()'
- :color='$vuetify.theme.dark ? `blue-grey` : `blue-grey darken-2`'
- outlined
- style='flex: 1 1 100%;'
- small
- )
- span.blue-grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-2`') {{$t('common:comments.viewDiscussion')}}
- v-tooltip(right, v-if='commentsPerms.write')
- template(v-slot:activator='{ on }')
- v-btn.ml-2(
- @click='goToComments(true)'
- v-on='on'
- outlined
- small
- :color='$vuetify.theme.dark ? `blue-grey` : `blue-grey darken-2`'
- :aria-label='$t(`common:comments.newComment`)'
- )
- v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-1` : `blue-grey darken-2`', dense) mdi-comment-plus
- span {{$t('common:comments.newComment')}}
- v-card.mb-5
- .pa-5
- .overline.indigo--text.d-flex(:class='$vuetify.theme.dark ? `text--lighten-3` : ``')
- span {{$t('common:page.lastEditedBy')}}
- v-spacer
- v-tooltip(right, v-if='isAuthenticated')
- template(v-slot:activator='{ on }')
- v-btn.btn-animate-edit(
- icon
- :href='"/h/" + locale + "/" + path'
- v-on='on'
- x-small
- v-if='hasReadHistoryPermission'
- :aria-label='$t(`common:header.history`)'
- )
- v-icon(color='indigo', dense) mdi-history
- span {{$t('common:header.history')}}
- .body-2.grey--text(:class='$vuetify.theme.dark ? `` : `text--darken-3`') {{ authorName }}
- .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
- //- v-card.mb-5
- //- .pa-5
- //- .overline.pb-2.yellow--text(:class='$vuetify.theme.dark ? `text--darken-3` : `text--darken-4`') Rating
- //- .text-center
- //- v-rating(
- //- v-model='rating'
- //- color='yellow darken-3'
- //- background-color='grey lighten-1'
- //- half-increments
- //- hover
- //- )
- //- .caption.grey--text 5 votes
- v-card(flat)
- v-toolbar(:color='$vuetify.theme.dark ? `grey darken-4-d3` : `grey lighten-3`', flat, dense)
- v-spacer
- v-tooltip(bottom)
- template(v-slot:activator='{ on }')
- v-btn(icon, tile, v-on='on', :aria-label='$t(`common:page.bookmark`)'): v-icon(color='grey') mdi-bookmark
- span {{$t('common:page.bookmark')}}
- v-menu(offset-y, bottom, min-width='300')
- template(v-slot:activator='{ on: menu }')
- v-tooltip(bottom)
- template(v-slot:activator='{ on: tooltip }')
- v-btn(icon, tile, v-on='{ ...menu, ...tooltip }', :aria-label='$t(`common:page.share`)'): v-icon(color='grey') mdi-share-variant
- span {{$t('common:page.share')}}
- social-sharing(
- :url='pageUrl'
- :title='title'
- :description='description'
- )
- v-tooltip(bottom)
- template(v-slot:activator='{ on }')
- v-btn(icon, tile, v-on='on', @click='print', :aria-label='$t(`common:page.printFormat`)')
- v-icon(:color='printView ? `primary` : `grey`') mdi-printer
- span {{$t('common:page.printFormat')}}
- v-spacer
- v-flex.page-col-content(xs12, lg9, xl10)
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasAnyPagePermissions')
- template(v-slot:activator='{ on: onEditActivator }')
- v-speed-dial(
- v-model='pageEditFab'
- direction='top'
- open-on-hover
- transition='scale-transition'
- bottom
- :right='!$vuetify.rtl'
- :left='$vuetify.rtl'
- fixed
- dark
- )
- template(v-slot:activator)
- v-btn.btn-animate-edit(
- fab
- color='primary'
- v-model='pageEditFab'
- @click='pageEdit'
- v-on='onEditActivator'
- :disabled='!hasWritePagesPermission'
- :aria-label='$t(`common:page.editPage`)'
- )
- v-icon mdi-pencil
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasReadHistoryPermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- small
- color='white'
- light
- v-on='on'
- @click='pageHistory'
- )
- v-icon(size='20') mdi-history
- span {{$t('common:header.history')}}
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasReadSourcePermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- small
- color='white'
- light
- v-on='on'
- @click='pageSource'
- )
- v-icon(size='20') mdi-code-tags
- span {{$t('common:header.viewSource')}}
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasWritePagesPermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- small
- color='white'
- light
- v-on='on'
- @click='pageConvert'
- )
- v-icon(size='20') mdi-lightning-bolt
- span {{$t('common:header.convert')}}
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasWritePagesPermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- small
- color='white'
- light
- v-on='on'
- @click='pageDuplicate'
- )
- v-icon(size='20') mdi-content-duplicate
- span {{$t('common:header.duplicate')}}
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasManagePagesPermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- small
- color='white'
- light
- v-on='on'
- @click='pageMove'
- )
- v-icon(size='20') mdi-content-save-move-outline
- span {{$t('common:header.move')}}
- v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasDeletePagesPermission')
- template(v-slot:activator='{ on }')
- v-btn(
- fab
- dark
- small
- color='red'
- v-on='on'
- @click='pageDelete'
- )
- v-icon(size='20') mdi-trash-can-outline
- span {{$t('common:header.delete')}}
- span {{$t('common:page.editPage')}}
- v-alert.mb-5(v-if='!isPublished', color='red', outlined, icon='mdi-minus-circle', dense)
- .caption {{$t('common:page.unpublishedWarning')}}
- .contents(ref='container')
- slot(name='contents')
- .comments-container#discussion(v-if='commentsEnabled && commentsPerms.read && !printView')
- .comments-header
- v-icon.mr-2(dark) mdi-comment-text-outline
- span {{$t('common:comments.title')}}
- .comments-main
- slot(name='comments')
- nav-footer
- notify
- search-results
- v-fab-transition
- v-btn(
- v-if='upBtnShown'
- fab
- fixed
- bottom
- :right='$vuetify.rtl'
- :left='!$vuetify.rtl'
- small
- :depressed='this.$vuetify.breakpoint.mdAndUp'
- @click='$vuetify.goTo(0, scrollOpts)'
- color='primary'
- dark
- :style='upBtnPosition'
- :aria-label='$t(`common:actions.returnToTop`)'
- )
- v-icon mdi-arrow-up
- </template>
- <script>
- import { StatusIndicator } from 'vue-status-indicator'
- import Tabset from './tabset.vue'
- import NavSidebar from './nav-sidebar.vue'
- import PageTocItem from './page-toc-item.vue'
- import Prism from 'prismjs'
- import mermaid from 'mermaid'
- import { get, sync } from 'vuex-pathify'
- import _ from 'lodash'
- import ClipboardJS from 'clipboard'
- import Vue from 'vue'
- Vue.component('Tabset', Tabset)
- Prism.plugins.autoloader.languages_path = '/_assets/js/prism/'
- Prism.plugins.NormalizeWhitespace.setDefaults({
- 'remove-trailing': true,
- 'remove-indent': true,
- 'left-trim': true,
- 'right-trim': true,
- 'remove-initial-line-feed': true,
- 'tabs-to-spaces': 2
- })
- Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
- let linkCopy = document.createElement('button')
- linkCopy.textContent = 'Copy'
- const clip = new ClipboardJS(linkCopy, {
- text: () => { return env.code }
- })
- clip.on('success', () => {
- linkCopy.textContent = 'Copied!'
- resetClipboardText()
- })
- clip.on('error', () => {
- linkCopy.textContent = 'Press Ctrl+C to copy'
- resetClipboardText()
- })
- return linkCopy
- function resetClipboardText() {
- setTimeout(() => {
- linkCopy.textContent = 'Copy'
- }, 5000)
- }
- })
- export default {
- components: {
- NavSidebar,
- PageTocItem,
- StatusIndicator
- },
- props: {
- pageId: {
- type: Number,
- default: 0
- },
- locale: {
- type: String,
- default: 'en'
- },
- path: {
- type: String,
- default: 'home'
- },
- title: {
- type: String,
- default: 'Untitled Page'
- },
- description: {
- type: String,
- default: ''
- },
- createdAt: {
- type: String,
- default: ''
- },
- updatedAt: {
- type: String,
- default: ''
- },
- tags: {
- type: Array,
- default: () => ([])
- },
- authorName: {
- type: String,
- default: 'Unknown'
- },
- authorId: {
- type: Number,
- default: 0
- },
- editor: {
- type: String,
- default: ''
- },
- isPublished: {
- type: Boolean,
- default: false
- },
- toc: {
- type: String,
- default: ''
- },
- sidebar: {
- type: String,
- default: ''
- },
- navMode: {
- type: String,
- default: 'MIXED'
- },
- commentsEnabled: {
- type: Boolean,
- default: false
- },
- effectivePermissions: {
- type: String,
- default: ''
- },
- commentsExternal: {
- type: Boolean,
- default: false
- },
- tocOptions: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- navShown: false,
- navExpanded: false,
- upBtnShown: false,
- pageEditFab: false,
- scrollOpts: {
- duration: 1500,
- offset: 0,
- easing: 'easeInOutCubic'
- },
- scrollStyle: {
- vuescroll: {},
- scrollPanel: {
- initialScrollX: 0.01, // fix scrollbar not disappearing on load
- scrollingX: false,
- speed: 50
- },
- rail: {
- gutterOfEnds: '2px'
- },
- bar: {
- onlyShowBarOnScroll: false,
- background: '#42A5F5',
- hoverStyle: {
- background: '#64B5F6'
- }
- }
- },
- winWidth: 0
- }
- },
- computed: {
- isAuthenticated: get('user/authenticated'),
- commentsCount: get('page/commentsCount'),
- commentsPerms: get('page/effectivePermissions@comments'),
- rating: {
- get () {
- return 3.5
- },
- set (val) {
- }
- },
- breadcrumbs() {
- return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
- result.push({
- path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
- name: value
- })
- return result
- }, []))
- },
- pageUrl () { return window.location.href },
- upBtnPosition () {
- if (this.$vuetify.breakpoint.mdAndUp) {
- return this.$vuetify.rtl ? `right: 235px;` : `left: 235px;`
- } else {
- return this.$vuetify.rtl ? `right: 65px;` : `left: 65px;`
- }
- },
- sidebarDecoded () {
- return JSON.parse(Buffer.from(this.sidebar, 'base64').toString())
- },
- tocDecoded () {
- return JSON.parse(Buffer.from(this.toc, 'base64').toString())
- },
- tocOptionsDecoded () {
- return JSON.parse(Buffer.from(this.tocOptions, 'base64').toString())
- },
- hasAdminPermission: get('page/effectivePermissions@system.manage'),
- hasWritePagesPermission: get('page/effectivePermissions@pages.write'),
- hasManagePagesPermission: get('page/effectivePermissions@pages.manage'),
- hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'),
- hasReadSourcePermission: get('page/effectivePermissions@source.read'),
- hasReadHistoryPermission: get('page/effectivePermissions@history.read'),
- hasAnyPagePermissions () {
- return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission ||
- this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission
- },
- printView: sync('site/printView')
- },
- created() {
- this.$store.set('page/authorId', this.authorId)
- this.$store.set('page/authorName', this.authorName)
- this.$store.set('page/createdAt', this.createdAt)
- this.$store.set('page/description', this.description)
- this.$store.set('page/isPublished', this.isPublished)
- this.$store.set('page/id', this.pageId)
- this.$store.set('page/locale', this.locale)
- this.$store.set('page/path', this.path)
- this.$store.set('page/tags', this.tags)
- this.$store.set('page/title', this.title)
- this.$store.set('page/editor', this.editor)
- this.$store.set('page/updatedAt', this.updatedAt)
- if (this.effectivePermissions) {
- this.$store.set('page/effectivePermissions', JSON.parse(Buffer.from(this.effectivePermissions, 'base64').toString()))
- }
- this.$store.set('page/mode', 'view')
- },
- mounted () {
- if (this.$vuetify.theme.dark) {
- this.scrollStyle.bar.background = '#424242'
- }
- // -> Check side navigation visibility
- this.handleSideNavVisibility()
- window.addEventListener('resize', _.debounce(() => {
- this.handleSideNavVisibility()
- }, 500))
- // -> Highlight Code Blocks
- Prism.highlightAllUnder(this.$refs.container)
- // -> Render Mermaid diagrams
- mermaid.mermaidAPI.initialize({
- startOnLoad: true,
- theme: this.$vuetify.theme.dark ? `dark` : `default`
- })
- // -> Handle anchor scrolling
- if (window.location.hash && window.location.hash.length > 1) {
- if (document.readyState === 'complete') {
- this.$nextTick(() => {
- this.$vuetify.goTo(decodeURIComponent(window.location.hash), this.scrollOpts)
- })
- } else {
- window.addEventListener('load', () => {
- this.$vuetify.goTo(decodeURIComponent(window.location.hash), this.scrollOpts)
- })
- }
- }
- // -> Handle anchor links within the page contents
- this.$nextTick(() => {
- this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
- el.onclick = ev => {
- ev.preventDefault()
- ev.stopPropagation()
- this.$vuetify.goTo(decodeURIComponent(ev.currentTarget.hash), this.scrollOpts)
- }
- })
- })
- },
- methods: {
- goHome () {
- window.location.assign('/')
- },
- toggleNavigation () {
- this.navOpen = !this.navOpen
- },
- upBtnScroll () {
- const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
- this.upBtnShown = scrollOffset > window.innerHeight * 0.33
- },
- print () {
- if (this.printView) {
- this.printView = false
- } else {
- this.printView = true
- this.$nextTick(() => {
- window.print()
- })
- }
- },
- pageEdit () {
- this.$root.$emit('pageEdit')
- },
- pageHistory () {
- this.$root.$emit('pageHistory')
- },
- pageSource () {
- this.$root.$emit('pageSource')
- },
- pageConvert () {
- this.$root.$emit('pageConvert')
- },
- pageDuplicate () {
- this.$root.$emit('pageDuplicate')
- },
- pageMove () {
- this.$root.$emit('pageMove')
- },
- pageDelete () {
- this.$root.$emit('pageDelete')
- },
- handleSideNavVisibility () {
- if (window.innerWidth === this.winWidth) { return }
- this.winWidth = window.innerWidth
- if (this.$vuetify.breakpoint.mdAndUp) {
- this.navShown = true
- } else {
- this.navShown = false
- }
- },
- goToComments (focusNewComment = false) {
- this.$vuetify.goTo('#discussion', this.scrollOpts)
- if (focusNewComment) {
- document.querySelector('#discussion-new').focus()
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .breadcrumbs-nav {
- .v-btn {
- min-width: 0;
- &__content {
- text-transform: none;
- }
- }
- .v-breadcrumbs__divider:nth-child(2n) {
- padding: 0 6px;
- }
- .v-breadcrumbs__divider:nth-child(2) {
- padding: 0 6px 0 12px;
- }
- }
- .page-col-sd {
- margin-top: -90px;
- align-self: flex-start;
- position: sticky;
- top: 64px;
- max-height: calc(100vh - 64px);
- overflow-y: auto;
- -ms-overflow-style: none;
- }
- .page-col-sd::-webkit-scrollbar {
- display: none;
- }
- </style>
|