page.vue 19 KB

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