page.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template lang="pug">
  2. v-app(v-scroll='upBtnScroll', :dark='darkMode')
  3. nav-header
  4. v-navigation-drawer(
  5. :class='darkMode ? `grey darken-5` : `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-5` : `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-toolbar.px-2(:color='darkMode ? `grey darken-4-l3` : `grey lighten-4`', flat, :height='90')
  49. div(style='padding-left: 376px;')
  50. .headline.grey--text(:class='darkMode ? `text--lighten-2` : `text--darken-3`') {{title}}
  51. .caption.grey--text.text--darken-1 {{description}}
  52. v-spacer
  53. v-divider
  54. v-container.pl-5.pt-2(fill-height, fluid, grid-list-xl)
  55. v-layout(row)
  56. v-flex.page-col-sd(lg3, xl2, fill-height, v-if='$vuetify.breakpoint.lgAndUp', style='margin-top: -90px;')
  57. v-card(v-if='toc.length')
  58. .overline.pa-5.pb-0(:class='darkMode ? `indigo--text text--lighten-3` : `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) mdi-chevron-right
  63. v-list-item-title.pl-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.pl-3(color='grey lighten-1', small) mdi-chevron-right
  68. v-list-item-title.pl-3.caption.grey--text.text--darken-1 {{tocSubItem.title}}
  69. //- v-divider(inset, v-if='tocIdx < toc.length - 1')
  70. v-card.mt-5
  71. .pa-5.pt-3
  72. .overline.indigo--text.d-flex.align-center
  73. span {{$t('common:page.lastEditedBy')}}
  74. v-spacer
  75. v-tooltip(top, v-if='isAuthenticated')
  76. template(v-slot:activator='{ on }')
  77. v-btn.btn-animate-edit(icon, :href='"/h/" + locale + "/" + path', v-on='on', x-small)
  78. v-icon(color='grey', dense) mdi-history
  79. span History
  80. .body-2.grey--text(:class='darkMode ? `` : `text--darken-3`') {{ authorName }}
  81. .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
  82. v-card.mt-5(v-if='tags.length > 0 || true')
  83. .pa-5
  84. .overline.teal--text.pb-2 Tags
  85. v-chip.mr-1(
  86. label
  87. color='teal lighten-5'
  88. v-for='(tag, idx) in tags'
  89. :href='`/t/` + tag.slug'
  90. :key='tag.slug'
  91. )
  92. v-icon(color='teal', left, small) mdi-label
  93. span.teal--text.text--darken-2 {{tag.text}}
  94. v-card.mt-5
  95. .pa-5
  96. .overline.pb-2.yellow--text.text--darken-4 Rating
  97. .text-center
  98. v-rating(
  99. v-model='rating'
  100. color='yellow darken-3'
  101. background-color='grey lighten-1'
  102. half-increments
  103. hover
  104. )
  105. .caption.grey--text 5 votes
  106. v-divider
  107. v-toolbar(:color='darkMode ? `grey darken-3` : `grey lighten-4`', flat, dense)
  108. v-spacer
  109. v-tooltip(bottom)
  110. template(v-slot:activator='{ on }')
  111. v-btn(icon, tile, small, v-on='on'): v-icon(color='grey') mdi-bookmark
  112. span {{$t('common:page.bookmark')}}
  113. v-tooltip(bottom)
  114. template(v-slot:activator='{ on }')
  115. v-btn(icon, tile, small, v-on='on'): v-icon(color='grey') mdi-share-variant
  116. span {{$t('common:page.share')}}
  117. v-tooltip(bottom)
  118. template(v-slot:activator='{ on }')
  119. v-btn(icon, tile, small, v-on='on'): v-icon(color='grey') mdi-printer
  120. span {{$t('common:page.printFormat')}}
  121. v-spacer
  122. v-flex.page-col-content(xs12, lg9, xl10)
  123. v-tooltip(left, v-if='isAuthenticated')
  124. template(v-slot:activator='{ on }')
  125. v-btn.btn-animate-edit(fab, bottom, right, color='primary', fixed, dark, :href='"/e/" + locale + "/" + path', v-on='on')
  126. v-icon mdi-pencil
  127. span {{$t('common:page.editPage')}}
  128. .contents(ref='container')
  129. slot(name='contents')
  130. nav-footer
  131. notify
  132. search-results
  133. v-fab-transition
  134. v-btn(
  135. v-if='upBtnShown'
  136. fab
  137. fixed
  138. bottom
  139. :right='$vuetify.rtl'
  140. :left='!$vuetify.rtl'
  141. small
  142. depressed
  143. @click='$vuetify.goTo(0, scrollOpts)'
  144. color='primary'
  145. dark
  146. :style='$vuetify.rtl ? `right: 235px;` : `left: 235px;`'
  147. )
  148. v-icon mdi-arrow-up
  149. </template>
  150. <script>
  151. import { StatusIndicator } from 'vue-status-indicator'
  152. import Prism from 'prismjs'
  153. import { get } from 'vuex-pathify'
  154. import _ from 'lodash'
  155. Prism.plugins.autoloader.languages_path = '/js/prism/'
  156. Prism.plugins.NormalizeWhitespace.setDefaults({
  157. 'remove-trailing': true,
  158. 'remove-indent': true,
  159. 'left-trim': true,
  160. 'right-trim': true,
  161. 'break-lines': 160,
  162. 'remove-initial-line-feed': true,
  163. 'tabs-to-spaces': 2
  164. })
  165. export default {
  166. components: {
  167. StatusIndicator
  168. },
  169. props: {
  170. pageId: {
  171. type: Number,
  172. default: 0
  173. },
  174. locale: {
  175. type: String,
  176. default: 'en'
  177. },
  178. path: {
  179. type: String,
  180. default: 'home'
  181. },
  182. title: {
  183. type: String,
  184. default: 'Untitled Page'
  185. },
  186. description: {
  187. type: String,
  188. default: ''
  189. },
  190. createdAt: {
  191. type: String,
  192. default: ''
  193. },
  194. updatedAt: {
  195. type: String,
  196. default: ''
  197. },
  198. tags: {
  199. type: Array,
  200. default: () => ([])
  201. },
  202. authorName: {
  203. type: String,
  204. default: 'Unknown'
  205. },
  206. authorId: {
  207. type: Number,
  208. default: 0
  209. },
  210. isPublished: {
  211. type: Boolean,
  212. default: false
  213. },
  214. toc: {
  215. type: Array,
  216. default: () => []
  217. },
  218. sidebar: {
  219. type: Array,
  220. default: () => []
  221. }
  222. },
  223. data() {
  224. return {
  225. navShown: false,
  226. navExpanded: false,
  227. upBtnShown: false,
  228. scrollOpts: {
  229. duration: 1500,
  230. offset: -75,
  231. easing: 'easeInOutCubic'
  232. },
  233. scrollStyle: {
  234. vuescroll: {},
  235. scrollPanel: {
  236. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  237. scrollingX: false,
  238. speed: 50
  239. },
  240. rail: {
  241. gutterOfEnds: '2px'
  242. },
  243. bar: {
  244. onlyShowBarOnScroll: false,
  245. background: '#42A5F5',
  246. hoverStyle: {
  247. background: '#64B5F6'
  248. }
  249. }
  250. }
  251. }
  252. },
  253. computed: {
  254. darkMode: get('site/dark'),
  255. isAuthenticated: get('user/authenticated'),
  256. rating: {
  257. get () {
  258. return 3.5
  259. },
  260. set (val) {
  261. }
  262. },
  263. breadcrumbs() {
  264. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  265. result.push({
  266. path: _.map(result, 'path').join('/') + `/${value}`,
  267. name: value
  268. })
  269. return result
  270. }, []))
  271. }
  272. },
  273. created() {
  274. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  275. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  276. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  277. this.$store.commit('page/SET_DESCRIPTION', this.description)
  278. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  279. this.$store.commit('page/SET_ID', this.pageId)
  280. this.$store.commit('page/SET_LOCALE', this.locale)
  281. this.$store.commit('page/SET_PATH', this.path)
  282. this.$store.commit('page/SET_TAGS', this.tags)
  283. this.$store.commit('page/SET_TITLE', this.title)
  284. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  285. this.$store.commit('page/SET_MODE', 'view')
  286. },
  287. mounted () {
  288. Prism.highlightAllUnder(this.$refs.container)
  289. this.navShown = this.$vuetify.breakpoint.smAndUp
  290. },
  291. methods: {
  292. goHome () {
  293. window.location.assign('/')
  294. },
  295. toggleNavigation () {
  296. this.navOpen = !this.navOpen
  297. },
  298. upBtnScroll () {
  299. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  300. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  301. }
  302. }
  303. }
  304. </script>
  305. <style lang="scss">
  306. .breadcrumbs-nav {
  307. .v-btn {
  308. min-width: 0;
  309. &__content {
  310. text-transform: none;
  311. }
  312. }
  313. .v-breadcrumbs__divider:nth-child(2n) {
  314. padding: 0 6px;
  315. }
  316. .v-breadcrumbs__divider:nth-child(2) {
  317. padding: 0 6px 0 12px;
  318. }
  319. }
  320. </style>