2
0

page.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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, v-if='$vuetify.breakpoint.smAndUp')
  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. :items='breadcrumbs'
  37. divider='/'
  38. )
  39. template(slot='item', slot-scope='props')
  40. v-icon(v-if='props.item.path === "/"', small, @click='goHome') home
  41. v-btn.ma-0(v-else, :href='props.item.path', small, flat) {{props.item.name}}
  42. template(v-if='!isPublished')
  43. v-spacer
  44. .caption.red--text Unpublished
  45. status-indicator.ml-3(negative, pulse)
  46. v-divider
  47. v-layout(row)
  48. v-flex(xs12, lg9, xl10)
  49. v-toolbar(:color='darkMode ? `grey darken-4` : `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-divider
  54. .contents(ref='container')
  55. slot(name='contents')
  56. v-flex(lg3, xl2, fill-height, v-if='$vuetify.breakpoint.lgAndUp')
  57. v-toolbar(:color='darkMode ? `grey darken-4` : `grey lighten-4`', flat, :height='90')
  58. div
  59. .caption.grey--text.text--lighten-1 Last edited by
  60. .body-2.grey--text(:class='darkMode ? `` : `text--darken-3`') {{ authorName }}
  61. .caption.grey--text.text--darken-1 {{ updatedAt | moment('calendar') }}
  62. v-spacer
  63. v-tooltip(left)
  64. v-btn.btn-animate-edit(icon, slot='activator', :href='"/e/" + path')
  65. v-icon(color='grey') edit
  66. span Edit Page
  67. v-divider
  68. template(v-if='toc.length')
  69. v-list.grey.pb-3(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
  70. v-subheader.pl-4(:class='darkMode ? `blue--text text--lighten-1` : `primary--text`') Table of contents
  71. template(v-for='(tocItem, tocIdx) in toc')
  72. v-list-tile(@click='$vuetify.goTo(tocItem.anchor, scrollOpts)')
  73. v-icon(color='grey') arrow_right
  74. v-list-tile-title.pl-3 {{tocItem.title}}
  75. v-divider.ml-4(v-if='tocIdx < toc.length - 1 || tocItem.children.length')
  76. template(v-for='tocSubItem in tocItem.children')
  77. v-list-tile(@click='$vuetify.goTo(tocSubItem.anchor, scrollOpts)')
  78. v-icon.pl-3(color='grey lighten-1') arrow_right
  79. v-list-tile-title.pl-3.caption {{tocSubItem.title}}
  80. v-divider(inset, v-if='tocIdx < toc.length - 1')
  81. v-divider
  82. //- v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`')
  83. //- v-subheader.pl-4.yellow--text.text--darken-4 Rating
  84. //- .text-xs-center
  85. //- v-rating(
  86. //- v-model='rating'
  87. //- color='yellow darken-3'
  88. //- background-color='grey lighten-1'
  89. //- half-increments
  90. //- hover
  91. //- )
  92. //- .pb-2.caption.grey--text 5 votes
  93. //- v-divider
  94. template(v-if='tags.length')
  95. v-list.grey(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
  96. v-subheader.pl-4.teal--text Tags
  97. template(v-for='(tag, idx) in tags')
  98. v-list-tile(:href='`/t/` + tag.slug')
  99. v-list-tile-avatar: v-icon(color='teal') label
  100. v-list-tile-title {{tag.title}}
  101. v-divider(inset, v-if='idx < tags.length - 1')
  102. v-divider
  103. v-toolbar(:color='darkMode ? `grey darken-3` : `grey lighten-4`', flat, dense)
  104. v-spacer
  105. v-tooltip(bottom)
  106. v-btn(icon, slot='activator'): v-icon(color='grey') bookmark
  107. span Bookmark
  108. v-tooltip(bottom)
  109. v-btn(icon, slot='activator'): v-icon(color='grey') share
  110. span Share
  111. v-tooltip(bottom)
  112. v-btn(icon, slot='activator'): v-icon(color='grey') print
  113. span Print Format
  114. v-spacer
  115. nav-footer
  116. notify
  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. import _ from 'lodash'
  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. scrollStyle: {
  192. vuescroll: {},
  193. scrollPanel: {
  194. initialScrollX: 0.01, // fix scrollbar not disappearing on load
  195. scrollingX: false,
  196. speed: 50
  197. },
  198. rail: {
  199. gutterOfEnds: '2px'
  200. },
  201. bar: {
  202. onlyShowBarOnScroll: false,
  203. background: '#42A5F5',
  204. hoverStyle: {
  205. background: '#64B5F6'
  206. }
  207. }
  208. }
  209. }
  210. },
  211. computed: {
  212. darkMode: get('site/dark'),
  213. rating: {
  214. get () {
  215. return 3.5
  216. },
  217. set (val) {
  218. }
  219. },
  220. breadcrumbs() {
  221. return [{ path: '/', name: 'Home' }].concat(_.reduce(this.path.split('/'), (result, value, key) => {
  222. result.push({
  223. path: _.map(result, 'path').join('/') + `/${value}`,
  224. name: value
  225. })
  226. return result
  227. }, []))
  228. }
  229. },
  230. created() {
  231. this.$store.commit('page/SET_AUTHOR_ID', this.authorId)
  232. this.$store.commit('page/SET_AUTHOR_NAME', this.authorName)
  233. this.$store.commit('page/SET_CREATED_AT', this.createdAt)
  234. this.$store.commit('page/SET_DESCRIPTION', this.description)
  235. this.$store.commit('page/SET_IS_PUBLISHED', this.isPublished)
  236. this.$store.commit('page/SET_ID', this.pageId)
  237. this.$store.commit('page/SET_LOCALE', this.locale)
  238. this.$store.commit('page/SET_PATH', this.path)
  239. this.$store.commit('page/SET_TAGS', this.tags)
  240. this.$store.commit('page/SET_TITLE', this.title)
  241. this.$store.commit('page/SET_UPDATED_AT', this.updatedAt)
  242. this.$store.commit('page/SET_MODE', 'view')
  243. },
  244. mounted () {
  245. Prism.highlightAllUnder(this.$refs.container)
  246. this.navShown = this.$vuetify.breakpoint.smAndUp
  247. },
  248. methods: {
  249. goHome () {
  250. window.location.assign('/')
  251. },
  252. toggleNavigation () {
  253. this.navOpen = !this.navOpen
  254. },
  255. upBtnScroll () {
  256. const scrollOffset = window.pageYOffset || document.documentElement.scrollTop
  257. this.upBtnShown = scrollOffset > window.innerHeight * 0.33
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss">
  263. .breadcrumbs-nav {
  264. .v-btn {
  265. min-width: 0;
  266. &__content {
  267. text-transform: none;
  268. }
  269. }
  270. .v-breadcrumbs__divider:nth-child(2n) {
  271. padding: 0 6px;
  272. }
  273. .v-breadcrumbs__divider:nth-child(2) {
  274. padding: 0 6px 0 12px;
  275. }
  276. }
  277. </style>