Skip to content

Commit

Permalink
✨ feat: 控制台打印主题信息
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Nov 18, 2024
1 parent a8e95c6 commit 87676d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/vitepress-theme-async/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ref<number>> = Symbol('current-page-index');
// export const AsyncShowMenuSymbol: InjectionKey<Ref<boolean>> = Symbol('show-menu');

export const useCurrentPageIndex = () => inject<Ref<number>>('AsyncCurrentPageIndexSymbol')!;
export const useShowMenu = () => inject<Ref<boolean>>('AsyncShowMenuSymbol')!;
export const useLang = () => inject<Ref<string>>('AsyncLanguageSymbol')!;
export const useCurrentLang = () => {
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions packages/vitepress-theme-async/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87676d3

Please sign in to comment.