page.vue 20 KB

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