page.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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')
  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.mb-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 && commentsPerms.read')
  90. .pa-5
  91. .overline.pb-2.blue-grey--text.d-flex.align-center(:class='$vuetify.theme.dark ? `text--lighten-3` : `text--darken-2`')
  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 ? `blue-grey darken-3` : `blue-grey darken-2`'
  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 ? `blue-grey` : `blue-grey darken-2`'
  107. outlined
  108. style='flex: 1 1 100%;'
  109. small
  110. )
  111. span.blue-grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-2`') View Discussion
  112. v-tooltip(right, v-if='commentsPerms.write')
  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 ? `blue-grey` : `blue-grey darken-2`'
  120. )
  121. v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-1` : `blue-grey darken-2`', 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(v-if='commentsEnabled && commentsPerms.read')
  257. .comments-header
  258. v-icon.mr-2(dark) mdi-comment-text-outline
  259. span Comments
  260. .comments-main
  261. slot(name='comments')
  262. nav-footer
  263. notify
  264. search-results
  265. v-fab-transition
  266. v-btn(
  267. v-if='upBtnShown'
  268. fab
  269. fixed
  270. bottom
  271. :right='$vuetify.rtl'
  272. :left='!$vuetify.rtl'
  273. small
  274. :depressed='this.$vuetify.breakpoint.mdAndUp'
  275. @click='$vuetify.goTo(0, scrollOpts)'
  276. color='primary'
  277. dark
  278. :style='upBtnPosition'
  279. )
  280. v-icon mdi-arrow-up
  281. </template>
  282. <script>
  283. import { StatusIndicator } from 'vue-status-indicator'
  284. import Tabset from './tabset.vue'
  285. import NavSidebar from './nav-sidebar.vue'
  286. import Prism from 'prismjs'
  287. import mermaid from 'mermaid'
  288. import { get } from 'vuex-pathify'
  289. import _ from 'lodash'
  290. import ClipboardJS from 'clipboard'
  291. import Vue from 'vue'
  292. Vue.component('tabset', Tabset)
  293. Prism.plugins.autoloader.languages_path = '/_assets/js/prism/'
  294. Prism.plugins.NormalizeWhitespace.setDefaults({
  295. 'remove-trailing': true,
  296. 'remove-indent': true,
  297. 'left-trim': true,
  298. 'right-trim': true,
  299. 'remove-initial-line-feed': true,
  300. 'tabs-to-spaces': 2
  301. })
  302. Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
  303. let linkCopy = document.createElement('button')
  304. linkCopy.textContent = 'Copy'
  305. const clip = new ClipboardJS(linkCopy, {
  306. text: () => { return env.code }
  307. })
  308. clip.on('success', () => {
  309. linkCopy.textContent = 'Copied!'
  310. resetClipboardText()
  311. })
  312. clip.on('error', () => {
  313. linkCopy.textContent = 'Press Ctrl+C to copy'
  314. resetClipboardText()
  315. })
  316. return linkCopy
  317. function resetClipboardText() {
  318. setTimeout(() => {
  319. linkCopy.textContent = 'Copy'
  320. }, 5000)
  321. }
  322. })
  323. export default {
  324. components: {
  325. NavSidebar,
  326. StatusIndicator
  327. },
  328. props: {
  329. pageId: {
  330. type: Number,
  331. default: 0
  332. },
  333. locale: {
  334. type: String,
  335. default: 'en'
  336. },
  337. path: {
  338. type: String,
  339. default: 'home'
  340. },
  341. title: {
  342. type: String,
  343. default: 'Untitled Page'
  344. },
  345. description: {
  346. type: String,
  347. default: ''
  348. },
  349. createdAt: {
  350. type: String,
  351. default: ''
  352. },
  353. updatedAt: {
  354. type: String,
  355. default: ''
  356. },
  357. tags: {
  358. type: Array,
  359. default: () => ([])
  360. },
  361. authorName: {
  362. type: String,
  363. default: 'Unknown'
  364. },
  365. authorId: {
  366. type: Number,
  367. default: 0
  368. },
  369. isPublished: {
  370. type: Boolean,
  371. default: false
  372. },
  373. toc: {
  374. type: String,
  375. default: ''
  376. },
  377. sidebar: {
  378. type: String,
  379. default: ''
  380. },
  381. navMode: {
  382. type: String,
  383. default: 'MIXED'
  384. },
  385. commentsEnabled: {
  386. type: Boolean,
  387. default: false
  388. },
  389. commentsPermissions: {
  390. type: String,
  391. default: ''
  392. },
  393. commentsExternal: {
  394. type: Boolean,
  395. default: false
  396. }
  397. },
  398. data() {
  399. return {
  400. navShown: false,
  401. navExpanded: false,
  402. upBtnShown: false,
  403. pageEditFab: false,
  404. scrollOpts: {
  405. duration: 1500,
  406. offset: 0,
  407. easing: 'easeInOutCubic'
  408. },
  409. scrollStyle: {
  410. vuescroll: {},
  411. scrollPanel: {
  412. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  413. scrollingX: false,
  414. speed: 50
  415. },
  416. rail: {
  417. gutterOfEnds: '2px'
  418. },
  419. bar: {
  420. onlyShowBarOnScroll: false,
  421. background: '#42A5F5',
  422. hoverStyle: {
  423. background: '#64B5F6'
  424. }
  425. }
  426. },
  427. winWidth: 0
  428. }
  429. },
  430. computed: {
  431. isAuthenticated: get('user/authenticated'),
  432. commentsCount: get('page/commentsCount'),
  433. commentsPerms: get('page/commentsPermissions'),
  434. rating: {
  435. get () {
  436. return 3.5
  437. },
  438. set (val) {
  439. }
  440. },
  441. breadcrumbs() {
  442. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  443. result.push({
  444. path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
  445. name: value
  446. })
  447. return result
  448. }, []))
  449. },
  450. pageUrl () { return window.location.href },
  451. upBtnPosition () {
  452. if (this.$vuetify.breakpoint.mdAndUp) {
  453. return this.$vuetify.rtl ? `right: 235px;` : `left: 235px;`
  454. } else {
  455. return this.$vuetify.rtl ? `right: 65px;` : `left: 65px;`
  456. }
  457. },
  458. sidebarDecoded () {
  459. return JSON.parse(Buffer.from(this.sidebar, 'base64').toString())
  460. },
  461. tocDecoded () {
  462. return JSON.parse(Buffer.from(this.toc, 'base64').toString())
  463. }
  464. },
  465. created() {
  466. this.$store.set('page/authorId', this.authorId)
  467. this.$store.set('page/authorName', this.authorName)
  468. this.$store.set('page/createdAt', this.createdAt)
  469. this.$store.set('page/description', this.description)
  470. this.$store.set('page/isPublished', this.isPublished)
  471. this.$store.set('page/id', this.pageId)
  472. this.$store.set('page/locale', this.locale)
  473. this.$store.set('page/path', this.path)
  474. this.$store.set('page/tags', this.tags)
  475. this.$store.set('page/title', this.title)
  476. this.$store.set('page/updatedAt', this.updatedAt)
  477. if (this.commentsPermissions) {
  478. this.$store.set('page/commentsPermissions', JSON.parse(atob(this.commentsPermissions)))
  479. }
  480. this.$store.set('page/mode', 'view')
  481. },
  482. mounted () {
  483. if (this.$vuetify.theme.dark) {
  484. this.scrollStyle.bar.background = '#424242'
  485. }
  486. // -> Check side navigation visibility
  487. this.handleSideNavVisibility()
  488. window.addEventListener('resize', _.debounce(() => {
  489. this.handleSideNavVisibility()
  490. }, 500))
  491. // -> Highlight Code Blocks
  492. Prism.highlightAllUnder(this.$refs.container)
  493. // -> Render Mermaid diagrams
  494. mermaid.mermaidAPI.initialize({
  495. startOnLoad: true,
  496. theme: this.$vuetify.theme.dark ? `dark` : `default`
  497. })
  498. // -> Handle anchor scrolling
  499. if (window.location.hash && window.location.hash.length > 1) {
  500. if (document.readyState === 'complete') {
  501. this.$nextTick(() => {
  502. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  503. })
  504. } else {
  505. window.addEventListener('load', () => {
  506. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  507. })
  508. }
  509. }
  510. // -> Handle anchor links within the page contents
  511. this.$nextTick(() => {
  512. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  513. el.onclick = ev => {
  514. ev.preventDefault()
  515. ev.stopPropagation()
  516. this.$vuetify.goTo(decodeURIComponent(ev.target.hash), this.scrollOpts)
  517. }
  518. })
  519. })
  520. },
  521. methods: {
  522. goHome () {
  523. window.location.assign('/')
  524. },
  525. toggleNavigation () {
  526. this.navOpen = !this.navOpen
  527. },
  528. upBtnScroll () {
  529. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  530. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  531. },
  532. print () {
  533. window.print()
  534. },
  535. pageEdit () {
  536. this.$root.$emit('pageEdit')
  537. },
  538. pageHistory () {
  539. this.$root.$emit('pageHistory')
  540. },
  541. pageSource () {
  542. this.$root.$emit('pageSource')
  543. },
  544. pageDuplicate () {
  545. this.$root.$emit('pageDuplicate')
  546. },
  547. pageMove () {
  548. this.$root.$emit('pageMove')
  549. },
  550. pageDelete () {
  551. this.$root.$emit('pageDelete')
  552. },
  553. handleSideNavVisibility () {
  554. if (window.innerWidth === this.winWidth) { return }
  555. this.winWidth = window.innerWidth
  556. if (this.$vuetify.breakpoint.mdAndUp) {
  557. this.navShown = true
  558. } else {
  559. this.navShown = false
  560. }
  561. },
  562. goToComments (focusNewComment = false) {
  563. this.$vuetify.goTo('#discussion', this.scrollOpts)
  564. if (focusNewComment) {
  565. document.querySelector('#discussion-new').focus()
  566. }
  567. }
  568. }
  569. }
  570. </script>
  571. <style lang="scss">
  572. .breadcrumbs-nav {
  573. .v-btn {
  574. min-width: 0;
  575. &__content {
  576. text-transform: none;
  577. }
  578. }
  579. .v-breadcrumbs__divider:nth-child(2n) {
  580. padding: 0 6px;
  581. }
  582. .v-breadcrumbs__divider:nth-child(2) {
  583. padding: 0 6px 0 12px;
  584. }
  585. }
  586. .page-col-sd {
  587. margin-top: -90px;
  588. align-self: flex-start;
  589. position: sticky;
  590. top: 64px;
  591. max-height: calc(100vh - 64px);
  592. overflow-y: auto;
  593. -ms-overflow-style: none;
  594. }
  595. .page-col-sd::-webkit-scrollbar {
  596. display: none;
  597. }
  598. </style>