2
0

page.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 }')
  131. v-btn.btn-animate-edit(
  132. fab
  133. bottom
  134. :right='!$vuetify.rtl'
  135. :left='$vuetify.rtl'
  136. color='primary'
  137. fixed
  138. dark
  139. :href='"/e/" + locale + "/" + path'
  140. v-on='on'
  141. )
  142. v-icon mdi-pencil
  143. span {{$t('common:page.editPage')}}
  144. .contents(ref='container')
  145. slot(name='contents')
  146. nav-footer
  147. notify
  148. search-results
  149. v-fab-transition
  150. v-btn(
  151. v-if='upBtnShown'
  152. fab
  153. fixed
  154. bottom
  155. :right='$vuetify.rtl'
  156. :left='!$vuetify.rtl'
  157. small
  158. depressed
  159. @click='$vuetify.goTo(0, scrollOpts)'
  160. color='primary'
  161. dark
  162. :style='$vuetify.rtl ? `right: 235px;` : `left: 235px;`'
  163. )
  164. v-icon mdi-arrow-up
  165. </template>
  166. <script>
  167. import { StatusIndicator } from 'vue-status-indicator'
  168. import Prism from 'prismjs'
  169. import { get } from 'vuex-pathify'
  170. import _ from 'lodash'
  171. Prism.plugins.autoloader.languages_path = '/js/prism/'
  172. Prism.plugins.NormalizeWhitespace.setDefaults({
  173. 'remove-trailing': true,
  174. 'remove-indent': true,
  175. 'left-trim': true,
  176. 'right-trim': true,
  177. 'break-lines': 160,
  178. 'remove-initial-line-feed': true,
  179. 'tabs-to-spaces': 2
  180. })
  181. export default {
  182. components: {
  183. StatusIndicator
  184. },
  185. props: {
  186. pageId: {
  187. type: Number,
  188. default: 0
  189. },
  190. locale: {
  191. type: String,
  192. default: 'en'
  193. },
  194. path: {
  195. type: String,
  196. default: 'home'
  197. },
  198. title: {
  199. type: String,
  200. default: 'Untitled Page'
  201. },
  202. description: {
  203. type: String,
  204. default: ''
  205. },
  206. createdAt: {
  207. type: String,
  208. default: ''
  209. },
  210. updatedAt: {
  211. type: String,
  212. default: ''
  213. },
  214. tags: {
  215. type: Array,
  216. default: () => ([])
  217. },
  218. authorName: {
  219. type: String,
  220. default: 'Unknown'
  221. },
  222. authorId: {
  223. type: Number,
  224. default: 0
  225. },
  226. isPublished: {
  227. type: Boolean,
  228. default: false
  229. },
  230. toc: {
  231. type: Array,
  232. default: () => []
  233. },
  234. sidebar: {
  235. type: Array,
  236. default: () => []
  237. }
  238. },
  239. data() {
  240. return {
  241. navShown: false,
  242. navExpanded: false,
  243. upBtnShown: false,
  244. scrollOpts: {
  245. duration: 1500,
  246. offset: 0,
  247. easing: 'easeInOutCubic'
  248. },
  249. scrollStyle: {
  250. vuescroll: {},
  251. scrollPanel: {
  252. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  253. scrollingX: false,
  254. speed: 50
  255. },
  256. rail: {
  257. gutterOfEnds: '2px'
  258. },
  259. bar: {
  260. onlyShowBarOnScroll: false,
  261. background: '#42A5F5',
  262. hoverStyle: {
  263. background: '#64B5F6'
  264. }
  265. }
  266. }
  267. }
  268. },
  269. computed: {
  270. darkMode: get('site/dark'),
  271. isAuthenticated: get('user/authenticated'),
  272. rating: {
  273. get () {
  274. return 3.5
  275. },
  276. set (val) {
  277. }
  278. },
  279. breadcrumbs() {
  280. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  281. result.push({
  282. path: _.map(result, 'path').join('/') + `/${value}`,
  283. name: value
  284. })
  285. return result
  286. }, []))
  287. }
  288. },
  289. created() {
  290. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  291. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  292. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  293. this.$store.commit('page/SET_DESCRIPTION', this.description)
  294. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  295. this.$store.commit('page/SET_ID', this.pageId)
  296. this.$store.commit('page/SET_LOCALE', this.locale)
  297. this.$store.commit('page/SET_PATH', this.path)
  298. this.$store.commit('page/SET_TAGS', this.tags)
  299. this.$store.commit('page/SET_TITLE', this.title)
  300. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  301. this.$store.commit('page/SET_MODE', 'view')
  302. },
  303. mounted () {
  304. Prism.highlightAllUnder(this.$refs.container)
  305. this.navShown = this.$vuetify.breakpoint.smAndUp
  306. this.$nextTick(() => {
  307. if (window.location.hash && window.location.hash.length > 1) {
  308. this.$vuetify.goTo(window.location.hash, this.scrollOpts)
  309. }
  310. this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
  311. el.onclick = ev => {
  312. ev.preventDefault()
  313. ev.stopPropagation()
  314. this.$vuetify.goTo(ev.target.hash, this.scrollOpts)
  315. }
  316. })
  317. })
  318. },
  319. methods: {
  320. goHome () {
  321. window.location.assign('/')
  322. },
  323. toggleNavigation () {
  324. this.navOpen = !this.navOpen
  325. },
  326. upBtnScroll () {
  327. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  328. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  329. },
  330. print () {
  331. window.print()
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss">
  337. .breadcrumbs-nav {
  338. .v-btn {
  339. min-width: 0;
  340. &__content {
  341. text-transform: none;
  342. }
  343. }
  344. .v-breadcrumbs__divider:nth-child(2n) {
  345. padding: 0 6px;
  346. }
  347. .v-breadcrumbs__divider:nth-child(2) {
  348. padding: 0 6px 0 12px;
  349. }
  350. }
  351. </style>