All files / src/components/SEO index.tsx

100% Statements 10/10
66.66% Branches 6/9
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151                            6x                                 14x   14x               14x 7x                                                               7x                           14x     6x                 14x     14x                                                                                              
import React from "react";
import Helmet from "react-helmet";
import config from "@/config/index.json";
 
type Props = {
  url: string;
  title?: string;
  siteTitleAlt: string;
  isPost: boolean;
  image: string;
  tag: string;
  description: string;
};
 
const schemaOrgJSONLD = ({
  url,
  title,
  siteTitleAlt,
  isPost,
  image,
  tag,
  description,
}: {
  url: string;
  title: string;
  siteTitleAlt: string;
  isPost: boolean;
  image: string;
  tag: string;
  description: string;
}) => {
  const returnJson = [];
 
  returnJson.push({
    "@context": "http://schema.org",
    "@type": "WebSite",
    url,
    name: title,
    alternateName: siteTitleAlt || config.siteTitle,
  });
 
  if (isPost) {
    returnJson.push({
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      itemListElement: [
        {
          "@type": "ListItem",
          position: 1,
          item: {
            "@id": "https://tubone-project24.xyz",
            name: "tubone BOYAKI",
          },
        },
        {
          "@type": "ListItem",
          position: 2,
          item: {
            "@id": `https://tubone-project24.xyz/tag/${tag}`,
            name: "tubone BOYAKI",
          },
        },
        {
          "@type": "ListItem",
          position: 3,
          item: {
            "@id": url,
            name: title,
            image,
          },
        },
      ],
    });
 
    returnJson.push({
      "@context": "http://schema.org",
      "@type": "BlogPosting",
      url,
      name: title,
      alternateName: siteTitleAlt || "",
      headline: title,
      image: {
        "@type": "ImageObject",
        url: image,
      },
      description,
    });
  }
  return returnJson;
};
 
const SEO = ({
  url,
  title = config.siteTitle,
  description,
  image,
  siteTitleAlt,
  isPost,
  tag,
}: Props) => {
  const ogpImageLink = `https://tubone-project24.xyz/ogp.png?title=${encodeURI(
    title
  )}`;
  return (
    <Helmet>
      <title>{title}</title>
 
      {/* General tags */}
      <meta name="description" content={description} />
      <meta name="image" content={image} />
 
      {/* Schema.org tags */}
      <script type="application/ld+json">
        {JSON.stringify(
          schemaOrgJSONLD({
            url,
            title,
            siteTitleAlt,
            isPost,
            image,
            description,
            tag,
          })
        )}
      </script>
 
      {/* OpenGraph tags */}
      <meta property="og:url" content={url} />
      {isPost ? (
        <meta property="og:type" content="article" />
      ) : (
        <meta property="og:type" content="website" />
      )}
      <meta property="og:title" content={title} />
      <meta property="og:description" content={description} />
      <meta property="og:image" content={image} />
      <meta property="og:locale" content="ja_JP" />
      <meta property="fb:app_id" content="280941406476272" />
 
      {/* Twitter Card tags */}
      <meta name="twitter:card" content="summary_large_image" />
      <meta name="twitter:creator" content="@meitante1conan" />
      <meta name="twitter:title" content={title} />
      <meta name="twitter:description" content={description} />
      <meta name="twitter:image" content={ogpImageLink} />
    </Helmet>
  );
};
 
export default SEO;