Skip to content

Commit

Permalink
fix: v1.10.2 - 修复nav不规范配置时导致浏览器控制台以及build时报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xugaoyi committed Apr 8, 2022
1 parent 2b945d3 commit 3844f83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"vuepress-plugin-one-click-copy": "^1.0.2",
"vuepress-plugin-thirdparty-search": "^1.0.2",
"vuepress-plugin-zooming": "^1.1.7",
"vuepress-theme-vdoing": "^1.10.1",
"vuepress-theme-vdoing": "^1.10.2",
"yamljs": "^0.3.0"
}
}
2 changes: 1 addition & 1 deletion vdoing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuepress-theme-vdoing",
"version": "1.10.1",
"version": "1.10.2",
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
"author": {
"name": "gaoyi(Evan) Xu"
Expand Down
47 changes: 24 additions & 23 deletions vdoing/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ export const extRE = /\.(md|html)$/
export const endingSlashRE = /\/$/
export const outboundRE = /^[a-z]+:/i

export function normalize (path) {
export function normalize(path) {
return decodeURI(path)
.replace(hashRE, '')
.replace(extRE, '')
}

export function getHash (path) {
const match = path.match(hashRE)
export function getHash(path) {
const match = path?.match(hashRE)
if (match) {
return match[0]
}
}

export function isExternal (path) {
export function isExternal(path) {
return outboundRE.test(path)
}

export function isMailto (path) {
export function isMailto(path) {
return /^mailto:/.test(path)
}

export function isTel (path) {
export function isTel(path) {
return /^tel:/.test(path)
}

export function ensureExt (path) {
export function ensureExt(path) {
if (isExternal(path)) {
return path
}
if (!path) return '404'
const hashMatch = path.match(hashRE)
const hash = hashMatch ? hashMatch[0] : ''
const normalized = normalize(path)
Expand All @@ -42,7 +43,7 @@ export function ensureExt (path) {
return normalized + '.html' + hash
}

export function isActive (route, path) {
export function isActive(route, path) {
const routeHash = route.hash
const linkHash = getHash(path)
if (linkHash && routeHash !== linkHash) {
Expand All @@ -53,7 +54,7 @@ export function isActive (route, path) {
return routePath === pagePath
}

export function resolvePage (pages, rawPath, base) {
export function resolvePage(pages, rawPath, base) {
if (isExternal(rawPath)) {
return {
type: 'external',
Expand All @@ -76,7 +77,7 @@ export function resolvePage (pages, rawPath, base) {
return {}
}

function resolvePath (relative, base, append) {
function resolvePath(relative, base, append) {
const firstChar = relative.charAt(0)
if (firstChar === '/') {
return relative
Expand Down Expand Up @@ -121,7 +122,7 @@ function resolvePath (relative, base, append) {
* @param { string } localePath
* @returns { SidebarGroup }
*/
export function resolveSidebarItems (page, regularPath, site, localePath) {
export function resolveSidebarItems(page, regularPath, site, localePath) {
const { pages, themeConfig } = site

const localeConfig = localePath && themeConfig.locales
Expand Down Expand Up @@ -151,7 +152,7 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
* @param { Page } page
* @returns { SidebarGroup }
*/
function resolveHeaders (page) {
function resolveHeaders(page) {
const headers = groupHeaders(page.headers || [])
return [{
type: 'group',
Expand All @@ -168,7 +169,7 @@ function resolveHeaders (page) {
}]
}

export function groupHeaders (headers) {
export function groupHeaders(headers) {
// group h3s under h2
headers = headers.map(h => Object.assign({}, h))
let lastH2
Expand All @@ -182,7 +183,7 @@ export function groupHeaders (headers) {
return headers.filter(h => h.level === 2)
}

export function resolveNavLinkItem (linkItem) {
export function resolveNavLinkItem(linkItem) {
return Object.assign(linkItem, {
type: linkItem.items && linkItem.items.length ? 'links' : 'link'
})
Expand All @@ -193,7 +194,7 @@ export function resolveNavLinkItem (linkItem) {
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config
* @returns { base: string, config: SidebarConfig }
*/
export function resolveMatchingConfig (regularPath, config) {
export function resolveMatchingConfig(regularPath, config) {
if (Array.isArray(config)) {
return {
base: '/',
Expand All @@ -211,13 +212,13 @@ export function resolveMatchingConfig (regularPath, config) {
return {}
}

function ensureEndingSlash (path) {
function ensureEndingSlash(path) {
return /(\.html|\/)$/.test(path)
? path
: path + '/'
}

function resolveItem (item, pages, base, groupDepth = 1) {
function resolveItem(item, pages, base, groupDepth = 1) {
if (typeof item === 'string') {
return resolvePage(pages, item, base)
} else if (Array.isArray(item)) {
Expand Down Expand Up @@ -250,26 +251,26 @@ function resolveItem (item, pages, base, groupDepth = 1) {


// 类型判断
export function type (o) {
export function type(o) {
const s = Object.prototype.toString.call(o)
return s.match(/\[object (.*?)\]/)[1].toLowerCase()
}

// 日期格式化(只获取年月日)
export function dateFormat (date) {
export function dateFormat(date) {
if (!(date instanceof Date)) {
date = new Date(date)
}
return `${date.getUTCFullYear()}-${zero(date.getUTCMonth() + 1)}-${zero(date.getUTCDate())}`
}

// 小于10补0
export function zero (d) {
export function zero(d) {
return d.toString().padStart(2, '0')
}

// 获取时间的时间戳
export function getTimeNum (post) {
export function getTimeNum(post) {
let dateStr = post.frontmatter.date || post.lastUpdated || new Date()
let date = new Date(dateStr)
if (date == "Invalid Date" && dateStr) { // 修复new Date()在Safari下出现Invalid Date的问题
Expand All @@ -279,12 +280,12 @@ export function getTimeNum (post) {
}

// 比对时间
export function compareDate (a, b) {
export function compareDate(a, b) {
return getTimeNum(b) - getTimeNum(a)
}

// 将特殊符号编码(应用于url)
export function encodeUrl (str) {
export function encodeUrl(str) {
str = str + ''
str = str.replace(/ |((?=[\x21-\x7e]+)[^A-Za-z0-9])/g, '-')
return str
Expand Down

1 comment on commit 3844f83

@vercel
Copy link

@vercel vercel bot commented on 3844f83 Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.