page.vue 9.7 KB

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