From 2e97a52a3f862f48665edd5425e712fdd941cc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Gaudencio=20do=20R=C3=AAgo?= Date: Wed, 1 Nov 2023 19:59:13 -0300 Subject: [PATCH] Add titles from toc. --- components/ui/Types.tsx | 1 + loaders/denoLoader.ts | 6 ++++-- sections/CustomizableContent.tsx | 2 +- sections/MarkdownContent.tsx | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/components/ui/Types.tsx b/components/ui/Types.tsx index b62e0e55..778321f4 100644 --- a/components/ui/Types.tsx +++ b/components/ui/Types.tsx @@ -5,6 +5,7 @@ export interface MDFileContent { * @format textarea */ content: string; + title?: string; } export interface Template { diff --git a/loaders/denoLoader.ts b/loaders/denoLoader.ts index e90e4c3e..9ca70c7c 100644 --- a/loaders/denoLoader.ts +++ b/loaders/denoLoader.ts @@ -1,6 +1,7 @@ import { MDFileContent } from "deco-sites/starting/components/ui/Types.tsx"; import type { LoaderContext } from "deco/types.ts"; import { redirect } from "deco/mod.ts"; +import { getTitleForPost } from "deco-sites/starting/docs/toc.ts"; /** @title {{{path}}} */ export interface Doc { @@ -9,6 +10,7 @@ export interface Doc { * @format textarea */ content: string; + title?: string; } const loader = async ( @@ -38,11 +40,11 @@ const loader = async ( const doc = props.docs?.find((doc) => doc.path === slug); if (doc) { - return { content: doc.content }; + return { content: doc.content, title: doc.title }; } const fileContent = await Deno.readTextFile(url); - return { content: fileContent }; + return { content: fileContent, title: getTitleForPost(language, documentSlug) }; }; export default loader; diff --git a/sections/CustomizableContent.tsx b/sections/CustomizableContent.tsx index 47725545..08b47ec2 100644 --- a/sections/CustomizableContent.tsx +++ b/sections/CustomizableContent.tsx @@ -89,7 +89,7 @@ export default function CustomizableMarkdownContent( {matchCustom?.content ? matchCustom.content.map((c) => ) - : } + : } ); } diff --git a/sections/MarkdownContent.tsx b/sections/MarkdownContent.tsx index 73e22dce..faa43caf 100644 --- a/sections/MarkdownContent.tsx +++ b/sections/MarkdownContent.tsx @@ -29,10 +29,14 @@ export default function DocsPage( if (attrs?.description) { description = String(attrs.description); } - return ( <> + + {props.data.title + ? `${props.data.title} | deco.cx docs` + : "deco.cx docs"} + {description && }