]> Untitled Git - lemmy-ui.git/blob - src/shared/components/common/html-tags.tsx
Refactor lets to consts
[lemmy-ui.git] / src / shared / components / common / html-tags.tsx
1 import { htmlToText } from "html-to-text";
2 import { Component } from "inferno";
3 import { Helmet } from "inferno-helmet";
4 import { httpExternalPath } from "../../env";
5 import { md } from "../../utils";
6
7 interface HtmlTagsProps {
8   title: string;
9   path: string;
10   description?: string;
11   image?: string;
12 }
13
14 /// Taken from https://metatags.io/
15 export class HtmlTags extends Component<HtmlTagsProps, any> {
16   render() {
17     const url = httpExternalPath(this.props.path);
18     const desc = this.props.description;
19     const image = this.props.image;
20
21     return (
22       <Helmet title={this.props.title}>
23         {["title", "og:title", "twitter:title"].map(t => (
24           <meta key={t} property={t} content={this.props.title} />
25         ))}
26         {["og:url", "twitter:url"].map(u => (
27           <meta key={u} property={u} content={url} />
28         ))}
29
30         {/* Open Graph / Facebook */}
31         <meta property="og:type" content="website" />
32
33         {/* Twitter */}
34         <meta property="twitter:card" content="summary_large_image" />
35
36         {/* Optional desc and images */}
37         {["description", "og:description", "twitter:description"].map(
38           n =>
39             desc && (
40               <meta
41                 key={n}
42                 name={n}
43                 content={htmlToText(md.renderInline(desc))}
44               />
45             )
46         )}
47         {["og:image", "twitter:image"].map(
48           p => image && <meta key={p} property={p} content={image} />
49         )}
50       </Helmet>
51     );
52   }
53 }