page.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template lang="pug">
  2. v-app(v-scroll='upBtnScroll', :dark='darkMode')
  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.mdAndDown'
  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.pl-4.page-col-content(offset-xl='2', offset-lg='3', style='margin-top: auto; margin-bottom: auto;')
  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-tooltip(bottom)
  120. template(v-slot:activator='{ on }')
  121. v-btn(icon, tile, v-on='on'): v-icon(color='grey') mdi-share-variant
  122. span {{$t('common:page.share')}}
  123. v-tooltip(bottom)
  124. template(v-slot:activator='{ on }')
  125. v-btn(icon, tile, v-on='on', @click='print'): v-icon(color='grey') mdi-printer
  126. span {{$t('common:page.printFormat')}}
  127. v-spacer
  128. v-flex.page-col-content(xs12, lg9, xl10)
  129. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='isAuthenticated')
  130. template(v-slot:activator='{ on: onEditActivator }')
  131. v-speed-dial(
  132. v-model='pageEditFab'
  133. direction='top'
  134. open-on-hover
  135. transition='scale-transition'
  136. bottom
  137. :right='!$vuetify.rtl'
  138. :left='$vuetify.rtl'
  139. fixed
  140. dark
  141. )
  142. template(v-slot:activator)
  143. v-btn.btn-animate-edit(
  144. fab
  145. color='primary'
  146. v-model='pageEditFab'
  147. @click='pageEdit'
  148. v-on='onEditActivator'
  149. )
  150. v-icon mdi-pencil
  151. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  152. template(v-slot:activator='{ on }')
  153. v-btn(
  154. fab
  155. small
  156. color='white'
  157. light
  158. v-on='on'
  159. @click='pageHistory'
  160. )
  161. v-icon(size='20') mdi-history
  162. span History
  163. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  164. template(v-slot:activator='{ on }')
  165. v-btn(
  166. fab
  167. small
  168. color='white'
  169. light
  170. v-on='on'
  171. @click='pageSource'
  172. )
  173. v-icon(size='20') mdi-code-tags
  174. span View Source
  175. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  176. template(v-slot:activator='{ on }')
  177. v-btn(
  178. fab
  179. small
  180. color='white'
  181. light
  182. v-on='on'
  183. @click='pageMove'
  184. )
  185. v-icon(size='20') mdi-content-save-move-outline
  186. span Move / Rename
  187. v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl')
  188. template(v-slot:activator='{ on }')
  189. v-btn(
  190. fab
  191. dark
  192. small
  193. color='red'
  194. v-on='on'
  195. @click='pageDelete'
  196. )
  197. v-icon(size='20') mdi-trash-can-outline
  198. span Delete
  199. span {{$t('common:page.editPage')}}
  200. .contents(ref='container')
  201. slot(name='contents')
  202. nav-footer
  203. notify
  204. search-results
  205. v-fab-transition
  206. v-btn(
  207. v-if='upBtnShown'
  208. fab
  209. fixed
  210. bottom
  211. :right='$vuetify.rtl'
  212. :left='!$vuetify.rtl'
  213. small
  214. depressed
  215. @click='$vuetify.goTo(0, scrollOpts)'
  216. color='primary'
  217. dark
  218. :style='$vuetify.rtl ? `right: 235px;` : `left: 235px;`'
  219. )
  220. v-icon mdi-arrow-up
  221. </template>
  222. <script>
  223. import { StatusIndicator } from 'vue-status-indicator'
  224. import Prism from 'prismjs'
  225. import { get } from 'vuex-pathify'
  226. import _ from 'lodash'
  227. import ClipboardJS from 'clipboard'
  228. Prism.plugins.autoloader.languages_path = '/js/prism/'
  229. Prism.plugins.NormalizeWhitespace.setDefaults({
  230. 'remove-trailing': true,
  231. 'remove-indent': true,
  232. 'left-trim': true,
  233. 'right-trim': true,
  234. 'remove-initial-line-feed': true,
  235. 'tabs-to-spaces': 2
  236. })
  237. Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
  238. let linkCopy = document.createElement('button')
  239. linkCopy.textContent = 'Copy'
  240. const clip = new ClipboardJS(linkCopy, {
  241. text: () => { return env.code }
  242. })
  243. clip.on('success', () => {
  244. linkCopy.textContent = 'Copied!'
  245. resetClipboardText()
  246. })
  247. clip.on('error', () => {
  248. linkCopy.textContent = 'Press Ctrl+C to copy'
  249. resetClipboardText()
  250. })
  251. return linkCopy
  252. function resetClipboardText() {
  253. setTimeout(() => {
  254. linkCopy.textContent = 'Copy'
  255. }, 5000)
  256. }
  257. })
  258. export default {
  259. components: {
  260. StatusIndicator
  261. },
  262. props: {
  263. pageId: {
  264. type: Number,
  265. default: 0
  266. },
  267. locale: {
  268. type: String,
  269. default: 'en'
  270. },
  271. path: {
  272. type: String,
  273. default: 'home'
  274. },
  275. title: {
  276. type: String,
  277. default: 'Untitled Page'
  278. },
  279. description: {
  280. type: String,
  281. default: ''
  282. },
  283. createdAt: {
  284. type: String,
  285. default: ''
  286. },
  287. updatedAt: {
  288. type: String,
  289. default: ''
  290. },
  291. tags: {
  292. type: Array,
  293. default: () => ([])
  294. },
  295. authorName: {
  296. type: String,
  297. default: 'Unknown'
  298. },
  299. authorId: {
  300. type: Number,
  301. default: 0
  302. },
  303. isPublished: {
  304. type: Boolean,
  305. default: false
  306. },
  307. toc: {
  308. type: Array,
  309. default: () => []
  310. },
  311. sidebar: {
  312. type: Array,
  313. default: () => []
  314. }
  315. },
  316. data() {
  317. return {
  318. navShown: false,
  319. navExpanded: false,
  320. upBtnShown: false,
  321. pageEditFab: false,
  322. scrollOpts: {
  323. duration: 1500,
  324. offset: 0,
  325. easing: 'easeInOutCubic'
  326. },
  327. scrollStyle: {
  328. vuescroll: {},
  329. scrollPanel: {
  330. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  331. scrollingX: false,
  332. speed: 50
  333. },
  334. rail: {
  335. gutterOfEnds: '2px'
  336. },
  337. bar: {
  338. onlyShowBarOnScroll: false,
  339. background: '#42A5F5',
  340. hoverStyle: {
  341. background: '#64B5F6'
  342. }
  343. }
  344. }
  345. }
  346. },
  347. computed: {
  348. darkMode: get('site/dark'),
  349. isAuthenticated: get('user/authenticated'),
  350. rating: {
  351. get () {
  352. return 3.5
  353. },
  354. set (val) {
  355. }
  356. },
  357. breadcrumbs() {
  358. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  359. result.push({
  360. path: _.get(_.last(result), 'path', `/${this.locale}`) + `/${value}`,
  361. name: value
  362. })
  363. return result
  364. }, []))
  365. }
  366. },
  367. created() {
  368. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  369. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  370. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  371. this.$store.commit('page/SET_DESCRIPTION', this.description)
  372. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  373. this.$store.commit('page/SET_ID', this.pageId)
  374. this.$store.commit('page/SET_LOCALE', this.locale)
  375. this.$store.commit('page/SET_PATH', this.path)
  376. this.$store.commit('page/SET_TAGS', this.tags)
  377. this.$store.commit('page/SET_TITLE', this.title)
  378. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  379. this.$store.commit('page/SET_MODE', 'view')
  380. },
  381. mounted () {
  382. Prism.highlightAllUnder(this.$refs.container)
  383. this.navShown = this.$vuetify.breakpoint.smAndUp
  384. this.$nextTick(() => {
  385. if (window.location.hash && window.location.hash.length > 1) {
  386. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  387. }
  388. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  389. el.onclick = ev => {
  390. ev.preventDefault()
  391. ev.stopPropagation()
  392. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  393. }
  394. })
  395. })
  396. },
  397. methods: {
  398. goHome () {
  399. window.location.assign('/')
  400. },
  401. toggleNavigation () {
  402. this.navOpen = !this.navOpen
  403. },
  404. upBtnScroll () {
  405. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  406. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  407. },
  408. print () {
  409. window.print()
  410. },
  411. pageEdit () {
  412. this.$root.$emit('pageEdit')
  413. },
  414. pageHistory () {
  415. this.$root.$emit('pageHistory')
  416. },
  417. pageSource () {
  418. this.$root.$emit('pageSource')
  419. },
  420. pageMove () {
  421. this.$root.$emit('pageMove')
  422. },
  423. pageDelete () {
  424. this.$root.$emit('pageDelete')
  425. }
  426. }
  427. }
  428. </script>
  429. <style lang="scss">
  430. .breadcrumbs-nav {
  431. .v-btn {
  432. min-width: 0;
  433. &__content {
  434. text-transform: none;
  435. }
  436. }
  437. .v-breadcrumbs__divider:nth-child(2n) {
  438. padding: 0 6px;
  439. }
  440. .v-breadcrumbs__divider:nth-child(2) {
  441. padding: 0 6px 0 12px;
  442. }
  443. }
  444. </style>