page.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template lang="pug">
  2. v-app(v-scroll='upBtnScroll', :dark='darkMode')
  3. nav-header
  4. v-navigation-drawer(
  5. :class='darkMode ? `grey darken-3` : `primary`'
  6. dark
  7. app
  8. clipped
  9. mobile-break-point='600'
  10. :temporary='$vuetify.breakpoint.mdAndDown'
  11. v-model='navShown'
  12. )
  13. vue-scroll(:ops='scrollStyle')
  14. nav-sidebar(:color='darkMode ? `grey darken-3` : `primary`')
  15. slot(name='sidebar')
  16. v-fab-transition
  17. v-btn(
  18. fab
  19. color='primary'
  20. fixed
  21. bottom
  22. left
  23. small
  24. @click='navShown = !navShown'
  25. v-if='$vuetify.breakpoint.mdAndDown'
  26. v-show='!navShown'
  27. )
  28. v-icon menu
  29. v-content(ref='content')
  30. template(v-if='path !== `home`')
  31. v-toolbar(:color='darkMode ? `grey darken-4-d3` : `grey lighten-3`', flat, dense)
  32. v-btn.pl-0(v-if='$vuetify.breakpoint.xsOnly', flat, @click='toggleNavigation')
  33. v-icon(color='grey darken-2', left) menu
  34. span Navigation
  35. v-breadcrumbs.breadcrumbs-nav.pl-0(
  36. v-else
  37. :items='breadcrumbs'
  38. divider='/'
  39. )
  40. template(slot='item', slot-scope='props')
  41. v-icon(v-if='props.item.path === "/"', small) home
  42. v-btn.ma-0(v-else, :href='props.item.path', small, flat) {{props.item.name}}
  43. template(v-if='!isPublished')
  44. v-spacer
  45. .caption.red--text Unpublished
  46. status-indicator.ml-3(negative, pulse)
  47. v-divider
  48. v-layout(row)
  49. v-flex(xs12, lg9, xl10)
  50. v-toolbar(:color='darkMode ? `grey darken-4` : `grey lighten-4`', flat, :height='90')
  51. div
  52. .headline.grey--text(:class='darkMode ? `text-lighten-2` : `text--darken-3`') {{title}}
  53. .caption.grey--text.text--darken-1 {{description}}
  54. v-divider
  55. .contents(ref='container')
  56. slot(name='contents')
  57. v-flex(lg3, xl2, fill-height, v-if='$vuetify.breakpoint.lgAndUp')
  58. v-toolbar(:color='darkMode ? `grey darken-4` : `grey lighten-4`', flat, :height='90')
  59. div
  60. .caption.grey--text.text--lighten-1 Last edited by
  61. .body-2.grey--text(:class='darkMode ? `` : `text--darken-3`') {{ authorName }}
  62. .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
  63. v-spacer
  64. v-tooltip(left)
  65. v-btn.btn-animate-edit(icon, slot='activator', :href='"/e/" + path')
  66. v-icon(color='grey') edit
  67. span Edit Page
  68. v-divider
  69. template(v-if='toc.length')
  70. v-list.grey.pb-3(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
  71. v-subheader.pl-4(:class='darkMode ? `blue--text text--lighten-1` : `primary--text`') Table of contents
  72. template(v-for='(tocItem, tocIdx) in toc')
  73. v-list-tile(@click='$vuetify.goTo(tocItem.anchor, scrollOpts)')
  74. v-icon(color='grey') arrow_right
  75. v-list-tile-title.pl-3 {{tocItem.title}}
  76. v-divider.ml-4(v-if='tocIdx < toc.length - 1 || tocItem.children.length')
  77. template(v-for='tocSubItem in tocItem.children')
  78. v-list-tile(@click='$vuetify.goTo(tocSubItem.anchor, scrollOpts)')
  79. v-icon.pl-3(color='grey lighten-1') arrow_right
  80. v-list-tile-title.pl-3.caption {{tocSubItem.title}}
  81. v-divider(inset, v-if='tocIdx < toc.length - 1')
  82. v-divider
  83. v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`')
  84. v-subheader.pl-4.yellow--text.text--darken-4 Rating
  85. .text-xs-center
  86. v-rating(
  87. v-model='rating'
  88. color='yellow darken-3'
  89. background-color='grey lighten-1'
  90. half-increments
  91. hover
  92. )
  93. .pb-2.caption.grey--text 5 votes
  94. v-divider
  95. template(v-if='tags.length')
  96. v-list.grey(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
  97. v-subheader.pl-4.teal--text Tags
  98. template(v-for='(tag, idx) in tags')
  99. v-list-tile(:href='`/t/` + tag.slug')
  100. v-list-tile-avatar: v-icon(color='teal') label
  101. v-list-tile-title {{tag.title}}
  102. v-divider(inset, v-if='idx < tags.length - 1')
  103. v-divider
  104. v-toolbar(:color='darkMode ? `grey darken-3` : `grey lighten-4`', flat, dense)
  105. v-spacer
  106. v-tooltip(bottom)
  107. v-btn(icon, slot='activator'): v-icon(color='grey') bookmark
  108. span Bookmark
  109. v-tooltip(bottom)
  110. v-btn(icon, slot='activator'): v-icon(color='grey') share
  111. span Share
  112. v-tooltip(bottom)
  113. v-btn(icon, slot='activator'): v-icon(color='grey') print
  114. span Print Format
  115. v-spacer
  116. nav-footer
  117. search-results
  118. v-fab-transition
  119. v-btn(v-if='upBtnShown', fab, fixed, bottom, right, small, @click='$vuetify.goTo(0, scrollOpts)', color='primary')
  120. v-icon arrow_upward
  121. </template>
  122. <script>
  123. import { StatusIndicator } from 'vue-status-indicator'
  124. import Prism from '@/libs/prism/prism.js'
  125. import { get } from 'vuex-pathify'
  126. export default {
  127. components: {
  128. StatusIndicator
  129. },
  130. props: {
  131. pageId: {
  132. type: Number,
  133. default: 0
  134. },
  135. locale: {
  136. type: String,
  137. default: 'en'
  138. },
  139. path: {
  140. type: String,
  141. default: 'home'
  142. },
  143. title: {
  144. type: String,
  145. default: 'Untitled Page'
  146. },
  147. description: {
  148. type: String,
  149. default: ''
  150. },
  151. createdAt: {
  152. type: String,
  153. default: ''
  154. },
  155. updatedAt: {
  156. type: String,
  157. default: ''
  158. },
  159. tags: {
  160. type: Array,
  161. default: () => ([])
  162. },
  163. authorName: {
  164. type: String,
  165. default: 'Unknown'
  166. },
  167. authorId: {
  168. type: Number,
  169. default: 0
  170. },
  171. isPublished: {
  172. type: Boolean,
  173. default: false
  174. },
  175. toc: {
  176. type: Array,
  177. default: () => []
  178. }
  179. },
  180. data() {
  181. return {
  182. navShown: false,
  183. navExpanded: false,
  184. upBtnShown: false,
  185. scrollOpts: {
  186. duration: 1500,
  187. offset: -75,
  188. easing: 'easeInOutCubic'
  189. },
  190. breadcrumbs: [
  191. { path: '/', name: 'Home' },
  192. { path: '/' + this.path, name: 'Breadcrumb' },
  193. { path: '/' + this.path, name: 'Coming soon' }
  194. ],
  195. scrollStyle: {
  196. vuescroll: {},
  197. scrollPanel: {
  198. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  199. scrollingX: false,
  200. speed: 50
  201. },
  202. rail: {
  203. gutterOfEnds: '2px'
  204. },
  205. bar: {
  206. onlyShowBarOnScroll: false,
  207. background: '#42A5F5',
  208. hoverStyle: {
  209. background: '#64B5F6'
  210. }
  211. }
  212. }
  213. }
  214. },
  215. computed: {
  216. darkMode: get('site/dark'),
  217. rating: {
  218. get () {
  219. return 3.5
  220. },
  221. set (val) {
  222. }
  223. }
  224. },
  225. created() {
  226. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  227. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  228. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  229. this.$store.commit('page/SET_DESCRIPTION', this.description)
  230. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  231. this.$store.commit('page/SET_ID', this.pageId)
  232. this.$store.commit('page/SET_LOCALE', this.locale)
  233. this.$store.commit('page/SET_PATH', this.path)
  234. this.$store.commit('page/SET_TAGS', this.tags)
  235. this.$store.commit('page/SET_TITLE', this.title)
  236. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  237. this.$store.commit('page/SET_MODE', 'view')
  238. },
  239. mounted () {
  240. Prism.highlightAllUnder(this.$refs.container)
  241. this.navShown = this.$vuetify.breakpoint.smAndUp
  242. },
  243. methods: {
  244. toggleNavigation () {
  245. this.navOpen = !this.navOpen
  246. },
  247. upBtnScroll () {
  248. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  249. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss">
  255. .breadcrumbs-nav {
  256. .v-btn {
  257. min-width: 0;
  258. &__content {
  259. text-transform: none;
  260. }
  261. }
  262. .v-breadcrumbs__divider:nth-child(2n) {
  263. padding: 0 6px;
  264. }
  265. .v-breadcrumbs__divider:nth-child(2) {
  266. padding: 0 6px 0 12px;
  267. }
  268. }
  269. </style>