]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/common/html-tags.tsx
Use canonical URLs (#1883)
[lemmy-ui.git] / src / shared / components / common / html-tags.tsx
index 3a8b270a496d60d85ae325da938c6de263fecdec..80649fa119e85cfa8e0214065aeeaad2edf45a47 100644 (file)
@@ -1,13 +1,14 @@
+import { httpExternalPath } from "@utils/env";
 import { htmlToText } from "html-to-text";
 import { Component } from "inferno";
 import { Helmet } from "inferno-helmet";
-import { httpExternalPath } from "../../env";
 import { md } from "../../markdown";
 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" />