page.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 334
  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. rating: {
  429. get () {
  430. return 3.5
  431. },
  432. set (val) {
  433. }
  434. },
  435. breadcrumbs() {
  436. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  437. result.push({
  438. path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
  439. name: value
  440. })
  441. return result
  442. }, []))
  443. },
  444. pageUrl () { return window.location.href },
  445. upBtnPosition () {
  446. if (this.$vuetify.breakpoint.mdAndUp) {
  447. return this.$vuetify.rtl ? `right: 235px;` : `left: 235px;`
  448. } else {
  449. return this.$vuetify.rtl ? `right: 65px;` : `left: 65px;`
  450. }
  451. },
  452. sidebarDecoded () {
  453. return JSON.parse(atob(this.sidebar))
  454. },
  455. tocDecoded () {
  456. return JSON.parse(atob(this.toc))
  457. }
  458. },
  459. created() {
  460. this.$store.set('page/authorId', this.authorId)
  461. this.$store.set('page/authorName', this.authorName)
  462. this.$store.set('page/createdAt', this.createdAt)
  463. this.$store.set('page/description', this.description)
  464. this.$store.set('page/isPublished', this.isPublished)
  465. this.$store.set('page/id', this.pageId)
  466. this.$store.set('page/locale', this.locale)
  467. this.$store.set('page/path', this.path)
  468. this.$store.set('page/tags', this.tags)
  469. this.$store.set('page/title', this.title)
  470. this.$store.set('page/updatedAt', this.updatedAt)
  471. if (this.commentsPermissions) {
  472. this.$store.set('page/comments', JSON.parse(atob(this.commentsPermissions)))
  473. }
  474. this.$store.set('page/mode', 'view')
  475. },
  476. mounted () {
  477. if (this.$vuetify.theme.dark) {
  478. this.scrollStyle.bar.background = '#424242'
  479. }
  480. // -> Check side navigation visibility
  481. this.handleSideNavVisibility()
  482. window.addEventListener('resize', _.debounce(() => {
  483. this.handleSideNavVisibility()
  484. }, 500))
  485. // -> Highlight Code Blocks
  486. Prism.highlightAllUnder(this.$refs.container)
  487. // -> Render Mermaid diagrams
  488. mermaid.mermaidAPI.initialize({
  489. startOnLoad: true,
  490. theme: this.$vuetify.theme.dark ? `dark` : `default`
  491. })
  492. // -> Handle anchor scrolling
  493. if (window.location.hash && window.location.hash.length > 1) {
  494. if (document.readyState === 'complete') {
  495. this.$nextTick(() => {
  496. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  497. })
  498. } else {
  499. window.addEventListener('load', () => {
  500. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  501. })
  502. }
  503. }
  504. this.$nextTick(() => {
  505. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  506. el.onclick = ev => {
  507. ev.preventDefault()
  508. ev.stopPropagation()
  509. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  510. }
  511. })
  512. })
  513. },
  514. methods: {
  515. goHome () {
  516. window.location.assign('/')
  517. },
  518. toggleNavigation () {
  519. this.navOpen = !this.navOpen
  520. },
  521. upBtnScroll () {
  522. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  523. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  524. },
  525. print () {
  526. window.print()
  527. },
  528. pageEdit () {
  529. this.$root.$emit('pageEdit')
  530. },
  531. pageHistory () {
  532. this.$root.$emit('pageHistory')
  533. },
  534. pageSource () {
  535. this.$root.$emit('pageSource')
  536. },
  537. pageDuplicate () {
  538. this.$root.$emit('pageDuplicate')
  539. },
  540. pageMove () {
  541. this.$root.$emit('pageMove')
  542. },
  543. pageDelete () {
  544. this.$root.$emit('pageDelete')
  545. },
  546. handleSideNavVisibility () {
  547. if (window.innerWidth === this.winWidth) { return }
  548. this.winWidth = window.innerWidth
  549. if (this.$vuetify.breakpoint.mdAndUp) {
  550. this.navShown = true
  551. } else {
  552. this.navShown = false
  553. }
  554. },
  555. goToComments (focusNewComment = false) {
  556. this.$vuetify.goTo('#discussion', this.scrollOpts)
  557. if (focusNewComment) {
  558. document.querySelector('#discussion-new').focus()
  559. }
  560. }
  561. }
  562. }
  563. </script>
  564. <style lang="scss">
  565. .breadcrumbs-nav {
  566. .v-btn {
  567. min-width: 0;
  568. &__content {
  569. text-transform: none;
  570. }
  571. }
  572. .v-breadcrumbs__divider:nth-child(2n) {
  573. padding: 0 6px;
  574. }
  575. .v-breadcrumbs__divider:nth-child(2) {
  576. padding: 0 6px 0 12px;
  577. }
  578. }
  579. </style>