page.vue 19 KB

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