@tsdoctor/seo 0.4.1 → 0.4.3

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.
Files changed (2) hide show
  1. package/Canonical.js +14 -2
  2. package/package.json +5 -5
package/Canonical.js CHANGED
@@ -76,9 +76,9 @@ function resolveUrl(siteUrl, url) {
76
76
  * @public
77
77
  */
78
78
  function deriveSiteUrl(siteOrigin, base) {
79
- const origin = (siteOrigin ?? "").trim().replace(/\/+$/, "");
79
+ const origin = trimSlashesEnd((siteOrigin ?? "").trim());
80
80
  const path = (base ?? "/").trim();
81
- return `${origin}${path === "" || path === "/" ? "" : `/${path.replace(/^\/+/, "").replace(/\/+$/, "")}`}`;
81
+ return `${origin}${path === "" || path === "/" ? "" : `/${trimSlashesEnd(trimSlashesStart(path))}`}`;
82
82
  }
83
83
  /**
84
84
  * The canonical URL for a page.
@@ -94,6 +94,18 @@ function deriveSiteUrl(siteOrigin, base) {
94
94
  function canonicalUrl(siteUrl, pageRoute) {
95
95
  return `${siteUrl.endsWith("/") ? siteUrl.slice(0, -1) : siteUrl}${pageRoute}`;
96
96
  }
97
+ /** Strip leading `/` characters with a linear scan rather than a backtracking regex. */
98
+ function trimSlashesStart(text) {
99
+ let start = 0;
100
+ while (start < text.length && text[start] === "/") start++;
101
+ return text.slice(start);
102
+ }
103
+ /** Strip trailing `/` characters with a linear scan rather than a backtracking regex. */
104
+ function trimSlashesEnd(text) {
105
+ let end = text.length;
106
+ while (end > 0 && text[end - 1] === "/") end--;
107
+ return text.slice(0, end);
108
+ }
97
109
 
98
110
  //#endregion
99
111
  export { canonicalUrl, deriveSiteUrl, imageMimeType, resolveUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsdoctor/seo",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "private": false,
5
5
  "description": "Framework-neutral head metadata for static TypeScript API documentation: schema.org JSON-LD, Open Graph and Twitter card vocabulary, canonical URLs, and package attribution derived from an api.json model plus its manifest.",
6
6
  "keywords": [
@@ -37,12 +37,12 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@effected/spdx": "^0.9.0"
40
+ "@effected/spdx": "^0.10.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@effected/package-json": "^0.18.0",
44
- "@effected/schema-org": "^0.5.0",
45
- "effect": "4.0.0-rc.117"
43
+ "@effected/package-json": "^0.19.0",
44
+ "@effected/schema-org": "^0.6.0",
45
+ "effect": "4.0.0-rc.118"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=24.11.0"