From: Matthew Miner <mminer237+face@gmail.com> Date: Mon, 10 Jul 2023 14:46:36 +0000 (-0500) Subject: Use canonical URLs (#1883) X-Git-Url: http://these/git/%7B%60%24%7BghostArchiveUrl%7D/%22%7Burl%7D/static/%24%7Bsubmission.url%7D?a=commitdiff_plain;h=53c3cfeade90150b07431386745a24aa699a25ec;p=lemmy-ui.git Use canonical URLs (#1883) --- diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index 5d53258..80649fa 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -8,6 +8,7 @@ import { I18NextService } from "../../services"; interface HtmlTagsProps { title: string; path: string; + canonicalPath?: string; description?: string; image?: string; } @@ -16,6 +17,8 @@ interface HtmlTagsProps { export class HtmlTags extends Component<HtmlTagsProps, any> { render() { const url = httpExternalPath(this.props.path); + const canonicalUrl = + this.props.canonicalPath ?? httpExternalPath(this.props.path); const desc = this.props.description; const image = this.props.image; @@ -30,6 +33,8 @@ export class HtmlTags extends Component<HtmlTagsProps, any> { <meta key={u} property={u} content={url} /> ))} + <link rel="canonical" href={canonicalUrl} /> + {/* Open Graph / Facebook */} <meta property="og:type" content="website" /> diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index c00380a..b88d6f6 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -312,6 +312,7 @@ export class Community extends Component< <HtmlTags title={this.documentTitle} path={this.context.router.route.match.url} + canonicalPath={res.community_view.community.actor_id} description={res.community_view.community.description} image={res.community_view.community.icon} /> diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 39979e2..d493f78 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -324,6 +324,7 @@ export class Profile extends Component< <HtmlTags title={this.documentTitle} path={this.context.router.route.match.url} + canonicalPath={personRes.person_view.person.actor_id} description={personRes.person_view.person.bio} image={personRes.person_view.person.avatar} /> diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index f9d3512..eeb713a 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -353,6 +353,7 @@ export class Post extends Component<any, PostState> { <HtmlTags title={this.documentTitle} path={this.context.router.route.match.url} + canonicalPath={res.post_view.post.ap_id} image={this.imageTag} description={res.post_view.post.body} /> diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index e9aaaa1..99b1803 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -466,6 +466,10 @@ export class Search extends Component<any, SearchState> { <HtmlTags title={this.documentTitle} path={this.context.router.route.match.url} + canonicalPath={ + this.context.router.route.match.url + + this.context.router.route.location.search + } /> <h1 className="h4 mb-4">{I18NextService.i18n.t("search")}</h1> {this.selects}