vuepress-theme-uniapp-official 1.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/components/AlgoliaSearchBox.vue +130 -0
- package/components/DcloudSearchPage/components/Result.vue +160 -0
- package/components/DcloudSearchPage/components/Results.vue +66 -0
- package/components/DcloudSearchPage/components/pagination.vue +155 -0
- package/components/DcloudSearchPage/index.styl +183 -0
- package/components/DcloudSearchPage/index.vue +500 -0
- package/components/DcloudSearchPage/styles/ask.styl +272 -0
- package/components/DcloudSearchPage/styles/ext.styl +68 -0
- package/components/DcloudSearchPage/utils/Base64.js +134 -0
- package/components/DcloudSearchPage/utils/mock.js +434 -0
- package/components/DcloudSearchPage/utils/postDcloudServer.js +141 -0
- package/components/DcloudSearchPage/utils/searchClient.js +101 -0
- package/components/DcloudSearchPage/utils/searchUtils.js +52 -0
- package/components/Footer.vue +142 -0
- package/components/MainNavbarLink.vue +57 -0
- package/components/NavLink.vue +95 -0
- package/components/NavLinks.vue +173 -0
- package/components/Navbar.vue +322 -0
- package/components/NavbarLogo.vue +24 -0
- package/components/OutboundLink.vue +45 -0
- package/components/SearchBox/dist/match-query.dev.js +61 -0
- package/components/SearchBox/index.vue +337 -0
- package/components/SearchBox/match-query.js +51 -0
- package/components/SearchBox/search.svg +1 -0
- package/components/SidebarGroup.vue +141 -0
- package/components/SidebarLink.vue +152 -0
- package/components/SidebarLinks.vue +106 -0
- package/components/SiderBarBottom.vue +134 -0
- package/components/Sticker.vue +64 -0
- package/components/Toc-top.vue +95 -0
- package/components/Toc.vue +165 -0
- package/config/copy.js +7 -0
- package/config/footer.js +195 -0
- package/config/i18n/index.js +2 -0
- package/config/navbar.js +163 -0
- package/config/redirectRouter.js +120 -0
- package/config/searchPage.js +48 -0
- package/config/siderbar/index.js +8 -0
- package/config/siderbar/uni-app.js +210 -0
- package/config/siderbar/uniCloud.js +55 -0
- package/config/toc.js +5 -0
- package/enhanceApp.js +142 -0
- package/global-components/CodeSimulator.vue +211 -0
- package/global-components/icons.js +647 -0
- package/global-components/iconsLayouts.vue +117 -0
- package/global-components/uniIcon.vue +85 -0
- package/global-components/uniicons.css +656 -0
- package/global-components/uniicons.ttf +0 -0
- package/index.js +152 -0
- package/layouts/404.vue +22 -0
- package/layouts/Layout.vue +238 -0
- package/layouts/SimpleLayout.vue +18 -0
- package/mixin/navInject.js +21 -0
- package/mixin/navProvider.js +65 -0
- package/mixin/toc.js +36 -0
- package/package.json +50 -0
- package/styles/custom-block.styl +336 -0
- package/styles/footer.styl +248 -0
- package/styles/index.styl +197 -0
- package/styles/navbar.styl +293 -0
- package/styles/palette.styl +9 -0
- package/util/index.js +317 -0
package/util/index.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
|
|
3
|
+
export const isServer = Vue.prototype.$isServer
|
|
4
|
+
export const hashRE = /#.*$/
|
|
5
|
+
export const extRE = /\.(md|html)$/
|
|
6
|
+
export const endingSlashRE = /\/$/
|
|
7
|
+
export const outboundRE = /^[a-z]+:/i
|
|
8
|
+
|
|
9
|
+
export function normalize(path) {
|
|
10
|
+
return decodeURI(path)
|
|
11
|
+
.replace(hashRE, '')
|
|
12
|
+
.replace(extRE, '')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getHash(path) {
|
|
16
|
+
const match = path.match(hashRE)
|
|
17
|
+
if (match) {
|
|
18
|
+
return match[0]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isExternal(path) {
|
|
23
|
+
return outboundRE.test(path)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isMailto(path) {
|
|
27
|
+
return /^mailto:/.test(path)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isTel(path) {
|
|
31
|
+
return /^tel:/.test(path)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function ensureExt(path) {
|
|
35
|
+
if (isExternal(path)) {
|
|
36
|
+
return path
|
|
37
|
+
}
|
|
38
|
+
const hashMatch = path.match(hashRE)
|
|
39
|
+
const hash = hashMatch ? hashMatch[0] : ''
|
|
40
|
+
const normalized = normalize(path)
|
|
41
|
+
|
|
42
|
+
if (endingSlashRE.test(normalized)) {
|
|
43
|
+
return path
|
|
44
|
+
}
|
|
45
|
+
return normalized + '.html' + hash
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isActive(route, path) {
|
|
49
|
+
const routeHash = decodeURIComponent(route.hash)
|
|
50
|
+
const linkHash = getHash(path)
|
|
51
|
+
if (linkHash && routeHash !== linkHash) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
const routePath = normalize(route.path)
|
|
55
|
+
const pagePath = normalize(path)
|
|
56
|
+
return routePath === pagePath
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function resolvePage(pages, rawPath, base) {
|
|
60
|
+
if (isExternal(rawPath)) {
|
|
61
|
+
return {
|
|
62
|
+
type: 'external',
|
|
63
|
+
path: rawPath
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (base) {
|
|
67
|
+
rawPath = resolvePath(rawPath, base)
|
|
68
|
+
}
|
|
69
|
+
const path = normalize(rawPath)
|
|
70
|
+
const hash = rawPath.split('#')[1]
|
|
71
|
+
for (let i = 0; i < pages.length; i++) {
|
|
72
|
+
if (normalize(pages[i].regularPath) === path) {
|
|
73
|
+
return Object.assign({}, pages[i], {
|
|
74
|
+
type: 'page',
|
|
75
|
+
path: ensureExt(pages[i].path) + (hash ? `#${hash}` : '')
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
|
|
80
|
+
return {}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function resolvePath(relative, base, append) {
|
|
84
|
+
const firstChar = relative.charAt(0)
|
|
85
|
+
if (firstChar === '/') {
|
|
86
|
+
return relative
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (firstChar === '?' || firstChar === '#') {
|
|
90
|
+
return base + relative
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const stack = base.split('/')
|
|
94
|
+
|
|
95
|
+
// remove trailing segment if:
|
|
96
|
+
// - not appending
|
|
97
|
+
// - appending to trailing slash (last segment is empty)
|
|
98
|
+
if (!append || !stack[stack.length - 1]) {
|
|
99
|
+
stack.pop()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// resolve relative path
|
|
103
|
+
const segments = relative.replace(/^\//, '').split('/')
|
|
104
|
+
for (let i = 0; i < segments.length; i++) {
|
|
105
|
+
const segment = segments[i]
|
|
106
|
+
if (segment === '..') {
|
|
107
|
+
stack.pop()
|
|
108
|
+
} else if (segment !== '.') {
|
|
109
|
+
stack.push(segment)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ensure leading slash
|
|
114
|
+
if (stack[0] !== '') {
|
|
115
|
+
stack.unshift('')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return stack.join('/')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param { Page } page
|
|
123
|
+
* @param { string } regularPath
|
|
124
|
+
* @param { SiteData } site
|
|
125
|
+
* @param { string } localePath
|
|
126
|
+
* @returns { SidebarGroup }
|
|
127
|
+
*/
|
|
128
|
+
export function resolveSidebarItems(page, regularPath, site, localePath) {
|
|
129
|
+
const { pages, themeConfig } = site
|
|
130
|
+
|
|
131
|
+
const localeConfig = localePath && themeConfig.locales
|
|
132
|
+
? themeConfig.locales[localePath] || themeConfig
|
|
133
|
+
: themeConfig
|
|
134
|
+
|
|
135
|
+
const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar
|
|
136
|
+
if (pageSidebarConfig === 'auto') {
|
|
137
|
+
return resolveHeaders(page)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
|
|
141
|
+
if (!sidebarConfig) {
|
|
142
|
+
return []
|
|
143
|
+
} else {
|
|
144
|
+
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
|
|
145
|
+
if (config === 'auto') {
|
|
146
|
+
return resolveHeaders(page)
|
|
147
|
+
}
|
|
148
|
+
return config
|
|
149
|
+
? config.map(item => resolveItem(item, pages, base))
|
|
150
|
+
: []
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param { Page } page
|
|
156
|
+
* @returns { SidebarGroup }
|
|
157
|
+
*/
|
|
158
|
+
function resolveHeaders(page) {
|
|
159
|
+
const headers = groupHeaders(page.headers || [])
|
|
160
|
+
return [{
|
|
161
|
+
type: 'group',
|
|
162
|
+
collapsable: false,
|
|
163
|
+
title: page.title,
|
|
164
|
+
path: null,
|
|
165
|
+
children: headers.map(h => ({
|
|
166
|
+
type: 'auto',
|
|
167
|
+
title: h.title,
|
|
168
|
+
basePath: page.path,
|
|
169
|
+
path: page.path + '#' + h.slug,
|
|
170
|
+
children: h.children || []
|
|
171
|
+
}))
|
|
172
|
+
}]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function groupHeaders(headers) {
|
|
176
|
+
// group h3s under h2
|
|
177
|
+
headers = headers.map(h => Object.assign({}, h))
|
|
178
|
+
let lastH2
|
|
179
|
+
headers.forEach(h => {
|
|
180
|
+
if (h.level === 2) {
|
|
181
|
+
lastH2 = h
|
|
182
|
+
} else if (lastH2) {
|
|
183
|
+
(lastH2.children || (lastH2.children = [])).push(h)
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
// TODO h1-h3
|
|
187
|
+
return headers.filter(h => h.level === 2)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function resolveNavLinkItem(linkItem) {
|
|
191
|
+
return Object.assign(linkItem, {
|
|
192
|
+
type: linkItem.items && linkItem.items.length ? 'links' : 'link'
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param { Route } route
|
|
198
|
+
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config
|
|
199
|
+
* @returns { base: string, config: SidebarConfig }
|
|
200
|
+
*/
|
|
201
|
+
export function resolveMatchingConfig(regularPath, config) {
|
|
202
|
+
if (Array.isArray(config)) {
|
|
203
|
+
return {
|
|
204
|
+
base: '/',
|
|
205
|
+
config: config
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (const base in config) {
|
|
209
|
+
if (ensureEndingSlash(regularPath).indexOf(encodeURI(base)) === 0) {
|
|
210
|
+
return {
|
|
211
|
+
base,
|
|
212
|
+
config: config[base]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function ensureEndingSlash(path) {
|
|
220
|
+
return /(\.html|\/)$/.test(path)
|
|
221
|
+
? path
|
|
222
|
+
: path + '/'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function resolveItem(item, pages, base, groupDepth = 1) {
|
|
226
|
+
if (typeof item === 'string') {
|
|
227
|
+
return resolvePage(pages, item, base)
|
|
228
|
+
} else if (Array.isArray(item)) {
|
|
229
|
+
return Object.assign(resolvePage(pages, item[0], base), {
|
|
230
|
+
title: item[1]
|
|
231
|
+
})
|
|
232
|
+
} else {
|
|
233
|
+
const children = item.children || []
|
|
234
|
+
if (children.length === 0 && item.path) {
|
|
235
|
+
return Object.assign(resolvePage(pages, item.path, base), {
|
|
236
|
+
title: item.title
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
type: 'group',
|
|
241
|
+
path: item.path,
|
|
242
|
+
title: item.title,
|
|
243
|
+
sidebarDepth: item.sidebarDepth,
|
|
244
|
+
initialOpenGroupIndex: item.initialOpenGroupIndex,
|
|
245
|
+
children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)),
|
|
246
|
+
collapsable: item.collapsable !== false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function forbidScroll(use = true) {
|
|
252
|
+
if (use) {
|
|
253
|
+
const classList = document.body.className.split(' ')
|
|
254
|
+
classList.push('forbid_scroll')
|
|
255
|
+
document.body.className = classList.join(' ')
|
|
256
|
+
} else {
|
|
257
|
+
document.body.className = document.body.className.replace(/\s+forbid_scroll/g, '')
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export const os = {
|
|
262
|
+
android: false,
|
|
263
|
+
ios: false,
|
|
264
|
+
mobile: false,
|
|
265
|
+
pc: false,
|
|
266
|
+
init: function () {
|
|
267
|
+
var ua = navigator.userAgent;
|
|
268
|
+
if (ua.match(/(Android);?[\s\/]+([\d+.]+)?/)) {
|
|
269
|
+
this.android = true;
|
|
270
|
+
this.mobile = true;
|
|
271
|
+
this.pc = false;
|
|
272
|
+
} else if (ua.match(/(iPhone\sOS)\s([\d_]+)/)) {
|
|
273
|
+
this.ios = true;
|
|
274
|
+
this.mobile = true;
|
|
275
|
+
this.pc = false;
|
|
276
|
+
} else {
|
|
277
|
+
this.android = false;
|
|
278
|
+
this.ios = false;
|
|
279
|
+
this.mobile = false;
|
|
280
|
+
this.pc = true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export function debounce(fn, delay) {
|
|
286
|
+
let timeout
|
|
287
|
+
const newFn = function () {
|
|
288
|
+
clearTimeout(timeout)
|
|
289
|
+
const timerFn = () => fn.apply(this, arguments)
|
|
290
|
+
timeout = setTimeout(timerFn, delay)
|
|
291
|
+
}
|
|
292
|
+
newFn.cancel = function () {
|
|
293
|
+
clearTimeout(timeout)
|
|
294
|
+
}
|
|
295
|
+
return newFn
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/*
|
|
299
|
+
* find parent vm by ref
|
|
300
|
+
* @param {String} ref
|
|
301
|
+
* @param {Vue} vm
|
|
302
|
+
* @param {any} def default value
|
|
303
|
+
* @returns {Element}
|
|
304
|
+
*/
|
|
305
|
+
export function findContainerInVm(ref, vm, def) {
|
|
306
|
+
if (!ref) return def
|
|
307
|
+
let container
|
|
308
|
+
let parent = vm
|
|
309
|
+
while ((parent = parent.$parent) && !container) {
|
|
310
|
+
container = parent.$refs[ref]
|
|
311
|
+
}
|
|
312
|
+
// Ensure it's html element (ref could be component)
|
|
313
|
+
if (container && container.$el) {
|
|
314
|
+
container = container.$el
|
|
315
|
+
}
|
|
316
|
+
return container || def
|
|
317
|
+
}
|