@salesforcedevs/dw-components 1.17.6 → 1.17.8

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": "@salesforcedevs/dw-components",
3
- "version": "1.17.6",
3
+ "version": "1.17.8",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -26,5 +26,5 @@
26
26
  "@types/setimmediate": "1.0.4",
27
27
  "setimmediate": "1.0.5"
28
28
  },
29
- "gitHead": "a3108bb2342f34377f5ec64b2bd0cb0c67c2c506"
29
+ "gitHead": "d54bfc720c13ba1a7991da4b1cdef9aa9f66a5d4"
30
30
  }
@@ -6,6 +6,7 @@ import uniqBy from "lodash.uniqby";
6
6
  import orderBy from "lodash.orderby";
7
7
  import { isGivenLanguageSupported } from "dxUtils/language";
8
8
  import { track } from "dxUtils/analytics";
9
+ import { escapeRegExp } from "dxUtils/regexps";
9
10
 
10
11
  const DSC_API_URL = {
11
12
  "en-us": "/docs/get_index/en-us/000.0/false/All%20Services/all",
@@ -476,7 +477,9 @@ export default class DocsGrid extends LightningElement {
476
477
  }
477
478
 
478
479
  findWithRegex(baseString: string, searchWord: string) {
479
- const regex = new RegExp(searchWord.replace(/\s/, ".*"));
480
+ // Escape special regex characters to prevent invalid regex patterns
481
+ const escapedSearchWord = escapeRegExp(searchWord);
482
+ const regex = new RegExp(escapedSearchWord.replace(/\s/, ".*"));
480
483
  return !!baseString.match(regex);
481
484
  }
482
485
 
@@ -11,6 +11,12 @@ const language_local_names_map: any = {
11
11
  japanese: "日本語",
12
12
  english: "English"
13
13
  };
14
+
15
+ const language_codes_map: any = {
16
+ japanese: "ja",
17
+ english: "en"
18
+ };
19
+
14
20
  const DEFAULT = language_local_names_map.english;
15
21
 
16
22
  interface ACF {
@@ -55,10 +61,26 @@ export default class LanguageSelector extends LightningElement {
55
61
  )
56
62
  ).json();
57
63
 
64
+ // Remove existing hreflang links to avoid duplicates
65
+ const existingLinks = document.querySelectorAll("link[hreflang]");
66
+ existingLinks.forEach((link) => link.remove());
67
+
58
68
  Object.values(alternatePosts).forEach((post: Post) => {
59
69
  const localLanguageName =
60
70
  this.getLanguageOrDefaultIfInvalid(post);
61
- this._languageMap[localLanguageName] = normalizePostLink(post);
71
+ const url = normalizePostLink(post);
72
+ this._languageMap[localLanguageName] = url;
73
+
74
+ // Add hreflang link for this language
75
+ const languageCode =
76
+ language_codes_map[post.acf.language || "english"];
77
+ if (languageCode && url) {
78
+ const link = document.createElement("link");
79
+ link.rel = "alternate";
80
+ link.hreflang = languageCode;
81
+ link.href = url;
82
+ document.head.appendChild(link);
83
+ }
62
84
  });
63
85
 
64
86
  this.languages = Object.values(alternatePosts).map((post) => {