From 7f8f169e7160a46c894bc6f8cea982d9b2775a47 Mon Sep 17 00:00:00 2001 From: chengpeiquan Date: Mon, 5 Dec 2022 16:21:29 +0800 Subject: [PATCH] chore: typo --- .vitepress/theme/index.ts | 3 - .vitepress/theme/plugins/analytics.ts | 15 +-- .vitepress/theme/plugins/redirect.ts | 17 +--- .vitepress/theme/plugins/symbol.ts | 127 -------------------------- 4 files changed, 3 insertions(+), 159 deletions(-) delete mode 100644 .vitepress/theme/plugins/symbol.ts diff --git a/.vitepress/theme/index.ts b/.vitepress/theme/index.ts index a3b47cd..694812b 100644 --- a/.vitepress/theme/index.ts +++ b/.vitepress/theme/index.ts @@ -1,7 +1,6 @@ import { inBrowser } from 'vitepress' import DefaultTheme from 'vitepress/theme' import { changeLocales } from './plugins/locales' -import { setSymbolStyle, replaceSymbol } from './plugins/symbol' import { siteIds, registerAnalytics, trackPageview } from './plugins/analytics' import { isInvalidRoute, redirect } from './plugins/redirect' import './styles/custom.css' @@ -15,7 +14,6 @@ const theme: Theme = { redirect() } - setSymbolStyle() siteIds.forEach((id) => registerAnalytics(id)) window.addEventListener('load', () => { @@ -29,7 +27,6 @@ const theme: Theme = { router.onAfterRouteChanged = (to) => { changeLocales() - replaceSymbol() siteIds.forEach((id) => trackPageview(id, to)) } } diff --git a/.vitepress/theme/plugins/analytics.ts b/.vitepress/theme/plugins/analytics.ts index c33dcc0..636cd27 100644 --- a/.vitepress/theme/plugins/analytics.ts +++ b/.vitepress/theme/plugins/analytics.ts @@ -1,16 +1,10 @@ import { inBrowser } from 'vitepress' -/** - * 统计站点的 ID 列表 - */ export const siteIds = [ - 'd6895b6f22616e579e9e6d37936b8dca', // 主站 - '025e7d9acbc7359afa71bdae5aa03f33', // 本站 + 'd6895b6f22616e579e9e6d37936b8dca', // Cropper + '8dca8e2532df48ea7f1b15c714588691', // Blog ] -/** - * 注册统计 - */ export function registerAnalytics(siteId: string) { if (!inBrowser) return if (document.querySelector(`#analytics-plugin-${siteId}`)) return @@ -23,11 +17,6 @@ export function registerAnalytics(siteId: string) { document.querySelector('head')?.appendChild(script) } -/** - * 上报 PV 数据 - * @param siteId - 站点 ID - * @param pageUrl - 页面 URL - */ export function trackPageview(siteId: string, pageUrl: string) { if (!inBrowser) return if (!pageUrl || typeof pageUrl !== 'string') { diff --git a/.vitepress/theme/plugins/redirect.ts b/.vitepress/theme/plugins/redirect.ts index 124fece..75be622 100644 --- a/.vitepress/theme/plugins/redirect.ts +++ b/.vitepress/theme/plugins/redirect.ts @@ -1,15 +1,9 @@ import { inBrowser } from 'vitepress' -/** - * 重定向的 Map 表 - */ export const redirectMap = { - update: 'upgrade', + // update: 'upgrade', } -/** - * 根据页面 URL 提取路由名称 - */ export function getRouteName() { if (!inBrowser) return '' const { pathname } = window.location @@ -17,9 +11,6 @@ export function getRouteName() { return routeName } -/** - * 判断是否无效路由 - */ export function isInvalidRoute() { if (!inBrowser) return false const routeName = getRouteName() @@ -27,18 +18,12 @@ export function isInvalidRoute() { return keys.includes(routeName) } -/** - * 获取重定向目标 - */ export function redirectTarget() { if (!inBrowser) return '/' const routeName = getRouteName() return `/${redirectMap[routeName]}.html` || '/' } -/** - * 重定向 - */ export function redirect() { if (!inBrowser) return window.location.replace(redirectTarget()) diff --git a/.vitepress/theme/plugins/symbol.ts b/.vitepress/theme/plugins/symbol.ts deleted file mode 100644 index 9467502..0000000 --- a/.vitepress/theme/plugins/symbol.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { inBrowser } from 'vitepress' - -interface Config { - hot: string - new: string -} - -// 标记 -const markConfig: Config = { - hot: ' ~hot', - new: ' ~new', -} - -// 图标 -const iconConfig: Config = { - hot: '', - new: '', -} - -/** - * 设置图标样式 - */ -export function setSymbolStyle() { - if (!inBrowser) return - try { - const ID = 'symbol-plugin' - if (document.querySelector(`#${ID}`)) return - - const CSS = ` - .sidebar__icon--default { - position: relative; - display: inline-block; - width: 18px; - height: 18px; - color: #fff; - font-size: 13px; - font-weight: bold; - font-style: normal; - vertical-align: middle; - margin: 0 5px; - transform: scale(0.7) rotate(30deg); - } - .sidebar__icon--default:before { - position: absolute; - top: 0; - left: 0; - width: 18px; - height: 18px; - line-height: 18px; - text-align: center; - transform: rotate(135deg); - } - .sidebar__icon--hot { - background-color: #da5961; - } - .sidebar__icon--hot:before { - content: "H"; - background-color: #da5961; - } - .sidebar__icon--new { - background-color: #3eaf7c; - } - .sidebar__icon--new:before { - content: "N"; - background-color: #3eaf7c; - } - ` - - const style = document.createElement('style') - style.id = ID - style.appendChild(document.createTextNode(CSS)) - document.head.appendChild(style) - } catch (e) { - console.log(e) - } -} - -/** - * 执行标记替换 - */ -export function replaceSymbol() { - if (!inBrowser) return - setTimeout(() => { - try { - // 获取 DOM - const sidebarLinks = - document.querySelectorAll('.aside-container nav .outline-link') || [] - const h2s = document.querySelectorAll('.content-container h2') || [] - const h3s = document.querySelectorAll('.content-container h3') || [] - const h4s = document.querySelectorAll('.content-container h4') || [] - const doms = [...sidebarLinks, ...h2s, ...h3s, ...h4s] - - // 替换标记成图标 - doms.forEach((item) => { - let html = item.innerHTML - - for (const key in markConfig) { - if (Object.hasOwnProperty.call(markConfig, key)) { - const mark = markConfig[key] - const icon = iconConfig[key] - const reg = new RegExp(mark, 'img') - - // 只处理包含标记的元素 - if (html.includes(mark)) { - // 部分元素不显示图标 - const { nodeName } = item - switch (nodeName) { - case 'H2': - case 'H3': - case 'H4': - html = html.replace(reg, '') - break - default: - html = html.replace(reg, icon) - } - - // 渲染 - item.innerHTML = html - } - } - } - }) - } catch (e) { - console.log(e) - } - }, 100) -}