Skip to content

Commit

Permalink
Add titles from toc. (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgr authored Nov 2, 2023
1 parent 0a6925b commit 5aecc84
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions components/ui/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface MDFileContent {
* @format textarea
*/
content: string;
title?: string;
}

export interface Template {
Expand Down
6 changes: 4 additions & 2 deletions loaders/denoLoader.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,6 +10,7 @@ export interface Doc {
* @format textarea
*/
content: string;
title?: string;
}

const loader = async (
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion sections/CustomizableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function CustomizableMarkdownContent(
</Head>
{matchCustom?.content
? matchCustom.content.map((c) => <c.Component {...c.props} />)
: <MarkdownContent data={{ content: props.data.content }} />}
: <MarkdownContent data={{ ...props.data }} />}
</>
);
}
17 changes: 13 additions & 4 deletions sections/MarkdownContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export default function DocsPage(
if (attrs?.description) {
description = String(attrs.description);
}

return (
<>
<Head>
<title>
{props.data.title
? `${props.data.title} | deco.cx docs`
: "deco.cx docs"}
</title>
<link rel="stylesheet" href={`/gfm.css`} />
{description && <meta name="description" content={description} />}
<style
Expand Down Expand Up @@ -80,8 +84,13 @@ export default function DocsPage(
</style>
</Head>
<div class="flex flex-col min-h-screen">
<div class="flex-1">
<div class="mx-auto max-w-screen-lg px-4 flex gap-6">
<div class="flex-1 px-4">
{props.data.title && (
<h1 class="text-neutral-900 text-[40px] font-semibold leading-[48px]">
{props.data.title}
</h1>
)}
<div class="mx-auto max-w-screen-lg flex gap-6">
<Content content={frontMatterContent} />
</div>
</div>
Expand All @@ -99,7 +108,7 @@ function Content(props: MDContent) {
);

return (
<main class="py-6 overflow-hidden">
<main class="py-2 overflow-hidden">
{attrs.since && (
<span class="bg-gray-100 text-gray-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-gray-300">
Version: {attrs.since}
Expand Down

0 comments on commit 5aecc84

Please sign in to comment.