Use canonical URLs (#1883)
authorMatthew Miner <mminer237+face@gmail.com>
Mon, 10 Jul 2023 14:46:36 +0000 (09:46 -0500)
committerGitHub <noreply@github.com>
Mon, 10 Jul 2023 14:46:36 +0000 (10:46 -0400)
src/shared/components/common/html-tags.tsx
src/shared/components/community/community.tsx
src/shared/components/person/profile.tsx
src/shared/components/post/post.tsx
src/shared/components/search.tsx

index 5d532589efb62fe2a7c08f2f61ccfa0131a1c468..80649fa119e85cfa8e0214065aeeaad2edf45a47 100644 (file)
@@ -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" />
 
index c00380ab2db9ff1b1258cadde8bd0f25a6d2efb8..b88d6f6100e03843ef387ad60a3c8d524a0b1650 100644 (file)
@@ -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}
             />
index 39979e292b490f6cee04a8538c6d3facd736ed87..d493f787d5602240ef2b0bfc339315da72863a10 100644 (file)
@@ -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}
               />
index f9d351270e5b3e057440d58d1d49593ec8c294f1..eeb713a9cef6538bc483776b3cbb0dbf7313b6b5 100644 (file)
@@ -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}
               />
index e9aaaa1b3761c97b37fcb821ce6930ad7cfa8c35..99b180356b87c5ab89f789a795c49c81f9ef8645 100644 (file)
@@ -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}