@coffic/cosy-ui 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import { logger } from './logger';
2
+
1
3
  /**
2
4
  * 判断当前路径是否匹配目标路径
3
5
  * @param currentPath 当前路径
@@ -5,36 +7,49 @@
5
7
  * @returns 是否匹配
6
8
  */
7
9
  export function isPathMatch(currentPath: string, targetPath: string): boolean {
8
- // 标准化路径,移除最后的斜杠
9
- const normalizedCurrentPath = currentPath.endsWith('/')
10
- ? currentPath.slice(0, -1)
11
- : currentPath;
12
-
13
- const normalizedTargetPath = targetPath.endsWith('/')
14
- ? targetPath.slice(0, -1)
15
- : targetPath;
16
-
17
- // 直接比较完整路径
18
- if (normalizedCurrentPath === normalizedTargetPath) {
19
- return true;
20
- }
21
-
22
- // 提取不带基础路径的部分进行比较
23
- // 例如把 /cosy-ui/zh-cn/components/button 中提取 /zh-cn/components/button
24
- const currentPathSegments = normalizedCurrentPath.split('/').filter(Boolean);
25
- const targetPathSegments = normalizedTargetPath.split('/').filter(Boolean);
26
-
27
- // 如果目标路径长度大于当前路径,不可能匹配
28
- if (targetPathSegments.length > currentPathSegments.length) {
29
- return false;
30
- }
31
-
32
- // 从后向前比较路径段
33
- for (let i = 1; i <= targetPathSegments.length; i++) {
34
- if (currentPathSegments[currentPathSegments.length - i] !== targetPathSegments[targetPathSegments.length - i]) {
35
- return false;
36
- }
37
- }
38
-
39
- return true;
40
- }
10
+ const debug = false;
11
+
12
+ if (debug) {
13
+ logger.info(`判断 ${currentPath} 是否匹配 ${targetPath}`);
14
+ }
15
+
16
+ // 如果完全匹配,直接返回
17
+ if (currentPath === targetPath) {
18
+ if (debug) {
19
+ logger.info(`${currentPath} 完全匹配 ${targetPath}`);
20
+ }
21
+ return true;
22
+ }
23
+
24
+ // 标准化路径,移除最后的斜杠
25
+ const normalizedCurrentPath = currentPath.endsWith('/') ? currentPath.slice(0, -1) : currentPath;
26
+
27
+ const normalizedTargetPath = targetPath.endsWith('/') ? targetPath.slice(0, -1) : targetPath;
28
+
29
+ // 直接比较完整路径
30
+ if (normalizedCurrentPath === normalizedTargetPath) {
31
+ return true;
32
+ }
33
+
34
+ // 提取不带基础路径的部分进行比较
35
+ // 例如把 /cosy-ui/zh-cn/components/button 中提取 /zh-cn/components/button
36
+ const currentPathSegments = normalizedCurrentPath.split('/').filter(Boolean);
37
+ const targetPathSegments = normalizedTargetPath.split('/').filter(Boolean);
38
+
39
+ // 如果目标路径长度大于当前路径,不可能匹配
40
+ if (targetPathSegments.length > currentPathSegments.length) {
41
+ return false;
42
+ }
43
+
44
+ // 从后向前比较路径段
45
+ for (let i = 1; i <= targetPathSegments.length; i++) {
46
+ if (
47
+ currentPathSegments[currentPathSegments.length - i] !==
48
+ targetPathSegments[targetPathSegments.length - i]
49
+ ) {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ return true;
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffic/cosy-ui",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "An astro component library",
5
5
  "author": {
6
6
  "name": "nookery",
@@ -24,7 +24,8 @@
24
24
  "sideEffects": false,
25
25
  "main": "./dist/index.js",
26
26
  "exports": {
27
- ".": "./dist/index.js"
27
+ ".": "./dist/index.js",
28
+ "./collection": "./dist/collection.js"
28
29
  },
29
30
  "files": [
30
31
  "dist",
@@ -1,19 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
- import { glob } from 'astro/loaders';
3
-
4
- export const makeArticleCollection = (base: string) => {
5
- return defineCollection({
6
- loader: glob({
7
- pattern: '**/*.{md,mdx}',
8
- base,
9
- }),
10
- schema: articleSchema,
11
- });
12
- };
13
-
14
- export const articleSchema = z.object({
15
- title: z.string(),
16
- folder: z.boolean(),
17
- order: z.number(),
18
- description: z.string().optional(),
19
- });
@@ -1,28 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
- import { glob } from 'astro/loaders';
3
-
4
- export const blogSchema = z.object({
5
- title: z.string(),
6
- description: z.string().optional(),
7
- tags: z.array(z.string()).optional(),
8
- date: z.date().optional(),
9
- authors: z
10
- .array(
11
- z.object({
12
- name: z.string(),
13
- picture: z.string().optional(),
14
- url: z.string().optional(),
15
- })
16
- )
17
- .optional(),
18
- });
19
-
20
- export const makeBlogCollection = (base: string) => {
21
- return defineCollection({
22
- loader: glob({
23
- pattern: '**/*.{md,mdx}',
24
- base,
25
- }),
26
- schema: blogSchema,
27
- });
28
- };
@@ -1,11 +0,0 @@
1
- import { glob } from 'astro/loaders';
2
- import { defineCollection } from 'astro:content';
3
-
4
- export const makeCourseCollection = (base: string) => {
5
- return defineCollection({
6
- loader: glob({
7
- pattern: '**/*.{md,mdx}',
8
- base,
9
- }),
10
- });
11
- };
@@ -1,18 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
- import { glob } from 'astro/loaders';
3
-
4
- export const experimentSchema = z.object({
5
- title: z.string(),
6
- description: z.string().optional(),
7
- pubDate: z.date().optional(),
8
- });
9
-
10
- export const makeExperimentCollection = (base: string) => {
11
- return defineCollection({
12
- loader: glob({
13
- pattern: '**/*.{md,mdx}',
14
- base,
15
- }),
16
- schema: experimentSchema,
17
- });
18
- };
@@ -1,25 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
- import { glob } from 'astro/loaders';
3
-
4
- export const lessonSchema = z.object({
5
- title: z.string(),
6
- description: z.string().optional(),
7
- authors: z
8
- .array(
9
- z.object({
10
- name: z.string(),
11
- picture: z.string().optional(),
12
- })
13
- )
14
- .optional(),
15
- });
16
-
17
- export const makeLessonCollection = (base: string) => {
18
- return defineCollection({
19
- loader: glob({
20
- pattern: '**/*.{md,mdx}',
21
- base,
22
- }),
23
- schema: lessonSchema,
24
- });
25
- };
@@ -1,17 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
- import { glob } from 'astro/loaders';
3
-
4
- export const metaSchema = z.object({
5
- title: z.string(),
6
- description: z.string().optional(),
7
- });
8
-
9
- export const makeMetaCollection = (base: string) => {
10
- return defineCollection({
11
- loader: glob({
12
- pattern: '**/*.{md,mdx}',
13
- base,
14
- }),
15
- schema: metaSchema,
16
- });
17
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * 表示文档中的标题结构
3
- */
4
- export interface Heading {
5
- /** 标题深度,如 h1=1, h2=2, h3=3 等 */
6
- depth: number;
7
-
8
- /** 标题的唯一标识符,用于锚点链接 */
9
- slug: string;
10
-
11
- /** 标题文本内容 */
12
- text: string;
13
- }