forked from ktquez/vuepress-theme-ktquez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.vue
227 lines (193 loc) · 6.25 KB
/
Layout.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
<div
class="layout-main"
:class="{ 'layout-main__nm--opened': nmOpened, 'layout-main__negative': negative }"
itemscope itemtype="https://schema.org/WebPage">
<meta itemprop="name" :content="$site.title">
<meta itemprop="alternateName" :content="$site.title">
<meta itemprop="url" :content="$themeConfig.url">
<transition name="nav-mobile">
<nav-mobile v-show="nmOpened" @click="closeMenu" />
</transition>
<transition :name="transitionName">
<component :is="layout" class="wrapper-body__nm" :class="{ 'wrapper-body__nm--opened': nmOpened }">
<div slot="view">
<skip-to to="#main" :text="$t('skip_to_main_content')" />
<component :is="view" />
<global-events @keyup.esc="cancel" />
<back-to-top />
<overlay />
</div>
</component>
</transition>
<vue-announcer v-if="announcerHasLoaded" />
<SWUpdatePopup :updateEvent="swUpdateEvent"/>
</div>
</template>
<script>
// layouts
import LayoutBase from '@theme/layouts/Base'
import LayoutPost from '@theme/layouts/Post'
import LayoutPage from '@theme/layouts/Page'
// views
import Home from '@theme/views/Home'
import Page from '@theme/views/Page'
import Post from '@theme/views/Post'
import Posts from '@theme/views/Posts'
import Category from '@theme/views/Category'
import Author from '@theme/views/Author'
import Authors from '@theme/views/Authors'
import Categories from '@theme/views/Categories'
// plugins
import EventBus from '@theme/plugins/EventBus'
// Components
import SWUpdatePopup from '@theme/components/SW/UpdatePopup'
// Mixins
import NProgressMixin from '@theme/mixins/NProgress'
import AnnouncerMixin from '@theme/mixins/Announcer'
import FontFaceObserver from 'fontfaceobserver'
export default {
name: 'MainLayout',
mixins: [NProgressMixin, AnnouncerMixin],
components: {
Home,
Page,
Post,
Posts,
Author,
Authors,
Categories,
Category,
LayoutBase,
LayoutPost,
LayoutPage,
SWUpdatePopup,
Overlay: () => import(/* webpackChunkName = "Overlay" */ '@theme/components/Overlay'),
NavMobile: () => import(/* webpackChunkName = "NavMobile" */ '@theme/components/NavMobile'),
GlobalEvents: () => import(/* webpackChunkName = "GlobalEvents" */ 'vue-global-events'),
SkipTo: () => import(/* webpackChunkName = "SkipTo" */ '@theme/components/SkipTo'),
BackToTop: () => import(/* webpackChunkName = "BackToTop" */ '@theme/components/BackToTop')
},
data () {
return {
transitionName: 'slideleft',
nmOpened: false,
negative: false,
swUpdateEvent: null
}
},
watch: {
'$route' (to, from) {
const toDepth = to.path.split('/').length
const fromDepth = from.path.split('/').length
this.transitionName = toDepth < fromDepth ? 'slideright' : 'slideleft'
}
},
computed: {
layout () {
return 'layout-' + (this.$page.frontmatter.layout || 'base')
},
view () {
return this.$page.frontmatter.view
}
},
created () {
EventBus.$on('show_nm', data => {
this.nmOpened = data
})
if (this.$themeConfig.blackWhite) {
EventBus.$on('toggle_black_white', data => {
this.negative = data
})
}
},
beforeMount () {
// SW update tip for PWA
this.$on('sw-updated', this.onSWUpdated)
this.handleLoadWebFont()
},
methods: {
handleLoadWebFont () {
const poppinsRegular = new FontFaceObserver('Poppins', { weight: 400 })
const poppinsBold = new FontFaceObserver('Poppins', { weight: 700 })
if (sessionStorage.fontsLoaded) {
return document.documentElement.classList.add('fonts-loaded')
}
Promise.all([poppinsRegular.load(), poppinsBold.load()]).then(() => {
document.documentElement.classList.add('fonts-loaded')
sessionStorage.fontsLoaded = true
}).catch(() => {
sessionStorage.fontsLoaded = false
})
},
cancel () {
EventBus.$emit('show_search', false)
EventBus.$emit('close_overlay', false)
},
closeMenu () {
this.nmOpened = false
EventBus.$emit('close_nm', false)
},
onSWUpdated (e) {
this.swUpdateEvent = e
}
}
}
</script>
<style src="carbon-grid"></style>
<style src="./styles/base.styl" lang="stylus"></style>
<style lang="stylus">
@import '~@theme/styles/config.styl'
.layout-main
&__nm
&--opened
background-color: darken($accentColor, 10%)
&__negative
&.layout-main__nm--opened,
*:not(.no_bw):not([class*='switch-bw']):not([class*='hamburguer__']):not([class*='language-']):not(code):not(.token)
background-color: black !important
color: white !important
box-shadow: none !important
fill: black !important
input, button:not(.back-button)
border: 1px solid white !important
::placeholder
color: white
.wrapper-body
&__nm
transition: transform .2s ease-in-out
transform-origin: top center
&--opened
border-radius: 20px
overflow: hidden
transform: perspective(400px) scale3d(.85, .85, 1)
@media (max-width: $mobile)
[class^="slideright"], [class^="slideleft"]
will-change: transform, opacity
.slideright-enter-active, .slideright-leave-active {
transition: transform .250s, opacity .1s;
}
.slideright-enter /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
position: absolute !important;
transform: translate(-100%) !important;
}
.slideright-leave-to /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
transform: translate(100%) !important;
position: absolute !important;
}
.slideleft-enter-active, .slideleft-leave-active {
transition: transform .250s, opacity .1s;
}
.slideleft-enter /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
position: absolute !important;
transform: translate(100%) !important;
}
.slideleft-leave-to /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
transform: translate(-100%) !important;
position: absolute !important;
}
</style>