Browse Source

[doc]更新构建命令以包含TypeScript编译,优化颜色数据处理,增强API文档链接功能。

dufu1991 1 year ago
parent
commit
4aa0715f53

+ 1 - 1
docs/site/package.json

@@ -6,7 +6,7 @@
 		"env": "bun run scripts/env.js",
 		"dev": "bun run env && vite dev",
 		"preview": "vite preview",
-		"build": "bun run env && vite build",
+		"build": "tsc -b && bun run env && vite build",
 		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
 		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
 		"format": "prettier --write .",

+ 7 - 7
docs/site/src/data/color.ts

@@ -2119,12 +2119,11 @@ colors.forEach((item) => {
 	const obj = {
 		name: item[1],
 		hex,
-		rgb: colorConvertFunc(hex).rgb,
-		hsl: colorConvertFunc(hex).hsl,
-		// hslArr: hslFunc(colorConvertFunc(hex).hsl),
-		hsl_h: hslFunc(colorConvertFunc(hex).hsl)?.[0],
-		hsl_s: hslFunc(colorConvertFunc(hex).hsl)?.[1],
-		hsl_l: hslFunc(colorConvertFunc(hex).hsl)?.[2],
+		rgb: colorConvertFunc(hex).rgb.split(','),
+		hsl: colorConvertFunc(hex).hsl.split(','),
+		hsl_h: hslFunc(colorConvertFunc(hex).hsl)?.[0] ?? null,
+		hsl_s: hslFunc(colorConvertFunc(hex).hsl)?.[1] ?? null,
+		hsl_l: hslFunc(colorConvertFunc(hex).hsl)?.[2] ?? null,
 		mode: hslFunc(colorConvertFunc(hex).hsl)?.[2] !== undefined && Number(hslFunc(colorConvertFunc(hex).hsl)?.[2]) > 50 ? 'light' : 'dark'
 	};
 	colorList.push(obj);
@@ -2132,7 +2131,8 @@ colors.forEach((item) => {
 
 // 过滤出 hsl_l 在 20-45 和 55-80 之间的颜色,区分明显
 colorList = colorList.filter((item) => {
-	return (item.hsl_l >= 20 && item.hsl_l < 45) || (item.hsl_l > 55 && item.hsl_l <= 80);
+	const hslL = item.hsl_l ? Number(item.hsl_l) : null;
+	return hslL !== null && ((hslL >= 20 && hslL < 45) || (hslL > 55 && hslL <= 80));
 });
 
 export default colorList;

+ 1 - 1
docs/site/src/routes/components/Api.svelte

@@ -15,7 +15,7 @@
 		const rawObj = await import(`../../../../mds/components/${nav}/api${isZh ? '' : '_en'}.md`);
 		const mdStr = rawObj.default;
 		loading = false;
-		return mdTextToHljs(mdStr.replace(/<a href="/g, '<a target="_blank" href="'));
+		return mdTextToHljs(mdStr.replace(/<a href="/g, '<a target="_blank" href="'), 'javascript');
 	};
 	let apiText: string | null = $state(null);
 	onMount(async () => {

+ 2 - 2
docs/site/src/utils/index.ts

@@ -75,9 +75,9 @@ const replacePart = (str: string, findText: string, replaceText: string) => {
  * @example
  * mdTextToHljs('```js\nconsole.log(123)\n```') // <code class="hljs language-js"><span class="hljs-built_in">console</span>.log(<span class="hljs-number">123</span>)</code>
  */
-export const mdTextToHljs = (mdText: string) => {
+export const mdTextToHljs = (mdText: string, language: string = '') => {
 	// 将所有 <td><code> 标签替换为 <td><code class="hljs language-typescript">
-	mdText = mdText.replace(/<td><code>/g, '<td><code class="hljs language-typescript">');
+	mdText = mdText.replace(/<td><code>/g, `<td><code class="${language ? 'language-' + language : ''}">`);
 	if (mdText.indexOf('<code class="') > 0) {
 		let apiText = mdText.indexOf('<code class="') > 0 ? htmlFilter(mdText).replace(/<code class="/g, '<code class="hljs ') : mdText;
 		const codeTexts = apiText.match(/<code[\s\S]*?<\/code>/g);