@kitr/seo 0.6.0 → 0.7.0

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/dist/index.js +7 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -34,6 +34,12 @@ function fromLoader(context) {
34
34
  ...typeof data.description === "string" ? { description: data.description } : {}
35
35
  };
36
36
  }
37
+ /** Drop trailing slashes. A loop, since `/\\/+$/` backtracks quadratically on long runs of `/`. */
38
+ function stripTrailingSlashes(s) {
39
+ let end = s.length;
40
+ while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
41
+ return s.slice(0, end);
42
+ }
37
43
  /**
38
44
  * Meta tags for a route's `head()`: `head: (ctx) => seo({ title, description }, ctx)`.
39
45
  * Covers title, description, Open Graph, Twitter cards, canonical and robots. Pass the `head`
@@ -54,7 +60,7 @@ function seo(input, context) {
54
60
  const title = input.title ? site.name && input.title !== site.name ? `${input.title} · ${site.name}` : input.title : site.name;
55
61
  const image = input.image ?? site.image;
56
62
  const path = pathOf(context);
57
- const url = input.url ?? (site.url && path ? `${site.url.replace(/\/+$/, "")}${path}` : site.url);
63
+ const url = input.url ?? (site.url && path ? `${stripTrailingSlashes(site.url)}${path}` : site.url);
58
64
  const meta = [];
59
65
  if (title) meta.push({ title }, {
60
66
  property: "og:title",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitr/seo",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "@kitr/seo: meta and Open Graph tags per route, prerender list, sitemap and robots, cache headers. Works for SSR, static sites, SPAs and PWAs.",
5
5
  "kitr": {
6
6
  "name": "seo",
@@ -41,7 +41,7 @@
41
41
  "docs"
42
42
  ],
43
43
  "dependencies": {
44
- "@kitr/core": "0.6.0"
44
+ "@kitr/core": "0.7.0"
45
45
  },
46
46
  "peerDependencies": {},
47
47
  "peerDependenciesMeta": {},