@autobusal/common 1.5.1 → 1.6.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.
- package/CHANGELOG.md +14 -0
- package/Meta.tsx +21 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to `@autobusal/common` are documented here. This project follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/) and [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [1.6.0] - 2026-07-30
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **`Meta` now emits a canonical `<link>` and `og:url` on every page by
|
|
11
|
+
default**, even when the caller passes no `url` prop - previously `url`
|
|
12
|
+
was never passed at any of this component's ~136 call sites across both
|
|
13
|
+
apps, so no page anywhere had a canonical tag. Defaults to the current
|
|
14
|
+
path (`location.pathname`, via `react-router-dom`'s `useLocation`) with
|
|
15
|
+
the origin prepended - query strings are naturally excluded, so a search
|
|
16
|
+
results page with `?sfrom=X&sto=Y` or a paginated `?page=N` correctly
|
|
17
|
+
canonicalizes to its bare path instead of creating unbounded near-duplicate
|
|
18
|
+
URLs. `url` can still be passed explicitly to override.
|
|
19
|
+
|
|
6
20
|
## [1.5.1] - 2026-07-30
|
|
7
21
|
|
|
8
22
|
### Fixed
|
package/Meta.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
2
3
|
|
|
3
4
|
interface Props {
|
|
4
5
|
title: string
|
|
@@ -52,8 +53,26 @@ const useSoleTitleOwnership = (fullTitle: string): void => {
|
|
|
52
53
|
});
|
|
53
54
|
};
|
|
54
55
|
|
|
56
|
+
// `url` was never passed at any of this component's ~136 call sites across
|
|
57
|
+
// both apps - every page shipped with no canonical tag at all, which is a
|
|
58
|
+
// real problem given the 9-segment /bus-lines search URLs and ?sfrom=/?sto=/
|
|
59
|
+
// ?page= parameters create effectively unbounded near-duplicate-content URL
|
|
60
|
+
// space. Rather than thread an explicit `url` through every single call site
|
|
61
|
+
// (easy to miss, easy to get subtly wrong per-page), default it to the
|
|
62
|
+
// current path - React Router's `location.pathname` naturally excludes the
|
|
63
|
+
// query string, so a search results page with ?sfrom=X&sto=Y canonicalizes
|
|
64
|
+
// to its bare /bus-lines/{from}/{to}/... path, and a static page's own path
|
|
65
|
+
// is already the correct canonical. Callers can still pass `url` explicitly
|
|
66
|
+
// to override (e.g. to canonicalize a paginated URL back to page 1).
|
|
67
|
+
const useCanonicalUrl = (explicit?: string): string => {
|
|
68
|
+
const location = useLocation();
|
|
69
|
+
|
|
70
|
+
return explicit ?? `${ window.location.origin }${ location.pathname }`;
|
|
71
|
+
};
|
|
72
|
+
|
|
55
73
|
const Meta = ({ title, keywords, description, image, url, type = 'website', noIndex = false, children }: Props): JSX.Element => {
|
|
56
74
|
const fullTitle = withBrand(title);
|
|
75
|
+
const canonicalUrl = useCanonicalUrl(url);
|
|
57
76
|
|
|
58
77
|
useSoleTitleOwnership(fullTitle);
|
|
59
78
|
|
|
@@ -67,14 +86,14 @@ const Meta = ({ title, keywords, description, image, url, type = 'website', noIn
|
|
|
67
86
|
{/* Standard Meta Tags */}
|
|
68
87
|
{ keywords && <meta name="keywords" content={ keywords } /> }
|
|
69
88
|
{ description && <meta name="description" content={ description } /> }
|
|
70
|
-
|
|
89
|
+
<link rel="canonical" href={ canonicalUrl } />
|
|
71
90
|
|
|
72
91
|
{/* Open Graph / Facebook */}
|
|
73
92
|
<meta property="og:type" content={ type } />
|
|
74
93
|
<meta property="og:title" content={ fullTitle } />
|
|
75
94
|
{ description && <meta property="og:description" content={ description } /> }
|
|
76
95
|
{ image && <meta property="og:image" content={ image } /> }
|
|
77
|
-
|
|
96
|
+
<meta property="og:url" content={ canonicalUrl } />
|
|
78
97
|
{ brand && <meta property="og:site_name" content={ brand } /> }
|
|
79
98
|
|
|
80
99
|
{/* Twitter */}
|