index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import Head from "next/head";
  2. import { ReactNode } from "react";
  3. export interface SeoHeadConfig {
  4. title?: string;
  5. description?: string;
  6. keywords?: string;
  7. url?: string;
  8. siteName?: string;
  9. img?: string;
  10. canonical?: string;
  11. pre?: string;
  12. next?: string;
  13. jsonLd?: string;
  14. }
  15. interface SeoHeadProps {
  16. seoConfig: SeoHeadConfig;
  17. children?: ReactNode;
  18. }
  19. export function SeoHead({ seoConfig, children }: SeoHeadProps) {
  20. return (
  21. <Head>
  22. {children}
  23. {seoConfig.title ? <title>{seoConfig.title}</title> : null}
  24. {seoConfig.description ? (
  25. <meta name="description" content={seoConfig.description} />
  26. ) : null}
  27. {seoConfig.keywords ? (
  28. <meta name="keywords" content={seoConfig.keywords} />
  29. ) : null}
  30. {seoConfig.url ? (
  31. <meta property="og:url" key="og:url" content={seoConfig.url} />
  32. ) : null}
  33. {seoConfig.siteName ? (
  34. <meta
  35. property="og:site_name"
  36. key="og:site_name"
  37. content={seoConfig.siteName}
  38. />
  39. ) : null}
  40. {seoConfig.title ? (
  41. <meta property="og:title" key="og:title" content={seoConfig.title} />
  42. ) : null}
  43. {seoConfig.description ? (
  44. <meta
  45. property="og:description"
  46. key="og:description"
  47. content={seoConfig.description}
  48. />
  49. ) : null}
  50. {seoConfig.img ? (
  51. <meta property="og:image" key="og:image" content={seoConfig.img} />
  52. ) : null}
  53. {seoConfig.title ? (
  54. <meta
  55. name="twitter:title"
  56. key="twitter:title"
  57. content={seoConfig.title}
  58. />
  59. ) : null}
  60. {seoConfig.description ? (
  61. <meta
  62. name="twitter:description"
  63. key="twitter:description"
  64. content={seoConfig.description}
  65. />
  66. ) : null}
  67. {seoConfig.img ? (
  68. <>
  69. <meta name="twitter:card" key="twitter:card" content="summary" />
  70. <meta
  71. name="twitter:image"
  72. key="twitter:image"
  73. content={seoConfig.img}
  74. />
  75. </>
  76. ) : null}
  77. {seoConfig.canonical ? (
  78. <link rel="canonical" key="canonical" href={seoConfig.canonical} />
  79. ) : null}
  80. {seoConfig.pre ? <link rel="prev" key="prev" href={seoConfig.pre} /> : null}
  81. {seoConfig.next ? <link rel="next" key="next" href={seoConfig.next} /> : null}
  82. {seoConfig.jsonLd ? (
  83. <script
  84. type="application/ld+json"
  85. key="application/ld+json"
  86. dangerouslySetInnerHTML={{ __html: seoConfig.jsonLd }}
  87. />
  88. ) : null}
  89. </Head>
  90. );
  91. }