fix: v1.10.2 - 修复nav不规范配置时导致浏览器控制台以及build时报错的问题
This commit is contained in:
parent
2b945d3dcb
commit
3844f83f6d
|
|
@ -24,7 +24,7 @@
|
||||||
"vuepress-plugin-one-click-copy": "^1.0.2",
|
"vuepress-plugin-one-click-copy": "^1.0.2",
|
||||||
"vuepress-plugin-thirdparty-search": "^1.0.2",
|
"vuepress-plugin-thirdparty-search": "^1.0.2",
|
||||||
"vuepress-plugin-zooming": "^1.1.7",
|
"vuepress-plugin-zooming": "^1.1.7",
|
||||||
"vuepress-theme-vdoing": "^1.10.1",
|
"vuepress-theme-vdoing": "^1.10.2",
|
||||||
"yamljs": "^0.3.0"
|
"yamljs": "^0.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vuepress-theme-vdoing",
|
"name": "vuepress-theme-vdoing",
|
||||||
"version": "1.10.1",
|
"version": "1.10.2",
|
||||||
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
|
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "gaoyi(Evan) Xu"
|
"name": "gaoyi(Evan) Xu"
|
||||||
|
|
|
||||||
|
|
@ -3,35 +3,36 @@ export const extRE = /\.(md|html)$/
|
||||||
export const endingSlashRE = /\/$/
|
export const endingSlashRE = /\/$/
|
||||||
export const outboundRE = /^[a-z]+:/i
|
export const outboundRE = /^[a-z]+:/i
|
||||||
|
|
||||||
export function normalize (path) {
|
export function normalize(path) {
|
||||||
return decodeURI(path)
|
return decodeURI(path)
|
||||||
.replace(hashRE, '')
|
.replace(hashRE, '')
|
||||||
.replace(extRE, '')
|
.replace(extRE, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHash (path) {
|
export function getHash(path) {
|
||||||
const match = path.match(hashRE)
|
const match = path?.match(hashRE)
|
||||||
if (match) {
|
if (match) {
|
||||||
return match[0]
|
return match[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isExternal (path) {
|
export function isExternal(path) {
|
||||||
return outboundRE.test(path)
|
return outboundRE.test(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isMailto (path) {
|
export function isMailto(path) {
|
||||||
return /^mailto:/.test(path)
|
return /^mailto:/.test(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isTel (path) {
|
export function isTel(path) {
|
||||||
return /^tel:/.test(path)
|
return /^tel:/.test(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureExt (path) {
|
export function ensureExt(path) {
|
||||||
if (isExternal(path)) {
|
if (isExternal(path)) {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
if (!path) return '404'
|
||||||
const hashMatch = path.match(hashRE)
|
const hashMatch = path.match(hashRE)
|
||||||
const hash = hashMatch ? hashMatch[0] : ''
|
const hash = hashMatch ? hashMatch[0] : ''
|
||||||
const normalized = normalize(path)
|
const normalized = normalize(path)
|
||||||
|
|
@ -42,7 +43,7 @@ export function ensureExt (path) {
|
||||||
return normalized + '.html' + hash
|
return normalized + '.html' + hash
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isActive (route, path) {
|
export function isActive(route, path) {
|
||||||
const routeHash = route.hash
|
const routeHash = route.hash
|
||||||
const linkHash = getHash(path)
|
const linkHash = getHash(path)
|
||||||
if (linkHash && routeHash !== linkHash) {
|
if (linkHash && routeHash !== linkHash) {
|
||||||
|
|
@ -53,7 +54,7 @@ export function isActive (route, path) {
|
||||||
return routePath === pagePath
|
return routePath === pagePath
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolvePage (pages, rawPath, base) {
|
export function resolvePage(pages, rawPath, base) {
|
||||||
if (isExternal(rawPath)) {
|
if (isExternal(rawPath)) {
|
||||||
return {
|
return {
|
||||||
type: 'external',
|
type: 'external',
|
||||||
|
|
@ -76,7 +77,7 @@ export function resolvePage (pages, rawPath, base) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolvePath (relative, base, append) {
|
function resolvePath(relative, base, append) {
|
||||||
const firstChar = relative.charAt(0)
|
const firstChar = relative.charAt(0)
|
||||||
if (firstChar === '/') {
|
if (firstChar === '/') {
|
||||||
return relative
|
return relative
|
||||||
|
|
@ -121,7 +122,7 @@ function resolvePath (relative, base, append) {
|
||||||
* @param { string } localePath
|
* @param { string } localePath
|
||||||
* @returns { SidebarGroup }
|
* @returns { SidebarGroup }
|
||||||
*/
|
*/
|
||||||
export function resolveSidebarItems (page, regularPath, site, localePath) {
|
export function resolveSidebarItems(page, regularPath, site, localePath) {
|
||||||
const { pages, themeConfig } = site
|
const { pages, themeConfig } = site
|
||||||
|
|
||||||
const localeConfig = localePath && themeConfig.locales
|
const localeConfig = localePath && themeConfig.locales
|
||||||
|
|
@ -151,7 +152,7 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
|
||||||
* @param { Page } page
|
* @param { Page } page
|
||||||
* @returns { SidebarGroup }
|
* @returns { SidebarGroup }
|
||||||
*/
|
*/
|
||||||
function resolveHeaders (page) {
|
function resolveHeaders(page) {
|
||||||
const headers = groupHeaders(page.headers || [])
|
const headers = groupHeaders(page.headers || [])
|
||||||
return [{
|
return [{
|
||||||
type: 'group',
|
type: 'group',
|
||||||
|
|
@ -168,7 +169,7 @@ function resolveHeaders (page) {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function groupHeaders (headers) {
|
export function groupHeaders(headers) {
|
||||||
// group h3s under h2
|
// group h3s under h2
|
||||||
headers = headers.map(h => Object.assign({}, h))
|
headers = headers.map(h => Object.assign({}, h))
|
||||||
let lastH2
|
let lastH2
|
||||||
|
|
@ -182,7 +183,7 @@ export function groupHeaders (headers) {
|
||||||
return headers.filter(h => h.level === 2)
|
return headers.filter(h => h.level === 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveNavLinkItem (linkItem) {
|
export function resolveNavLinkItem(linkItem) {
|
||||||
return Object.assign(linkItem, {
|
return Object.assign(linkItem, {
|
||||||
type: linkItem.items && linkItem.items.length ? 'links' : 'link'
|
type: linkItem.items && linkItem.items.length ? 'links' : 'link'
|
||||||
})
|
})
|
||||||
|
|
@ -193,7 +194,7 @@ export function resolveNavLinkItem (linkItem) {
|
||||||
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config
|
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config
|
||||||
* @returns { base: string, config: SidebarConfig }
|
* @returns { base: string, config: SidebarConfig }
|
||||||
*/
|
*/
|
||||||
export function resolveMatchingConfig (regularPath, config) {
|
export function resolveMatchingConfig(regularPath, config) {
|
||||||
if (Array.isArray(config)) {
|
if (Array.isArray(config)) {
|
||||||
return {
|
return {
|
||||||
base: '/',
|
base: '/',
|
||||||
|
|
@ -211,13 +212,13 @@ export function resolveMatchingConfig (regularPath, config) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureEndingSlash (path) {
|
function ensureEndingSlash(path) {
|
||||||
return /(\.html|\/)$/.test(path)
|
return /(\.html|\/)$/.test(path)
|
||||||
? path
|
? path
|
||||||
: path + '/'
|
: path + '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveItem (item, pages, base, groupDepth = 1) {
|
function resolveItem(item, pages, base, groupDepth = 1) {
|
||||||
if (typeof item === 'string') {
|
if (typeof item === 'string') {
|
||||||
return resolvePage(pages, item, base)
|
return resolvePage(pages, item, base)
|
||||||
} else if (Array.isArray(item)) {
|
} else if (Array.isArray(item)) {
|
||||||
|
|
@ -250,13 +251,13 @@ function resolveItem (item, pages, base, groupDepth = 1) {
|
||||||
|
|
||||||
|
|
||||||
// 类型判断
|
// 类型判断
|
||||||
export function type (o) {
|
export function type(o) {
|
||||||
const s = Object.prototype.toString.call(o)
|
const s = Object.prototype.toString.call(o)
|
||||||
return s.match(/\[object (.*?)\]/)[1].toLowerCase()
|
return s.match(/\[object (.*?)\]/)[1].toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日期格式化(只获取年月日)
|
// 日期格式化(只获取年月日)
|
||||||
export function dateFormat (date) {
|
export function dateFormat(date) {
|
||||||
if (!(date instanceof Date)) {
|
if (!(date instanceof Date)) {
|
||||||
date = new Date(date)
|
date = new Date(date)
|
||||||
}
|
}
|
||||||
|
|
@ -264,12 +265,12 @@ export function dateFormat (date) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 小于10补0
|
// 小于10补0
|
||||||
export function zero (d) {
|
export function zero(d) {
|
||||||
return d.toString().padStart(2, '0')
|
return d.toString().padStart(2, '0')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取时间的时间戳
|
// 获取时间的时间戳
|
||||||
export function getTimeNum (post) {
|
export function getTimeNum(post) {
|
||||||
let dateStr = post.frontmatter.date || post.lastUpdated || new Date()
|
let dateStr = post.frontmatter.date || post.lastUpdated || new Date()
|
||||||
let date = new Date(dateStr)
|
let date = new Date(dateStr)
|
||||||
if (date == "Invalid Date" && dateStr) { // 修复new Date()在Safari下出现Invalid Date的问题
|
if (date == "Invalid Date" && dateStr) { // 修复new Date()在Safari下出现Invalid Date的问题
|
||||||
|
|
@ -279,12 +280,12 @@ export function getTimeNum (post) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 比对时间
|
// 比对时间
|
||||||
export function compareDate (a, b) {
|
export function compareDate(a, b) {
|
||||||
return getTimeNum(b) - getTimeNum(a)
|
return getTimeNum(b) - getTimeNum(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将特殊符号编码(应用于url)
|
// 将特殊符号编码(应用于url)
|
||||||
export function encodeUrl (str) {
|
export function encodeUrl(str) {
|
||||||
str = str + ''
|
str = str + ''
|
||||||
str = str.replace(/ |((?=[\x21-\x7e]+)[^A-Za-z0-9])/g, '-')
|
str = str.replace(/ |((?=[\x21-\x7e]+)[^A-Za-z0-9])/g, '-')
|
||||||
return str
|
return str
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue