diff --git a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx index a06b392a..1c8f1b19 100644 --- a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx +++ b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx @@ -34,6 +34,7 @@ import { PublishedPollBlock } from "./Blocks/PublishedPollBlock"; import { PollData } from "./fetchPollData"; import { ButtonPrimary } from "components/Buttons"; import { blockTextSize } from "src/utils/blockTextSize"; +import { slugify } from "src/utils/slugify"; import { PostNotAvailable } from "components/Blocks/BlueskyPostBlock/BlueskyEmbed"; export function PostContent({ @@ -391,68 +392,48 @@ export let Block = ({ ); case PubLeafletBlocksHeader.isMain(b.block): { + let slug = slugify(b.block.plaintext); + let headingProps = { + ...blockProps, + id: preview ? undefined : slug || blockProps.id, + }; + let textBlockProps = { + ...b.block, + index, + preview, + pageId, + footnoteIndexMap, + }; + let href = pageId ? `?page=${pageId}#${slug}` : `#${slug}`; + let link = (children: React.ReactNode) => + preview || !slug ? ( + children + ) : ( + + {children} + + ); if (b.block.level === 1) return ( -

- +

+ {link()}

); if (b.block.level === 2) return ( -

- +

+ {link()}

); if (b.block.level === 3) return ( -

- +

+ {link()}

); - // if (b.block.level === 4) return

{b.block.plaintext}

; - // if (b.block.level === 5) return
{b.block.plaintext}
; return ( -
- +
+ {link()}
); } diff --git a/src/utils/slugify.ts b/src/utils/slugify.ts new file mode 100644 index 00000000..2876a38f --- /dev/null +++ b/src/utils/slugify.ts @@ -0,0 +1,9 @@ +export function slugify(text: string): string { + return text + .toLowerCase() + .trim() + .replace(/[^\w\s-]/g, "") + .replace(/[\s_]+/g, "-") + .replace(/-+/g, "-") + .replace(/^-|-$/g, ""); +}