|
15 | 15 | </div>
|
16 | 16 | </template>
|
17 | 17 |
|
18 |
| -<script src="./theme.js" lang="javascript"></script> |
| 18 | +<script> |
| 19 | + import Footer from '@theme/components/Footer' |
| 20 | + import Header from '@theme/components/Header' |
| 21 | + import Hero from '@theme/components/Hero' |
| 22 | + import Sidebar from '@theme/components/Sidebar' |
| 23 | + import { resolveSidebarItems } from './utils/util' |
| 24 | + import { translate } from './utils/translations' |
| 25 | +
|
| 26 | + export default { |
| 27 | + data () { |
| 28 | + return { |
| 29 | + isSidebarOpen: false, |
| 30 | + darkMode: false |
| 31 | + } |
| 32 | + }, |
| 33 | + components: { |
| 34 | + Footer, |
| 35 | + Header, |
| 36 | + Hero, |
| 37 | + Sidebar |
| 38 | + }, |
| 39 | + beforeMount () { |
| 40 | + if (localStorage && localStorage.getItem('dark-mode') !== null) { |
| 41 | + this.darkMode = localStorage.getItem('dark-mode') === "true" |
| 42 | + } |
| 43 | + }, |
| 44 | + mounted () { |
| 45 | + window.addEventListener('scroll', this.onScroll) |
| 46 | + if (localStorage && localStorage.getItem('dark-mode') === null) { |
| 47 | + this.darkMode = window.matchMedia('(prefers-color-scheme: dark)').matches |
| 48 | + } |
| 49 | + window.matchMedia('(prefers-color-scheme: dark)').addListener(({ matches }) => { |
| 50 | + if (localStorage && localStorage.getItem('dark-mode') === null) { |
| 51 | + this.darkMode = matches |
| 52 | + } |
| 53 | + }) |
| 54 | + }, |
| 55 | + computed: { |
| 56 | + isLanding() { |
| 57 | + return this.$page.frontmatter && this.$page.frontmatter.layout === "home" |
| 58 | + }, |
| 59 | + posts() { |
| 60 | + return this.$site.pages |
| 61 | + .filter(page => page.path.endsWith(".html") && page.path.startsWith(this.$page.path)) |
| 62 | + }, |
| 63 | + showSidebar () { |
| 64 | + return this.$page.frontmatter.sidebar |
| 65 | + }, |
| 66 | + sidebarItems () { |
| 67 | + return resolveSidebarItems( |
| 68 | + this.$page, |
| 69 | + this.$route, |
| 70 | + this.$site, |
| 71 | + this.$localePath |
| 72 | + ) |
| 73 | + }, |
| 74 | + contentClasses () { |
| 75 | + return { |
| 76 | + 'content-block': this.isLanding, |
| 77 | + 'page': !this.isLanding |
| 78 | + } |
| 79 | + }, |
| 80 | + pageClasses () { |
| 81 | + const userPageClass = this.$page.frontmatter.pageClass |
| 82 | + return [ |
| 83 | + { |
| 84 | + 'home': this.isLanding, |
| 85 | + 'has-sidebar': this.showSidebar, |
| 86 | + 'sidebar-open': this.isSidebarOpen, |
| 87 | + 'dark-mode': this.darkMode |
| 88 | + }, |
| 89 | + userPageClass |
| 90 | + ] |
| 91 | + }, |
| 92 | + linkText() { |
| 93 | + return translate('link-text-artwork', this.$lang) |
| 94 | + }, |
| 95 | + linkTextMore() { |
| 96 | + return translate('link-text-more', this.$lang) |
| 97 | + } |
| 98 | + }, |
| 99 | + methods: { |
| 100 | + toggleSidebar (to) { |
| 101 | + this.isSidebarOpen = typeof to === 'boolean' ? to : !this.isSidebarOpen |
| 102 | + }, |
| 103 | + closeSidebar () { |
| 104 | + this.isSidebarOpen = false |
| 105 | + }, |
| 106 | + toggleMode () { |
| 107 | + this.darkMode = this.darkMode ? false : true |
| 108 | + if (localStorage) { |
| 109 | + localStorage.setItem('dark-mode', this.darkMode) |
| 110 | + } |
| 111 | + } |
| 112 | + }, |
| 113 | + watch: { |
| 114 | + '$route' () { |
| 115 | + this.closeSidebar() |
| 116 | + } |
| 117 | + }, |
| 118 | + } |
| 119 | +</script> |
19 | 120 |
|
20 | 121 | <style lang="stylus" scoped>
|
21 | 122 | @require './styles/config'
|
|
0 commit comments