page.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template lang="pug">
  2. v-app(v-scroll='upBtnScroll', :dark='$vuetify.theme.dark', :class='$vuetify.rtl ? `is-rtl` : `is-ltr`')
  3. nav-header
  4. v-navigation-drawer(
  5. v-if='navMode !== `NONE`'
  6. :class='$vuetify.theme.dark ? `grey darken-4-d4` : `primary`'
  7. dark
  8. app
  9. clipped
  10. mobile-break-point='600'
  11. :temporary='$vuetify.breakpoint.smAndDown'
  12. v-model='navShown'
  13. :right='$vuetify.rtl'
  14. )
  15. vue-scroll(:ops='scrollStyle')
  16. nav-sidebar(:color='$vuetify.theme.dark ? `grey darken-4-d4` : `primary`', :items='sidebarDecoded', :nav-mode='navMode')
  17. v-fab-transition(v-if='navMode !== `NONE`')
  18. v-btn(
  19. fab
  20. color='primary'
  21. fixed
  22. bottom
  23. :right='$vuetify.rtl'
  24. :left='!$vuetify.rtl'
  25. small
  26. @click='navShown = !navShown'
  27. v-if='$vuetify.breakpoint.mdAndDown'
  28. v-show='!navShown'
  29. )
  30. v-icon mdi-menu
  31. v-content(ref='content')
  32. template(v-if='path !== `home`')
  33. v-toolbar(:color='$vuetify.theme.dark ? `grey darken-4-d3` : `grey lighten-3`', flat, dense, v-if='$vuetify.breakpoint.smAndUp')
  34. //- v-btn.pl-0(v-if='$vuetify.breakpoint.xsOnly', flat, @click='toggleNavigation')
  35. //- v-icon(color='grey darken-2', left) menu
  36. //- span Navigation
  37. v-breadcrumbs.breadcrumbs-nav.pl-0(
  38. :items='breadcrumbs'
  39. divider='/'
  40. )
  41. template(slot='item', slot-scope='props')
  42. v-icon(v-if='props.item.path === "/"', small, @click='goHome') mdi-home
  43. v-btn.ma-0(v-else, :href='props.item.path', small, text) {{props.item.name}}
  44. template(v-if='!isPublished')
  45. v-spacer
  46. .caption.red--text {{$t('common:page.unpublished')}}
  47. status-indicator.ml-3(negative, pulse)
  48. v-divider
  49. v-container.grey.pa-0(fluid, :class='$vuetify.theme.dark ? `darken-4-l3` : `lighten-4`')
  50. v-row(no-gutters, align-content='center', style='height: 90px;')
  51. 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`')
  52. .headline.grey--text(:class='$vuetify.theme.dark ? `text--lighten-2` : `text--darken-3`') {{title}}
  53. .caption.grey--text.text--darken-1 {{description}}
  54. v-divider
  55. v-container.pl-5.pt-4(fluid, grid-list-xl)
  56. v-layout(row)
  57. v-flex.page-col-sd(lg3, xl2, v-if='$vuetify.breakpoint.lgAndUp', align-self-start, style='margin-top: -90px; position: sticky; top: 70px;')
  58. v-card.mb-5(v-if='tocDecoded.length')
  59. .overline.pa-5.pb-0(:class='$vuetify.theme.dark ? `blue--text text--lighten-2` : `primary--text`') {{$t('common:page.toc')}}
  60. v-list.pb-3(dense, nav, :class='$vuetify.theme.dark ? `darken-3-d3` : ``')
  61. template(v-for='(tocItem, tocIdx) in tocDecoded')
  62. v-list-item(@click='$vuetify.goTo(tocItem.anchor, scrollOpts)')
  63. v-icon(color='grey', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
  64. v-list-item-title.px-3 {{tocItem.title}}
  65. //- v-divider(v-if='tocIdx < toc.length - 1 || tocItem.children.length')
  66. template(v-for='tocSubItem in tocItem.children')
  67. v-list-item(@click='$vuetify.goTo(tocSubItem.anchor, scrollOpts)')
  68. v-icon.px-3(color='grey lighten-1', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
  69. v-list-item-title.px-3.caption.grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-1`') {{tocSubItem.title}}
  70. //- v-divider(inset, v-if='tocIdx < toc.length - 1')
  71. v-card.mb-5(v-if='tags.length > 0')
  72. .pa-5
  73. .overline.teal--text.pb-2(:class='$vuetify.theme.dark ? `text--lighten-3` : ``') Tags
  74. v-chip.mr-1.mb-1(
  75. label
  76. :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
  77. v-for='(tag, idx) in tags'
  78. :href='`/t/` + tag.tag'
  79. :key='`tag-` + tag.tag'
  80. )
  81. v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', left, small) mdi-tag
  82. span(:class='$vuetify.theme.dark ? `teal--text text--lighten-5` : `teal--text text--darken-2`') {{tag.title}}
  83. v-chip.mr-1(
  84. label
  85. :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
  86. :href='`/t/` + tags.map(t => t.tag).join(`/`)'
  87. )
  88. v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', size='20') mdi-tag-multiple
  89. v-card.mb-5
  90. .pa-5
  91. .overline.indigo--text.d-flex.align-center(:class='$vuetify.theme.dark ? `text--lighten-3` : ``')
  92. span {{$t('common:page.lastEditedBy')}}
  93. //- v-spacer
  94. //- v-tooltip(top, v-if='isAuthenticated')
  95. //- template(v-slot:activator='{ on }')
  96. //- v-btn.btn-animate-edit(icon, :href='"/h/" + locale + "/" + path', v-on='on', x-small)
  97. //- v-icon(color='grey', dense) mdi-history
  98. //- span History
  99. .body-2.grey--text(:class='$vuetify.theme.dark ? `` : `text--darken-3`') {{ authorName }}
  100. .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
  101. //- v-card.mb-5
  102. //- .pa-5
  103. //- .overline.pb-2.yellow--text(:class='$vuetify.theme.dark ? `text--darken-3` : `text--darken-4`') Rating
  104. //- .text-center
  105. //- v-rating(
  106. //- v-model='rating'
  107. //- color='yellow darken-3'
  108. //- background-color='grey lighten-1'
  109. //- half-increments
  110. //- hover
  111. //- )
  112. //- .caption.grey--text 5 votes
  113. v-card(flat)
  114. v-toolbar(:color='$vuetify.theme.dark ? `grey darken-4-d3` : `grey lighten-3`', flat, dense)
  115. v-spacer
  116. v-tooltip(bottom)
  117. template(v-slot:activator='{ on }')
  118. v-btn(icon, tile, v-on='on'): v-icon(color='grey') mdi-bookmark
  119. span {{$t('common:page.bookmark')}}
  120. v-menu(offset-y, bottom, min-width='300')
  121. template(v-slot:activator='{ on: menu }')
  122. v-tooltip(bottom)
  123. template(v-slot:activator='{ on: tooltip }')
  124. v-btn(icon, tile, v-on='{ ...menu, ...tooltip }'): v-icon(color='grey') mdi-share-variant
  125. span {{$t('common:page.share')}}
  126. social-sharing(
  127. :url='pageUrl'
  128. :title='title'
  129. :description='description'
  130. )
  131. v-tooltip(bottom)
  132. template(v-slot:activator='{ on }')
  133. v-btn(icon, tile, v-on='on', @click='print'): v-icon(color='grey') mdi-printer
  134. span {{$t('common:page.printFormat')}}
  135. v-spacer
  136. v-flex.page-col-content(xs12, lg9, xl10)
  137. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='isAuthenticated')
  138. template(v-slot:activator='{ on: onEditActivator }')
  139. v-speed-dial(
  140. v-model='pageEditFab'
  141. direction='top'
  142. open-on-hover
  143. transition='scale-transition'
  144. bottom
  145. :right='!$vuetify.rtl'
  146. :left='$vuetify.rtl'
  147. fixed
  148. dark
  149. )
  150. template(v-slot:activator)
  151. v-btn.btn-animate-edit(
  152. fab
  153. color='primary'
  154. v-model='pageEditFab'
  155. @click='pageEdit'
  156. v-on='onEditActivator'
  157. )
  158. v-icon mdi-pencil
  159. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  160. template(v-slot:activator='{ on }')
  161. v-btn(
  162. fab
  163. small
  164. color='white'
  165. light
  166. v-on='on'
  167. @click='pageHistory'
  168. )
  169. v-icon(size='20') mdi-history
  170. span {{$t('common:header.history')}}
  171. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  172. template(v-slot:activator='{ on }')
  173. v-btn(
  174. fab
  175. small
  176. color='white'
  177. light
  178. v-on='on'
  179. @click='pageSource'
  180. )
  181. v-icon(size='20') mdi-code-tags
  182. span {{$t('common:header.viewSource')}}
  183. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  184. template(v-slot:activator='{ on }')
  185. v-btn(
  186. fab
  187. small
  188. color='white'
  189. light
  190. v-on='on'
  191. @click='pageDuplicate'
  192. )
  193. v-icon(size='20') mdi-content-duplicate
  194. span {{$t('common:header.duplicate')}}
  195. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  196. template(v-slot:activator='{ on }')
  197. v-btn(
  198. fab
  199. small
  200. color='white'
  201. light
  202. v-on='on'
  203. @click='pageMove'
  204. )
  205. v-icon(size='20') mdi-content-save-move-outline
  206. span {{$t('common:header.move')}}
  207. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  208. template(v-slot:activator='{ on }')
  209. v-btn(
  210. fab
  211. dark
  212. small
  213. color='red'
  214. v-on='on'
  215. @click='pageDelete'
  216. )
  217. v-icon(size='20') mdi-trash-can-outline
  218. span {{$t('common:header.delete')}}
  219. span {{$t('common:page.editPage')}}
  220. .contents(ref='container')
  221. slot(name='contents')
  222. nav-footer
  223. notify
  224. search-results
  225. v-fab-transition
  226. v-btn(
  227. v-if='upBtnShown'
  228. fab
  229. fixed
  230. bottom
  231. :right='$vuetify.rtl'
  232. :left='!$vuetify.rtl'
  233. small
  234. :depressed='this.$vuetify.breakpoint.mdAndUp'
  235. @click='$vuetify.goTo(0, scrollOpts)'
  236. color='primary'
  237. dark
  238. :style='upBtnPosition'
  239. )
  240. v-icon mdi-arrow-up
  241. </template>
  242. <script>
  243. import { StatusIndicator } from 'vue-status-indicator'
  244. import Tabset from './tabset.vue'
  245. import NavSidebar from './nav-sidebar.vue'
  246. import Prism from 'prismjs'
  247. import mermaid from 'mermaid'
  248. import { get } from 'vuex-pathify'
  249. import _ from 'lodash'
  250. import ClipboardJS from 'clipboard'
  251. import Vue from 'vue'
  252. Vue.component('tabset', Tabset)
  253. Prism.plugins.autoloader.languages_path = '/js/prism/'
  254. Prism.plugins.NormalizeWhitespace.setDefaults({
  255. 'remove-trailing': true,
  256. 'remove-indent': true,
  257. 'left-trim': true,
  258. 'right-trim': true,
  259. 'remove-initial-line-feed': true,
  260. 'tabs-to-spaces': 2
  261. })
  262. Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
  263. let linkCopy = document.createElement('button')
  264. linkCopy.textContent = 'Copy'
  265. const clip = new ClipboardJS(linkCopy, {
  266. text: () => { return env.code }
  267. })
  268. clip.on('success', () => {
  269. linkCopy.textContent = 'Copied!'
  270. resetClipboardText()
  271. })
  272. clip.on('error', () => {
  273. linkCopy.textContent = 'Press Ctrl+C to copy'
  274. resetClipboardText()
  275. })
  276. return linkCopy
  277. function resetClipboardText() {
  278. setTimeout(() => {
  279. linkCopy.textContent = 'Copy'
  280. }, 5000)
  281. }
  282. })
  283. export default {
  284. components: {
  285. NavSidebar,
  286. StatusIndicator
  287. },
  288. props: {
  289. pageId: {
  290. type: Number,
  291. default: 0
  292. },
  293. locale: {
  294. type: String,
  295. default: 'en'
  296. },
  297. path: {
  298. type: String,
  299. default: 'home'
  300. },
  301. title: {
  302. type: String,
  303. default: 'Untitled Page'
  304. },
  305. description: {
  306. type: String,
  307. default: ''
  308. },
  309. createdAt: {
  310. type: String,
  311. default: ''
  312. },
  313. updatedAt: {
  314. type: String,
  315. default: ''
  316. },
  317. tags: {
  318. type: Array,
  319. default: () => ([])
  320. },
  321. authorName: {
  322. type: String,
  323. default: 'Unknown'
  324. },
  325. authorId: {
  326. type: Number,
  327. default: 0
  328. },
  329. isPublished: {
  330. type: Boolean,
  331. default: false
  332. },
  333. toc: {
  334. type: String,
  335. default: ''
  336. },
  337. sidebar: {
  338. type: String,
  339. default: ''
  340. },
  341. navMode: {
  342. type: String,
  343. default: 'MIXED'
  344. }
  345. },
  346. data() {
  347. return {
  348. navShown: false,
  349. navExpanded: false,
  350. upBtnShown: false,
  351. pageEditFab: false,
  352. scrollOpts: {
  353. duration: 1500,
  354. offset: 0,
  355. easing: 'easeInOutCubic'
  356. },
  357. scrollStyle: {
  358. vuescroll: {},
  359. scrollPanel: {
  360. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  361. scrollingX: false,
  362. speed: 50
  363. },
  364. rail: {
  365. gutterOfEnds: '2px'
  366. },
  367. bar: {
  368. onlyShowBarOnScroll: false,
  369. background: '#42A5F5',
  370. hoverStyle: {
  371. background: '#64B5F6'
  372. }
  373. }
  374. },
  375. winWidth: 0
  376. }
  377. },
  378. computed: {
  379. isAuthenticated: get('user/authenticated'),
  380. rating: {
  381. get () {
  382. return 3.5
  383. },
  384. set (val) {
  385. }
  386. },
  387. breadcrumbs() {
  388. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  389. result.push({
  390. path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
  391. name: value
  392. })
  393. return result
  394. }, []))
  395. },
  396. pageUrl () { return window.location.href },
  397. upBtnPosition () {
  398. if (this.$vuetify.breakpoint.mdAndUp) {
  399. return this.$vuetify.rtl ? `right: 235px;` : `left: 235px;`
  400. } else {
  401. return this.$vuetify.rtl ? `right: 65px;` : `left: 65px;`
  402. }
  403. },
  404. sidebarDecoded () {
  405. return JSON.parse(atob(this.sidebar))
  406. },
  407. tocDecoded () {
  408. return JSON.parse(atob(this.toc))
  409. }
  410. },
  411. created() {
  412. this.$store.set('page/authorId', this.authorId)
  413. this.$store.set('page/authorName', this.authorName)
  414. this.$store.set('page/createdAt', this.createdAt)
  415. this.$store.set('page/description', this.description)
  416. this.$store.set('page/isPublished', this.isPublished)
  417. this.$store.set('page/id', this.pageId)
  418. this.$store.set('page/locale', this.locale)
  419. this.$store.set('page/path', this.path)
  420. this.$store.set('page/tags', this.tags)
  421. this.$store.set('page/title', this.title)
  422. this.$store.set('page/updatedAt', this.updatedAt)
  423. this.$store.set('page/mode', 'view')
  424. },
  425. mounted () {
  426. if (this.$vuetify.theme.dark) {
  427. this.scrollStyle.bar.background = '#424242'
  428. }
  429. // -> Check side navigation visibility
  430. this.handleSideNavVisibility()
  431. window.addEventListener('resize', _.debounce(() => {
  432. this.handleSideNavVisibility()
  433. }, 500))
  434. // -> Highlight Code Blocks
  435. Prism.highlightAllUnder(this.$refs.container)
  436. // -> Render Mermaid diagrams
  437. mermaid.mermaidAPI.initialize({
  438. startOnLoad: true,
  439. theme: this.$vuetify.theme.dark ? `dark` : `default`
  440. })
  441. // -> Handle anchor scrolling
  442. this.$nextTick(() => {
  443. if (window.location.hash && window.location.hash.length > 1) {
  444. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  445. }
  446. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  447. el.onclick = ev => {
  448. ev.preventDefault()
  449. ev.stopPropagation()
  450. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  451. }
  452. })
  453. })
  454. },
  455. methods: {
  456. goHome () {
  457. window.location.assign('/')
  458. },
  459. toggleNavigation () {
  460. this.navOpen = !this.navOpen
  461. },
  462. upBtnScroll () {
  463. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  464. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  465. },
  466. print () {
  467. window.print()
  468. },
  469. pageEdit () {
  470. this.$root.$emit('pageEdit')
  471. },
  472. pageHistory () {
  473. this.$root.$emit('pageHistory')
  474. },
  475. pageSource () {
  476. this.$root.$emit('pageSource')
  477. },
  478. pageDuplicate () {
  479. this.$root.$emit('pageDuplicate')
  480. },
  481. pageMove () {
  482. this.$root.$emit('pageMove')
  483. },
  484. pageDelete () {
  485. this.$root.$emit('pageDelete')
  486. },
  487. handleSideNavVisibility () {
  488. if (window.innerWidth === this.winWidth) { return }
  489. this.winWidth = window.innerWidth
  490. if (this.$vuetify.breakpoint.mdAndUp) {
  491. this.navShown = true
  492. } else {
  493. this.navShown = false
  494. }
  495. }
  496. }
  497. }
  498. </script>
  499. <style lang="scss">
  500. .breadcrumbs-nav {
  501. .v-btn {
  502. min-width: 0;
  503. &__content {
  504. text-transform: none;
  505. }
  506. }
  507. .v-breadcrumbs__divider:nth-child(2n) {
  508. padding: 0 6px;
  509. }
  510. .v-breadcrumbs__divider:nth-child(2) {
  511. padding: 0 6px 0 12px;
  512. }
  513. }
  514. </style>