page.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. notify
  118. search-results
  119. v-fab-transition
  120. v-btn(v-if='upBtnShown', fab, fixed, bottom, right, small, @click='$vuetify.goTo(0, scrollOpts)', color='primary')
  121. v-icon arrow_upward
  122. </template>
  123. <script>
  124. import { StatusIndicator } from 'vue-status-indicator'
  125. import Prism from '@/libs/prism/prism.js'
  126. import { get } from 'vuex-pathify'
  127. export default {
  128. components: {
  129. StatusIndicator
  130. },
  131. props: {
  132. pageId: {
  133. type: Number,
  134. default: 0
  135. },
  136. locale: {
  137. type: String,
  138. default: 'en'
  139. },
  140. path: {
  141. type: String,
  142. default: 'home'
  143. },
  144. title: {
  145. type: String,
  146. default: 'Untitled Page'
  147. },
  148. description: {
  149. type: String,
  150. default: ''
  151. },
  152. createdAt: {
  153. type: String,
  154. default: ''
  155. },
  156. updatedAt: {
  157. type: String,
  158. default: ''
  159. },
  160. tags: {
  161. type: Array,
  162. default: () => ([])
  163. },
  164. authorName: {
  165. type: String,
  166. default: 'Unknown'
  167. },
  168. authorId: {
  169. type: Number,
  170. default: 0
  171. },
  172. isPublished: {
  173. type: Boolean,
  174. default: false
  175. },
  176. toc: {
  177. type: Array,
  178. default: () => []
  179. }
  180. },
  181. data() {
  182. return {
  183. navShown: false,
  184. navExpanded: false,
  185. upBtnShown: false,
  186. scrollOpts: {
  187. duration: 1500,
  188. offset: -75,
  189. easing: 'easeInOutCubic'
  190. },
  191. breadcrumbs: [
  192. { path: '/', name: 'Home' },
  193. { path: '/' + this.path, name: 'Breadcrumb' },
  194. { path: '/' + this.path, name: 'Coming soon' }
  195. ],
  196. scrollStyle: {
  197. vuescroll: {},
  198. scrollPanel: {
  199. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  200. scrollingX: false,
  201. speed: 50
  202. },
  203. rail: {
  204. gutterOfEnds: '2px'
  205. },
  206. bar: {
  207. onlyShowBarOnScroll: false,
  208. background: '#42A5F5',
  209. hoverStyle: {
  210. background: '#64B5F6'
  211. }
  212. }
  213. }
  214. }
  215. },
  216. computed: {
  217. darkMode: get('site/dark'),
  218. rating: {
  219. get () {
  220. return 3.5
  221. },
  222. set (val) {
  223. }
  224. }
  225. },
  226. created() {
  227. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  228. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  229. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  230. this.$store.commit('page/SET_DESCRIPTION', this.description)
  231. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  232. this.$store.commit('page/SET_ID', this.pageId)
  233. this.$store.commit('page/SET_LOCALE', this.locale)
  234. this.$store.commit('page/SET_PATH', this.path)
  235. this.$store.commit('page/SET_TAGS', this.tags)
  236. this.$store.commit('page/SET_TITLE', this.title)
  237. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  238. this.$store.commit('page/SET_MODE', 'view')
  239. },
  240. mounted () {
  241. Prism.highlightAllUnder(this.$refs.container)
  242. this.navShown = this.$vuetify.breakpoint.smAndUp
  243. },
  244. methods: {
  245. toggleNavigation () {
  246. this.navOpen = !this.navOpen
  247. },
  248. upBtnScroll () {
  249. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  250. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. .breadcrumbs-nav {
  257. .v-btn {
  258. min-width: 0;
  259. &__content {
  260. text-transform: none;
  261. }
  262. }
  263. .v-breadcrumbs__divider:nth-child(2n) {
  264. padding: 0 6px;
  265. }
  266. .v-breadcrumbs__divider:nth-child(2) {
  267. padding: 0 6px 0 12px;
  268. }
  269. }
  270. </style>