Skip to content

Commit f7d93b1

Browse files
committed
Don't render markdown in multiple components in nextjs template
1 parent e2f598d commit f7d93b1

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

browser/create-template/templates/nextjs-site/src/components/MarkdownContent.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ import styles from '@/views/Block/TextBlock.module.css';
1313
*/
1414
export const MarkdownContent = ({
1515
subject,
16-
initialContent,
16+
initialValue,
1717
}: {
1818
subject: string;
19-
initialContent: string | TrustedHTML;
19+
initialValue: string;
2020
}) => {
2121
const resource = useResource<TextBlock>(subject);
2222

23-
const matterResult = matter(resource.props.description ?? '');
23+
const matterResult = matter(
24+
resource.loading ? initialValue : resource.props.description,
25+
);
2426
const processed = remark().use(html).processSync(matterResult.content);
2527

2628
return (
2729
<div
2830
className={styles.wrapper}
2931
dangerouslySetInnerHTML={{
30-
__html: resource.loading ? initialContent : processed.toString(),
32+
__html: processed.toString(),
3133
}}
3234
/>
3335
);

browser/create-template/templates/nextjs-site/src/views/Block/TextBlock.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import { Resource } from '@tomic/react';
2-
import { remark } from 'remark';
3-
import html from 'remark-html';
4-
import matter from 'gray-matter';
52
import { MarkdownContent } from '@/components/MarkdownContent';
3+
import type { TextBlock as TextBlockType } from '@/ontologies/website';
64

7-
const TextBlock = ({ resource }: { resource: Resource }) => {
8-
const matterResult = matter(resource.props.description);
9-
10-
const processed = remark().use(html).processSync(matterResult.content);
11-
12-
const initialContent = processed.toString();
5+
const TextBlock = ({ resource }: { resource: Resource<TextBlockType> }) => {
136
return (
147
<MarkdownContent
158
subject={resource.subject}
16-
initialContent={initialContent}
9+
initialValue={resource.props.description}
1710
/>
1811
);
1912
};

browser/create-template/templates/nextjs-site/src/views/FullPage/BlogpostFullPage.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import Container from '@/components/Layout/Container';
2-
import { Blogpost } from '@/ontologies/website';
2+
import type { Blogpost } from '@/ontologies/website';
33
import { Resource } from '@tomic/lib';
44
import styles from './BlogpostFullPage.module.css';
55
import { Image } from '@/components/Image';
6-
import matter from 'gray-matter';
7-
import html from 'remark-html';
8-
import { remark } from 'remark';
96
import { MarkdownContent } from '@/components/MarkdownContent';
107

118
const formatter = new Intl.DateTimeFormat('default', {
@@ -16,9 +13,6 @@ const formatter = new Intl.DateTimeFormat('default', {
1613

1714
const BlogpostFullPage = ({ resource }: { resource: Resource<Blogpost> }) => {
1815
const date = formatter.format(new Date(resource.props.publishedAt));
19-
const matterResult = matter(resource.props.description);
20-
const processed = remark().use(html).processSync(matterResult.content);
21-
const initialContent = processed.toString();
2216

2317
return (
2418
<Container>
@@ -31,7 +25,7 @@ const BlogpostFullPage = ({ resource }: { resource: Resource<Blogpost> }) => {
3125
<p className={styles.publishDate}>{date}</p>
3226
<MarkdownContent
3327
subject={resource.subject}
34-
initialContent={initialContent}
28+
initialValue={resource.props.description}
3529
/>
3630
</div>
3731
</div>

0 commit comments

Comments
 (0)