page.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template lang="pug">
  2. v-app(v-scroll='upBtnScroll', :dark='darkMode', :class='$vuetify.rtl ? `is-rtl` : `is-ltr`')
  3. nav-header
  4. v-navigation-drawer(
  5. :class='darkMode ? `grey darken-4-d4` : `primary`'
  6. dark
  7. app
  8. clipped
  9. mobile-break-point='600'
  10. :temporary='$vuetify.breakpoint.smAndDown'
  11. v-model='navShown'
  12. :right='$vuetify.rtl'
  13. )
  14. vue-scroll(:ops='scrollStyle')
  15. nav-sidebar(:color='darkMode ? `grey darken-4-d4` : `primary`', :items='sidebar')
  16. v-fab-transition
  17. v-btn(
  18. fab
  19. color='primary'
  20. fixed
  21. bottom
  22. :right='$vuetify.rtl'
  23. :left='!$vuetify.rtl'
  24. small
  25. @click='navShown = !navShown'
  26. v-if='$vuetify.breakpoint.mdAndDown'
  27. v-show='!navShown'
  28. )
  29. v-icon mdi-menu
  30. v-content(ref='content')
  31. template(v-if='path !== `home`')
  32. v-toolbar(:color='darkMode ? `grey darken-4-d3` : `grey lighten-3`', flat, dense, v-if='$vuetify.breakpoint.smAndUp')
  33. //- v-btn.pl-0(v-if='$vuetify.breakpoint.xsOnly', flat, @click='toggleNavigation')
  34. //- v-icon(color='grey darken-2', left) menu
  35. //- span Navigation
  36. v-breadcrumbs.breadcrumbs-nav.pl-0(
  37. :items='breadcrumbs'
  38. divider='/'
  39. )
  40. template(slot='item', slot-scope='props')
  41. v-icon(v-if='props.item.path === "/"', small, @click='goHome') mdi-home
  42. v-btn.ma-0(v-else, :href='props.item.path', small, text) {{props.item.name}}
  43. template(v-if='!isPublished')
  44. v-spacer
  45. .caption.red--text {{$t('common:page.unpublished')}}
  46. status-indicator.ml-3(negative, pulse)
  47. v-divider
  48. v-container.grey.pa-0(fluid, :class='darkMode ? `darken-4-l3` : `lighten-4`')
  49. v-row(no-gutters, align-content='center', style='height: 90px;')
  50. 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`')
  51. .headline.grey--text(:class='darkMode ? `text--lighten-2` : `text--darken-3`') {{title}}
  52. .caption.grey--text.text--darken-1 {{description}}
  53. v-divider
  54. v-container.pl-5.pt-4(fluid, grid-list-xl)
  55. v-layout(row)
  56. v-flex.page-col-sd(lg3, xl2, v-if='$vuetify.breakpoint.lgAndUp', style='margin-top: -90px;')
  57. v-card.mb-5(v-if='toc.length')
  58. .overline.pa-5.pb-0(:class='darkMode ? `blue--text text--lighten-2` : `primary--text`') {{$t('common:page.toc')}}
  59. v-list.pb-3(dense, nav, :class='darkMode ? `darken-3-d3` : ``')
  60. template(v-for='(tocItem, tocIdx) in toc')
  61. v-list-item(@click='$vuetify.goTo(tocItem.anchor, scrollOpts)')
  62. v-icon(color='grey', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
  63. v-list-item-title.px-3 {{tocItem.title}}
  64. //- v-divider(v-if='tocIdx < toc.length - 1 || tocItem.children.length')
  65. template(v-for='tocSubItem in tocItem.children')
  66. v-list-item(@click='$vuetify.goTo(tocSubItem.anchor, scrollOpts)')
  67. v-icon.px-3(color='grey lighten-1', small) {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
  68. v-list-item-title.px-3.caption.grey--text(:class='darkMode ? `text--lighten-1` : `text--darken-1`') {{tocSubItem.title}}
  69. //- v-divider(inset, v-if='tocIdx < toc.length - 1')
  70. v-card.mb-5(v-if='tags.length > 0')
  71. .pa-5
  72. .overline.teal--text.pb-2(:class='$vuetify.theme.dark ? `text--lighten-3` : ``') Tags
  73. v-chip.mr-1.mb-1(
  74. label
  75. :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
  76. v-for='(tag, idx) in tags'
  77. :href='`/t/` + tag.tag'
  78. :key='`tag-` + tag.tag'
  79. )
  80. v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', left, small) mdi-tag
  81. span(:class='$vuetify.theme.dark ? `teal--text text--lighten-5` : `teal--text text--darken-2`') {{tag.title}}
  82. v-chip.mr-1(
  83. label
  84. :color='$vuetify.theme.dark ? `teal darken-1` : `teal lighten-5`'
  85. :href='`/t/` + tags.map(t => t.tag).join(`/`)'
  86. )
  87. v-icon(:color='$vuetify.theme.dark ? `teal lighten-3` : `teal`', size='20') mdi-tag-multiple
  88. v-card.mb-5
  89. .pa-5
  90. .overline.indigo--text.d-flex.align-center(:class='$vuetify.theme.dark ? `text--lighten-3` : ``')
  91. span {{$t('common:page.lastEditedBy')}}
  92. //- v-spacer
  93. //- v-tooltip(top, v-if='isAuthenticated')
  94. //- template(v-slot:activator='{ on }')
  95. //- v-btn.btn-animate-edit(icon, :href='"/h/" + locale + "/" + path', v-on='on', x-small)
  96. //- v-icon(color='grey', dense) mdi-history
  97. //- span History
  98. .body-2.grey--text(:class='darkMode ? `` : `text--darken-3`') {{ authorName }}
  99. .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
  100. //- v-card.mb-5
  101. //- .pa-5
  102. //- .overline.pb-2.yellow--text(:class='$vuetify.theme.dark ? `text--darken-3` : `text--darken-4`') Rating
  103. //- .text-center
  104. //- v-rating(
  105. //- v-model='rating'
  106. //- color='yellow darken-3'
  107. //- background-color='grey lighten-1'
  108. //- half-increments
  109. //- hover
  110. //- )
  111. //- .caption.grey--text 5 votes
  112. v-card(flat)
  113. v-toolbar(:color='darkMode ? `grey darken-4-d3` : `grey lighten-3`', flat, dense)
  114. v-spacer
  115. v-tooltip(bottom)
  116. template(v-slot:activator='{ on }')
  117. v-btn(icon, tile, v-on='on'): v-icon(color='grey') mdi-bookmark
  118. span {{$t('common:page.bookmark')}}
  119. v-menu(offset-y, bottom, min-width='300')
  120. template(v-slot:activator='{ on: menu }')
  121. v-tooltip(bottom)
  122. template(v-slot:activator='{ on: tooltip }')
  123. v-btn(icon, tile, v-on='{ ...menu, ...tooltip }'): v-icon(color='grey') mdi-share-variant
  124. span {{$t('common:page.share')}}
  125. social-sharing(
  126. :url='pageUrl'
  127. :title='title'
  128. :description='description'
  129. )
  130. v-tooltip(bottom)
  131. template(v-slot:activator='{ on }')
  132. v-btn(icon, tile, v-on='on', @click='print'): v-icon(color='grey') mdi-printer
  133. span {{$t('common:page.printFormat')}}
  134. v-spacer
  135. v-flex.page-col-content(xs12, lg9, xl10)
  136. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='isAuthenticated')
  137. template(v-slot:activator='{ on: onEditActivator }')
  138. v-speed-dial(
  139. v-model='pageEditFab'
  140. direction='top'
  141. open-on-hover
  142. transition='scale-transition'
  143. bottom
  144. :right='!$vuetify.rtl'
  145. :left='$vuetify.rtl'
  146. fixed
  147. dark
  148. )
  149. template(v-slot:activator)
  150. v-btn.btn-animate-edit(
  151. fab
  152. color='primary'
  153. v-model='pageEditFab'
  154. @click='pageEdit'
  155. v-on='onEditActivator'
  156. )
  157. v-icon mdi-pencil
  158. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  159. template(v-slot:activator='{ on }')
  160. v-btn(
  161. fab
  162. small
  163. color='white'
  164. light
  165. v-on='on'
  166. @click='pageHistory'
  167. )
  168. v-icon(size='20') mdi-history
  169. span {{$t('common:header.history')}}
  170. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  171. template(v-slot:activator='{ on }')
  172. v-btn(
  173. fab
  174. small
  175. color='white'
  176. light
  177. v-on='on'
  178. @click='pageSource'
  179. )
  180. v-icon(size='20') mdi-code-tags
  181. span {{$t('common:header.viewSource')}}
  182. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  183. template(v-slot:activator='{ on }')
  184. v-btn(
  185. fab
  186. small
  187. color='white'
  188. light
  189. v-on='on'
  190. @click='pageDuplicate'
  191. )
  192. v-icon(size='20') mdi-content-duplicate
  193. span {{$t('common:header.duplicate')}}
  194. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  195. template(v-slot:activator='{ on }')
  196. v-btn(
  197. fab
  198. small
  199. color='white'
  200. light
  201. v-on='on'
  202. @click='pageMove'
  203. )
  204. v-icon(size='20') mdi-content-save-move-outline
  205. span {{$t('common:header.move')}}
  206. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  207. template(v-slot:activator='{ on }')
  208. v-btn(
  209. fab
  210. dark
  211. small
  212. color='red'
  213. v-on='on'
  214. @click='pageDelete'
  215. )
  216. v-icon(size='20') mdi-trash-can-outline
  217. span {{$t('common:header.delete')}}
  218. span {{$t('common:page.editPage')}}
  219. .contents(ref='container')
  220. slot(name='contents')
  221. nav-footer
  222. notify
  223. search-results
  224. v-fab-transition
  225. v-btn(
  226. v-if='upBtnShown'
  227. fab
  228. fixed
  229. bottom
  230. :right='$vuetify.rtl'
  231. :left='!$vuetify.rtl'
  232. small
  233. :depressed='this.$vuetify.breakpoint.mdAndUp'
  234. @click='$vuetify.goTo(0, scrollOpts)'
  235. color='primary'
  236. dark
  237. :style='upBtnPosition'
  238. )
  239. v-icon mdi-arrow-up
  240. </template>
  241. <script>
  242. import { StatusIndicator } from 'vue-status-indicator'
  243. import Prism from 'prismjs'
  244. import mermaid from 'mermaid'
  245. import { get } from 'vuex-pathify'
  246. import _ from 'lodash'
  247. import ClipboardJS from 'clipboard'
  248. Prism.plugins.autoloader.languages_path = '/js/prism/'
  249. Prism.plugins.NormalizeWhitespace.setDefaults({
  250. 'remove-trailing': true,
  251. 'remove-indent': true,
  252. 'left-trim': true,
  253. 'right-trim': true,
  254. 'remove-initial-line-feed': true,
  255. 'tabs-to-spaces': 2
  256. })
  257. Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
  258. let linkCopy = document.createElement('button')
  259. linkCopy.textContent = 'Copy'
  260. const clip = new ClipboardJS(linkCopy, {
  261. text: () => { return env.code }
  262. })
  263. clip.on('success', () => {
  264. linkCopy.textContent = 'Copied!'
  265. resetClipboardText()
  266. })
  267. clip.on('error', () => {
  268. linkCopy.textContent = 'Press Ctrl+C to copy'
  269. resetClipboardText()
  270. })
  271. return linkCopy
  272. function resetClipboardText() {
  273. setTimeout(() => {
  274. linkCopy.textContent = 'Copy'
  275. }, 5000)
  276. }
  277. })
  278. export default {
  279. components: {
  280. StatusIndicator
  281. },
  282. props: {
  283. pageId: {
  284. type: Number,
  285. default: 0
  286. },
  287. locale: {
  288. type: String,
  289. default: 'en'
  290. },
  291. path: {
  292. type: String,
  293. default: 'home'
  294. },
  295. title: {
  296. type: String,
  297. default: 'Untitled Page'
  298. },
  299. description: {
  300. type: String,
  301. default: ''
  302. },
  303. createdAt: {
  304. type: String,
  305. default: ''
  306. },
  307. updatedAt: {
  308. type: String,
  309. default: ''
  310. },
  311. tags: {
  312. type: Array,
  313. default: () => ([])
  314. },
  315. authorName: {
  316. type: String,
  317. default: 'Unknown'
  318. },
  319. authorId: {
  320. type: Number,
  321. default: 0
  322. },
  323. isPublished: {
  324. type: Boolean,
  325. default: false
  326. },
  327. toc: {
  328. type: Array,
  329. default: () => []
  330. },
  331. sidebar: {
  332. type: Array,
  333. default: () => []
  334. }
  335. },
  336. data() {
  337. return {
  338. navShown: false,
  339. navExpanded: false,
  340. upBtnShown: false,
  341. pageEditFab: false,
  342. scrollOpts: {
  343. duration: 1500,
  344. offset: 0,
  345. easing: 'easeInOutCubic'
  346. },
  347. scrollStyle: {
  348. vuescroll: {},
  349. scrollPanel: {
  350. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  351. scrollingX: false,
  352. speed: 50
  353. },
  354. rail: {
  355. gutterOfEnds: '2px'
  356. },
  357. bar: {
  358. onlyShowBarOnScroll: false,
  359. background: '#42A5F5',
  360. hoverStyle: {
  361. background: '#64B5F6'
  362. }
  363. }
  364. },
  365. winWidth: 0
  366. }
  367. },
  368. computed: {
  369. darkMode: get('site/dark'),
  370. isAuthenticated: get('user/authenticated'),
  371. rating: {
  372. get () {
  373. return 3.5
  374. },
  375. set (val) {
  376. }
  377. },
  378. breadcrumbs() {
  379. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  380. result.push({
  381. path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
  382. name: value
  383. })
  384. return result
  385. }, []))
  386. },
  387. pageUrl () { return window.location.href },
  388. upBtnPosition () {
  389. if (this.$vuetify.breakpoint.mdAndUp) {
  390. return this.$vuetify.rtl ? `right: 235px;` : `left: 235px;`
  391. } else {
  392. return this.$vuetify.rtl ? `right: 65px;` : `left: 65px;`
  393. }
  394. }
  395. },
  396. created() {
  397. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  398. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  399. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  400. this.$store.commit('page/SET_DESCRIPTION', this.description)
  401. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  402. this.$store.commit('page/SET_ID', this.pageId)
  403. this.$store.commit('page/SET_LOCALE', this.locale)
  404. this.$store.commit('page/SET_PATH', this.path)
  405. this.$store.commit('page/SET_TAGS', this.tags)
  406. this.$store.commit('page/SET_TITLE', this.title)
  407. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  408. this.$store.commit('page/SET_MODE', 'view')
  409. },
  410. mounted () {
  411. // -> Check side navigation visibility
  412. this.handleSideNavVisibility()
  413. window.addEventListener('resize', _.debounce(() => {
  414. this.handleSideNavVisibility()
  415. }, 500))
  416. // -> Highlight Code Blocks
  417. Prism.highlightAllUnder(this.$refs.container)
  418. // -> Render Mermaid diagrams
  419. mermaid.mermaidAPI.initialize({
  420. startOnLoad: true,
  421. theme: this.$vuetify.theme.dark ? `dark` : `default`
  422. })
  423. // -> Handle anchor scrolling
  424. this.$nextTick(() => {
  425. if (window.location.hash && window.location.hash.length > 1) {
  426. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  427. }
  428. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  429. el.onclick = ev => {
  430. ev.preventDefault()
  431. ev.stopPropagation()
  432. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  433. }
  434. })
  435. })
  436. },
  437. methods: {
  438. goHome () {
  439. window.location.assign('/')
  440. },
  441. toggleNavigation () {
  442. this.navOpen = !this.navOpen
  443. },
  444. upBtnScroll () {
  445. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  446. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  447. },
  448. print () {
  449. window.print()
  450. },
  451. pageEdit () {
  452. this.$root.$emit('pageEdit')
  453. },
  454. pageHistory () {
  455. this.$root.$emit('pageHistory')
  456. },
  457. pageSource () {
  458. this.$root.$emit('pageSource')
  459. },
  460. pageDuplicate () {
  461. this.$root.$emit('pageDuplicate')
  462. },
  463. pageMove () {
  464. this.$root.$emit('pageMove')
  465. },
  466. pageDelete () {
  467. this.$root.$emit('pageDelete')
  468. },
  469. handleSideNavVisibility () {
  470. if (window.innerWidth === this.winWidth) { return }
  471. this.winWidth = window.innerWidth
  472. if (this.$vuetify.breakpoint.mdAndUp) {
  473. this.navShown = true
  474. } else {
  475. this.navShown = false
  476. }
  477. }
  478. }
  479. }
  480. </script>
  481. <style lang="scss">
  482. .breadcrumbs-nav {
  483. .v-btn {
  484. min-width: 0;
  485. &__content {
  486. text-transform: none;
  487. }
  488. }
  489. .v-breadcrumbs__divider:nth-child(2n) {
  490. padding: 0 6px;
  491. }
  492. .v-breadcrumbs__divider:nth-child(2) {
  493. padding: 0 6px 0 12px;
  494. }
  495. }
  496. </style>