@rxdrag/website-lib-core 0.0.130 → 0.0.132

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib-core",
3
- "version": "0.0.130",
3
+ "version": "0.0.132",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -24,8 +24,8 @@
24
24
  "eslint": "^9.39.2",
25
25
  "typescript": "^5",
26
26
  "@rxdrag/eslint-config-custom": "0.2.13",
27
- "@rxdrag/tiptap-preview": "0.0.3",
28
- "@rxdrag/tsconfig": "0.2.1"
27
+ "@rxdrag/tsconfig": "0.2.1",
28
+ "@rxdrag/tiptap-preview": "0.0.3"
29
29
  },
30
30
  "dependencies": {
31
31
  "@iconify/utils": "^3.0.2",
@@ -33,8 +33,8 @@
33
33
  "gsap": "^3.12.7",
34
34
  "hls.js": "^1.6.13",
35
35
  "lodash-es": "^4.17.21",
36
- "@rxdrag/entify-lib": "0.0.24",
37
- "@rxdrag/rxcms-models": "0.3.110"
36
+ "@rxdrag/rxcms-models": "0.3.111",
37
+ "@rxdrag/entify-lib": "0.0.24"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "astro": "^5.16.6",
@@ -1,3 +1,10 @@
1
+ // 判断路径是否为根路径(/ 或 /zh/ 等语言前缀根路径)
2
+ const isRootPath = (path: string): boolean => {
3
+ if (path === "/") return true;
4
+ // 匹配 /xx/ 或 /xx-xx/ 格式的语言前缀根路径
5
+ return /^\/[a-z]{2}(-[a-z]{2})?\/?$/.test(path);
6
+ };
7
+
1
8
  export const initLinks = () => {
2
9
  // 获取当前URL的路径部分(去除域名)
3
10
  const currentPath = window.location.pathname;
@@ -15,11 +22,14 @@ export const initLinks = () => {
15
22
  anchorLink.dataset.activedPath === "true"
16
23
  ? linkUrl?.pathname
17
24
  : anchorLink.dataset.activedPath;
18
- // 检查当前路径是否与链接路径匹配或是其子路径
19
- if (
20
- currentPath === linkPath ||
21
- (linkPath !== "/" && linkPath && currentPath.startsWith(linkPath))
22
- ) {
25
+
26
+ // 根路径使用精确匹配,其他路径使用前缀匹配
27
+ const isRoot = linkPath ? isRootPath(linkPath) : false;
28
+ const isMatch = isRoot
29
+ ? currentPath === linkPath || currentPath === linkPath?.replace(/\/$/, "")
30
+ : currentPath === linkPath || (linkPath && currentPath.startsWith(linkPath));
31
+
32
+ if (isMatch) {
23
33
  anchorLink.classList.add("actived");
24
34
  } else {
25
35
  anchorLink.classList.remove("actived");
@@ -103,6 +103,15 @@ export class Entify implements IEntify {
103
103
  return this.ensureLangAbbr();
104
104
  }
105
105
 
106
+ /**
107
+ * 获取当前语言对象(包含 dir 等完整信息)
108
+ */
109
+ public async getCurrentLang() {
110
+ const langAbbr = this.ensureLangAbbr();
111
+ const langs = await this.getLangs();
112
+ return langs?.find((l) => l.abbr === langAbbr);
113
+ }
114
+
106
115
  /**
107
116
  * 获取当前语言,如果未设置则抛出异常
108
117
  */
@@ -71,6 +71,11 @@ export interface IEntify {
71
71
  */
72
72
  getLang(): string;
73
73
 
74
+ /**
75
+ * 获取当前语言对象(包含 dir 等完整信息)
76
+ */
77
+ getCurrentLang(): Promise<Lang | undefined>;
78
+
74
79
  getBaseLang(): Promise<Lang | undefined>;
75
80
 
76
81
  getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined>;
@@ -9,6 +9,7 @@ export const langFields = [
9
9
  LangFields.localName,
10
10
  LangFields.icon,
11
11
  LangFields.htmlLang,
12
+ LangFields.dir,
12
13
  //TODO 用枚举有时会出空值
13
14
  "urlFragment" as LangFields.urlFragment,
14
15
  ];