Skip to content

Commit

Permalink
generate meta tag preview from doc id
Browse files Browse the repository at this point in the history
  • Loading branch information
DZGoldman committed Sep 6, 2022
1 parent b38b5e1 commit 0c7742f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion website/src/theme/Layout.js → website/src/theme/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import React from "react";
import OriginalLayout from "@theme-original/Layout";
import Head from "@docusaurus/Head";
import { useLocation } from "@docusaurus/router";

const pathNameToPreviewText = (pathName: string) => {
const splitPaths = pathName.split("/").filter(x => x);
const probablyID = splitPaths[splitPaths.length - 1];
if (!probablyID) return "";
return probablyID
.split("-")
.map(word => word[0].toUpperCase() + word.slice(1))
.join(" ");
};

export default function Layout(props) {
const { pathname } = useLocation();

const previewText = pathNameToPreviewText(pathname);

return (
<>
<Head>
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@arbitrum" />
<meta name="twitter:title" content="Arbitrum Docs!" />
<meta name="twitter:title" content={previewText || "Arbitrum Docs!"} />
<meta
name="twitter:description"
content="Arbitrum Documentation Center"
Expand Down

0 comments on commit 0c7742f

Please sign in to comment.