From 3844f83f6dd3fbc3abae28676a7c57cd212ea363 Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Fri, 8 Apr 2022 16:48:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20v1.10.2=20-=20=E4=BF=AE=E5=A4=8Dnav?= =?UTF-8?q?=E4=B8=8D=E8=A7=84=E8=8C=83=E9=85=8D=E7=BD=AE=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=B5=8F=E8=A7=88=E5=99=A8=E6=8E=A7=E5=88=B6=E5=8F=B0?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Abuild=E6=97=B6=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- vdoing/package.json | 2 +- vdoing/util/index.js | 47 ++++++++++++++++++++++---------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 1f9855a45d..1277be4335 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/vdoing/package.json b/vdoing/package.json index e350890e82..8e20471e6c 100644 --- a/vdoing/package.json +++ b/vdoing/package.json @@ -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" diff --git a/vdoing/util/index.js b/vdoing/util/index.js index 168225e376..e5ba52bb48 100644 --- a/vdoing/util/index.js +++ b/vdoing/util/index.js @@ -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) @@ -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) { @@ -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', @@ -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 @@ -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 @@ -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', @@ -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 @@ -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' }) @@ -193,7 +194,7 @@ export function resolveNavLinkItem (linkItem) { * @param { Array | Array | [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: '/', @@ -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)) { @@ -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) return s.match(/\[object (.*?)\]/)[1].toLowerCase() } // 日期格式化(只获取年月日) -export function dateFormat (date) { +export function dateFormat(date) { if (!(date instanceof Date)) { date = new Date(date) } @@ -264,12 +265,12 @@ export function dateFormat (date) { } // 小于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的问题 @@ -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