Skip to content

Commit d8cb774

Browse files
add dynamic preview titles
1 parent 5937aa2 commit d8cb774

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs-v2/theme.config.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ const config: DocsThemeConfig = {
1414
const router = useRouter()
1515
const { frontMatter } = useConfig()
1616

17+
let pageTitle = frontMatter?.title;
18+
// If no title in front matter, derive it from the URL
19+
if (!pageTitle) {
20+
const segments = router.asPath.replace(/\/$/, "").split("/");
21+
pageTitle = segments[segments.length - 1];
22+
// Replace dashes/underscores with spaces and capitalize each first letter
23+
pageTitle = pageTitle.replace(/[-_]/g, " ");
24+
pageTitle = pageTitle.replace(/\b\w/g, (char) => char.toUpperCase());
25+
}
26+
1727
return (
1828
<>
1929
<meta name="description" content="Workflow automation for developers" />
2030
{router && <link rel="canonical" href={`https://pipedream.com/docs${router.route === "/"
2131
? ""
2232
: router.route}`} />}
2333
<link rel="icon" href="/docs/favicon.ico" />
24-
<meta property="og:title" content={`${frontMatter?.title || ""} — Pipedream`} />
34+
<meta property="og:title" content={`${pageTitle} — Pipedream`} />
2535
</>
2636
)
2737
},

0 commit comments

Comments
 (0)