diff --git a/components/EasyScrollBar.vue b/components/EasyScrollBar.vue new file mode 100644 index 0000000..826d304 --- /dev/null +++ b/components/EasyScrollBar.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/components/TechStackCard.vue b/components/TechStackCard.vue index cfdb918..d0a830c 100644 --- a/components/TechStackCard.vue +++ b/components/TechStackCard.vue @@ -5,8 +5,6 @@ import { DataAnomaly } from '~/types/PostMetaData'; import 'overlayscrollbars/overlayscrollbars.css'; import useColorModeStore from '~/stores/colorModeStore'; import useIconStore from '~/stores/iconStore'; -import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue'; -import type { OverflowBehavior, ScrollbarsAutoHideBehavior, ScrollbarsVisibilityBehavior } from 'overlayscrollbars'; const props = withDefaults(defineProps<{ asyncKey: string; @@ -26,7 +24,7 @@ const techStackLightIconSVG = ref([]); const techStackDarkIconSVG = ref([]); const { colorMode } = storeToRefs(useColorModeStore()); -// 没有这个asyncKey会加载不出正确的图标 +// 没有这个 asyncKey 会加载不出正确的图标 const { pending } = useAsyncData(props.asyncKey, async () => { if (props.techStackIconNames === DataAnomaly.DataNotFound || props.techStackIconNames === DataAnomaly.Invalid) return []; @@ -64,7 +62,7 @@ const renderChart = () => { chart: { type: 'bar', backgroundColor: 'transparent', - reflow: false, + reflow: true, }, credits: { enabled: false, @@ -165,21 +163,6 @@ onUnmounted(() => { useColorModeStore().unregisterCallBack(colorModeCallBackKey); }); -const scrollbarOptions = { - scrollbars: { - theme: 'os-theme-thin-dark', - visibility: 'auto' as ScrollbarsVisibilityBehavior, - autoHide: 'move' as ScrollbarsAutoHideBehavior, - autoHideDelay: 1300, - dragScroll: true, - clickScroll: true, - }, - overflow: { - x: 'hidden' as OverflowBehavior, - y: 'scroll' as OverflowBehavior, - }, -}; - const mounted = ref(false); onMounted(() => { mounted.value = true; @@ -221,29 +204,8 @@ onMounted(() => { - +
- +
- - diff --git a/nuxt.config.ts b/nuxt.config.ts index cbd28dd..1d809b9 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -33,6 +33,17 @@ export default defineNuxtConfig({ script: [{ src: '/darkVerify.js' }], }, }, + icon: { + provider: 'server', + serverBundle: 'local', + + fallbackToApi: true, + + clientBundle: { + scan: true, + icons: [], + }, + }, // sourcemap: { // server: true, // client: true, diff --git a/pages/index/components/ArticleCard.vue b/pages/index/components/ArticleCard.vue index f2d1d05..46b33d3 100644 --- a/pages/index/components/ArticleCard.vue +++ b/pages/index/components/ArticleCard.vue @@ -2,7 +2,6 @@ import { DataAnomaly, defaultMetaData } from '~/types/PostMetaData'; import type { PostMetaData } from '~/types/PostMetaData'; -import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue'; withDefaults(defineProps<{ metaData?: PostMetaData; @@ -95,9 +94,9 @@ onMounted(() => {
- + {{ metaData?.description }} - +
diff --git a/stores/iconStore.ts b/stores/iconStore.ts index a49caf7..9d39af8 100644 --- a/stores/iconStore.ts +++ b/stores/iconStore.ts @@ -1,3 +1,7 @@ +import { loadIcon } from '@iconify/vue'; +import { iconToHTML, iconToSVG, replaceIDs } from '@iconify/utils'; + +// call await set first, then call getIcon or getColoredIcon const useIconStore = defineStore('icon', { state: () => ({ iconCache: new Map(), @@ -30,40 +34,28 @@ const useIconStore = defineStore('icon', { }); } this.addingSet.add(iconName); - if (iconData === undefined || iconData === null || iconData === '') { - this.iconCache.set(iconName, await fetchSvg(iconName)); - } else - this.iconCache.set(iconName, iconData as string); + if (!iconData) { + try { + const data = await loadIcon(iconName); + const { body, attributes } = iconToSVG(data, { + width: '100%', + height: '100%', + }); + + iconData = iconToHTML(replaceIDs(body), attributes); + } catch (e) { + console.error(e); + iconData = ''; + } + } + if (iconData) { + this.iconCache.set(iconName, iconData); + } this.addingSet.delete(iconName); this.waitingCallbackFunctions.get(iconName)?.forEach((callback) => callback()); this.waitingCallbackFunctions.delete(iconName); }, - }, }); + export default useIconStore; - -export async function fetchSvg(svgName: string, maxRetries = 3) { - const iconifyUrl = 'https://api.iconify.design/'; - - for (let attempt = 1; attempt <= maxRetries; attempt++) { - try { - return await (await $fetch(iconifyUrl + svgName + '.svg', { - method: 'GET', - params: { - width: '100%', - }, - })).text(); - } catch (error) { - console.warn(`Attempt ${attempt} failed for ${svgName}:`, error); - - if (attempt === maxRetries) { - console.error(`All ${maxRetries} attempts failed for ${svgName}`); - } - - // 等待一段时间后重试(可选) - await new Promise((resolve) => setTimeout(resolve, 1000 * attempt)); - } - } - return ''; -}