You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

440 lines
14 KiB

  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')
  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(
  74. label
  75. color='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='teal', left, small) mdi-tag
  81. span.teal--text.text--darken-2 {{tag.title}}
  82. v-chip.mr-1(
  83. label
  84. color='teal lighten-5'
  85. :href='`/t/` + tags.map(t => t.tag).join(`/`)'
  86. )
  87. v-icon(color='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. Prism.plugins.autoloader.languages_path = '/js/prism/'
  228. Prism.plugins.NormalizeWhitespace.setDefaults({
  229. 'remove-trailing': true,
  230. 'remove-indent': true,
  231. 'left-trim': true,
  232. 'right-trim': true,
  233. 'break-lines': 160,
  234. 'remove-initial-line-feed': true,
  235. 'tabs-to-spaces': 2
  236. })
  237. export default {
  238. components: {
  239. StatusIndicator
  240. },
  241. props: {
  242. pageId: {
  243. type: Number,
  244. default: 0
  245. },
  246. locale: {
  247. type: String,
  248. default: 'en'
  249. },
  250. path: {
  251. type: String,
  252. default: 'home'
  253. },
  254. title: {
  255. type: String,
  256. default: 'Untitled Page'
  257. },
  258. description: {
  259. type: String,
  260. default: ''
  261. },
  262. createdAt: {
  263. type: String,
  264. default: ''
  265. },
  266. updatedAt: {
  267. type: String,
  268. default: ''
  269. },
  270. tags: {
  271. type: Array,
  272. default: () => ([])
  273. },
  274. authorName: {
  275. type: String,
  276. default: 'Unknown'
  277. },
  278. authorId: {
  279. type: Number,
  280. default: 0
  281. },
  282. isPublished: {
  283. type: Boolean,
  284. default: false
  285. },
  286. toc: {
  287. type: Array,
  288. default: () => []
  289. },
  290. sidebar: {
  291. type: Array,
  292. default: () => []
  293. }
  294. },
  295. data() {
  296. return {
  297. navShown: false,
  298. navExpanded: false,
  299. upBtnShown: false,
  300. pageEditFab: false,
  301. scrollOpts: {
  302. duration: 1500,
  303. offset: 0,
  304. easing: 'easeInOutCubic'
  305. },
  306. scrollStyle: {
  307. vuescroll: {},
  308. scrollPanel: {
  309. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  310. scrollingX: false,
  311. speed: 50
  312. },
  313. rail: {
  314. gutterOfEnds: '2px'
  315. },
  316. bar: {
  317. onlyShowBarOnScroll: false,
  318. background: '#42A5F5',
  319. hoverStyle: {
  320. background: '#64B5F6'
  321. }
  322. }
  323. }
  324. }
  325. },
  326. computed: {
  327. darkMode: get('site/dark'),
  328. isAuthenticated: get('user/authenticated'),
  329. rating: {
  330. get () {
  331. return 3.5
  332. },
  333. set (val) {
  334. }
  335. },
  336. breadcrumbs() {
  337. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  338. result.push({
  339. path: _.map(result, 'path').join('/') + `/${value}`,
  340. name: value
  341. })
  342. return result
  343. }, []))
  344. }
  345. },
  346. created() {
  347. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  348. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  349. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  350. this.$store.commit('page/SET_DESCRIPTION', this.description)
  351. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  352. this.$store.commit('page/SET_ID', this.pageId)
  353. this.$store.commit('page/SET_LOCALE', this.locale)
  354. this.$store.commit('page/SET_PATH', this.path)
  355. this.$store.commit('page/SET_TAGS', this.tags)
  356. this.$store.commit('page/SET_TITLE', this.title)
  357. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  358. this.$store.commit('page/SET_MODE', 'view')
  359. },
  360. mounted () {
  361. Prism.highlightAllUnder(this.$refs.container)
  362. this.navShown = this.$vuetify.breakpoint.smAndUp
  363. this.$nextTick(() => {
  364. if (window.location.hash && window.location.hash.length > 1) {
  365. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  366. }
  367. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  368. el.onclick = ev => {
  369. ev.preventDefault()
  370. ev.stopPropagation()
  371. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  372. }
  373. })
  374. })
  375. },
  376. methods: {
  377. goHome () {
  378. window.location.assign('/')
  379. },
  380. toggleNavigation () {
  381. this.navOpen = !this.navOpen
  382. },
  383. upBtnScroll () {
  384. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  385. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  386. },
  387. print () {
  388. window.print()
  389. },
  390. pageEdit () {
  391. this.$root.$emit('pageEdit')
  392. },
  393. pageHistory () {
  394. this.$root.$emit('pageHistory')
  395. },
  396. pageSource () {
  397. this.$root.$emit('pageSource')
  398. },
  399. pageMove () {
  400. this.$root.$emit('pageMove')
  401. },
  402. pageDelete () {
  403. this.$root.$emit('pageDelete')
  404. }
  405. }
  406. }
  407. </script>
  408. <style lang="scss">
  409. .breadcrumbs-nav {
  410. .v-btn {
  411. min-width: 0;
  412. &__content {
  413. text-transform: none;
  414. }
  415. }
  416. .v-breadcrumbs__divider:nth-child(2n) {
  417. padding: 0 6px;
  418. }
  419. .v-breadcrumbs__divider:nth-child(2) {
  420. padding: 0 6px 0 12px;
  421. }
  422. }
  423. </style>