page.vue 17 KB

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