diff --git a/package.json b/package.json index a410080..5dc8cd5 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "docs:dev": "vitepress dev docs", "docs:build": "vitepress build docs", "docs:preview": "vitepress preview docs", - "demo:dev": "vitepress dev demo", + "demo:dev": "vitepress dev demo --host", "demo:build": "vitepress build demo", "demo:preview": "vitepress preview demo", "lint": "eslint --cache --max-warnings 0 \"**/*.{js,jsx,vue,ts,tsx}\" --fix", diff --git a/packages/vitepress-theme-async/blog.ts b/packages/vitepress-theme-async/blog.ts index 1a28614..22e8175 100644 --- a/packages/vitepress-theme-async/blog.ts +++ b/packages/vitepress-theme-async/blog.ts @@ -2,14 +2,13 @@ import { useData, useRoute, useRouter, withBase } from 'vitepress'; import { Component, defineComponent, Ref, h, inject, onMounted, provide, ref, nextTick, onUnmounted, WatchStopHandle, watch } from 'vue'; import failure from './assets/failure.ico'; import errimg from './assets/404.jpg'; -import { dataPath, stringFormat } from './utils/shared'; +import pkg from './package.json'; +import { dataPath, stringFormat, log } from './utils/shared'; import { initClipboard, initPictures, initPostErrorImg, initScrollAnimation, initVisibilitychange } from './utils/client'; import { getMitt } from './composables/mitt'; -// export const AsyncCurrentPageIndexSymbol: InjectionKey> = Symbol('current-page-index'); // export const AsyncShowMenuSymbol: InjectionKey> = Symbol('show-menu'); -export const useCurrentPageIndex = () => inject>('AsyncCurrentPageIndexSymbol')!; export const useShowMenu = () => inject>('AsyncShowMenuSymbol')!; export const useLang = () => inject>('AsyncLanguageSymbol')!; export const useCurrentLang = () => { @@ -35,14 +34,13 @@ export function withConfigProvider(App: Component) { const router = useRouter(); const route = useRoute(); const mitt = getMitt(); - const currentPageIndex = ref(1); + const showMenu = ref(false); const language = ref(site.value.lang ?? 'zh-Hans'); let watcher: WatchStopHandle; // fix: 通过 npm 安装, 在 dev 模式时 vue 会提示 injection "Symbol(current-page-index)" not found. // 未找到具体原因 暂时用字符替代 - provide('AsyncCurrentPageIndexSymbol', currentPageIndex); provide('AsyncShowMenuSymbol', showMenu); provide('AsyncLanguageSymbol', language); @@ -73,6 +71,8 @@ export function withConfigProvider(App: Component) { }; onMounted(() => { + log(`%c 🚀 Vitepress-Theme-Async ${pkg.version == '0.0.0' ? 'Github' : pkg.version} %c https://github.com/MaLuns/hexo-theme-async `); + log(`%c 📑 Vitepress-Theme-Async Docs %c ${pkg.homepage}`); mitt.on('page:update', initPageUpdate); if (theme.value.pageLoading) { diff --git a/packages/vitepress-theme-async/utils/shared.ts b/packages/vitepress-theme-async/utils/shared.ts index 7a1a403..624a49a 100644 --- a/packages/vitepress-theme-async/utils/shared.ts +++ b/packages/vitepress-theme-async/utils/shared.ts @@ -356,6 +356,17 @@ export const formatDate = (d: Date | number | string | undefined, fmt: string = */ export const isEmpty = (val: any) => val == null || !(Object.keys(val) || val).length; +/** + * 日志打印 + * @param str + * @returns + */ +export const log = (str: string) => + console.log( + str, + 'color: white; background: #0078E7; padding:5px 0;margin: 0 0 2px 0;border-radius: 4px 0 0 4px;', + 'padding: 4px;border:1px solid #0078E7;border-radius: 0 4px 4px 0; background: linear-gradient(70deg, #e3f9eb, #d1dbff);', + ); /** * 获取语言配置文本 * @param langData