diff --git a/docs/.vuepress/client.ts b/docs/.vuepress/client.ts new file mode 100644 index 00000000..a3f515cf --- /dev/null +++ b/docs/.vuepress/client.ts @@ -0,0 +1,10 @@ +import { type ClientConfig, defineClientConfig } from 'vuepress/client' +import HeroTintPlateConfig from './themes/components/HeroTintPlateConfig.vue' +import CanIUseConfig from './themes/components/CanIUseConfig.vue' + +export default defineClientConfig({ + enhance({ app }) { + app.component('HeroTintPlateConfig', HeroTintPlateConfig) + app.component('CanIUseConfig', CanIUseConfig) + }, +}) as ClientConfig diff --git a/docs/.vuepress/themes/components/CanIUseConfig.vue b/docs/.vuepress/themes/components/CanIUseConfig.vue new file mode 100644 index 00000000..8c9e8b4f --- /dev/null +++ b/docs/.vuepress/themes/components/CanIUseConfig.vue @@ -0,0 +1,267 @@ + + + + + diff --git a/docs/.vuepress/themes/composables/caniuse.ts b/docs/.vuepress/themes/composables/caniuse.ts new file mode 100644 index 00000000..9ac85d3f --- /dev/null +++ b/docs/.vuepress/themes/composables/caniuse.ts @@ -0,0 +1,46 @@ +export function resolveCanIUse(feature: string, mode: string, versions: string): string { + if (!feature) + return '' + + if (mode === 'image') { + const link = 'https://caniuse.bitsofco.de/image/' + const alt = `Data on support for the ${feature} feature across the major browsers from caniuse.com` + return `

+ + + ${alt} +

` + } + + const periods = resolveVersions(versions) + const accessible = 'false' + const image = 'none' + const url = 'https://caniuse.bitsofco.de/embed/index.html' + const src = `${url}?feat=${feature}&periods=${periods}&accessible-colours=${accessible}&image-base=${image}` + + return `
` +} + +function resolveVersions(versions: string): string { + if (!versions) + return 'future_1,current,past_1,past_2' + + const list = versions + .split(',') + .map(v => Number(v.trim())) + .filter(v => !Number.isNaN(v) && v >= -5 && v <= 3) + + list.push(0) + + const uniq = [...new Set(list)].sort((a, b) => b - a) + const result: string[] = [] + uniq.forEach((v) => { + if (v < 0) + result.push(`past_${Math.abs(v)}`) + if (v === 0) + result.push('current') + if (v > 0) + result.push(`future_${v}`) + }) + return result.join(',') +} diff --git a/docs/notes/tools/README.md b/docs/notes/tools/README.md new file mode 100644 index 00000000..ca92add8 --- /dev/null +++ b/docs/notes/tools/README.md @@ -0,0 +1,15 @@ +--- +title: 主题工具包 +author: pengzhanbo +createTime: 2024/04/16 16:27:03 +permalink: /tools/ +--- + +## 概述 + +主题工具包 旨在帮助用户在使用本主题提供的一些功能时,降低其使用门槛。 + +## 工具列表 + +- [caniuse 特性搜索](./caniuse.md) +- [首页背景色板配置](./home-hero-tint-plate.md) diff --git a/docs/notes/tools/caniuse.md b/docs/notes/tools/caniuse.md new file mode 100644 index 00000000..e9ec65ee --- /dev/null +++ b/docs/notes/tools/caniuse.md @@ -0,0 +1,15 @@ +--- +title: caniuse 特性搜索 +author: pengzhanbo +icon: fa-brands:css3 +createTime: 2024/04/16 12:41:26 +permalink: /tools/caniuse/ +readingTime: false +editLink: false +contributors: false +lastUpdated: false +--- + +本工具用于帮助搜索 caniuse 中的特性。并生成 caniuse markdown 代码。 + +