From cdcade404bc25806e9c83ffea163fbe52a42a36b Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Wed, 17 Apr 2024 12:16:51 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20`caniuse`=20?= =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E9=85=8D=E7=BD=AE=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vuepress/client.ts | 10 + .../themes/components/CanIUseConfig.vue | 267 ++++++++++++++++++ docs/.vuepress/themes/composables/caniuse.ts | 46 +++ docs/notes/tools/README.md | 15 + docs/notes/tools/caniuse.md | 15 + 5 files changed, 353 insertions(+) create mode 100644 docs/.vuepress/client.ts create mode 100644 docs/.vuepress/themes/components/CanIUseConfig.vue create mode 100644 docs/.vuepress/themes/composables/caniuse.ts create mode 100644 docs/notes/tools/README.md create mode 100644 docs/notes/tools/caniuse.md 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 代码。 + +