mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-05-12 06:16:55 +00:00
use native astro md rendering where possible
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
---
|
---
|
||||||
import {getCollection} from "astro:content";
|
import {type CollectionEntry, getCollection} from "astro:content";
|
||||||
import BaseLayout from '../../layouts/BaseLayout.astro';
|
import BaseLayout from '../../layouts/BaseLayout.astro';
|
||||||
import Bio from '../../components/Bio.astro';
|
import Bio from '../../components/Bio.astro';
|
||||||
import readingTime from 'reading-time';
|
import readingTime from 'reading-time';
|
||||||
import {marked} from 'marked';
|
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
|
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts');
|
||||||
return posts.map(p => ({
|
return posts.map(p => ({
|
||||||
params: {
|
params: {
|
||||||
@@ -18,14 +16,17 @@ export async function getStaticPaths() {
|
|||||||
publishDate: p.data.publishDate,
|
publishDate: p.data.publishDate,
|
||||||
slug: p.slug,
|
slug: p.slug,
|
||||||
tags: p.data.tags,
|
tags: p.data.tags,
|
||||||
content: marked.parse(p.body),
|
|
||||||
readTime: readingTime(p.body).text,
|
readTime: readingTime(p.body).text,
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const {slug, title, description, publishDate, tags, content, readTime} = Astro.props;
|
const {slug, title, description, publishDate, tags, readTime} = Astro.props;
|
||||||
const permalink = `${Astro?.site?.href}blog/${slug}`;
|
const permalink = `${Astro?.site?.href}blog/${slug}`;
|
||||||
|
const posts = await getCollection('posts');
|
||||||
|
const entry: CollectionEntry<'posts'> | undefined = posts.find(e => e.slug === slug);
|
||||||
|
if (!entry) throw new Error(`Post not found: ${slug}`);
|
||||||
|
const { Content } = await entry.render();
|
||||||
---
|
---
|
||||||
|
|
||||||
<BaseLayout title={title} description={description} permalink={permalink} current="blog">
|
<BaseLayout title={title} description={description} permalink={permalink} current="blog">
|
||||||
@@ -40,7 +41,9 @@ const permalink = `${Astro?.site?.href}blog/${slug}`;
|
|||||||
<hr/>
|
<hr/>
|
||||||
</header>
|
</header>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<article class="content" set:html={content}></article>
|
<article class="content">
|
||||||
|
<Content />
|
||||||
|
</article>
|
||||||
<hr/>
|
<hr/>
|
||||||
<Bio/>
|
<Bio/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
import {getCollection} from "astro:content";
|
import {type CollectionEntry, getCollection} from "astro:content";
|
||||||
import {marked} from 'marked';
|
|
||||||
import BaseLayout from "../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
@@ -13,13 +12,16 @@ export async function getStaticPaths() {
|
|||||||
props: {
|
props: {
|
||||||
title: p.data.title,
|
title: p.data.title,
|
||||||
slug: p.slug,
|
slug: p.slug,
|
||||||
content: marked.parse(p.body),
|
},
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const {slug, title, content} = Astro.props;
|
const {slug, title} = Astro.props;
|
||||||
const permalink = `${Astro?.site?.href}writing/${slug}`;
|
const permalink = `${Astro?.site?.href}writing/${slug}`;
|
||||||
|
const writing = await getCollection('writing');
|
||||||
|
const entry: CollectionEntry<'writing'> | undefined = writing.find(e => e.slug === slug);
|
||||||
|
if (!entry) throw new Error(`Entry not found: ${slug}`);
|
||||||
|
const { Content } = await entry.render();
|
||||||
---
|
---
|
||||||
<BaseLayout title={title} description={""} permalink={permalink} current="writing">
|
<BaseLayout title={title} description={""} permalink={permalink} current="writing">
|
||||||
<header>
|
<header>
|
||||||
@@ -27,7 +29,9 @@ const permalink = `${Astro?.site?.href}writing/${slug}`;
|
|||||||
<hr/>
|
<hr/>
|
||||||
</header>
|
</header>
|
||||||
<div class="container writing">
|
<div class="container writing">
|
||||||
<article class="content" set:html={content}></article>
|
<article class="content">
|
||||||
|
<Content />
|
||||||
|
</article>
|
||||||
<hr/>
|
<hr/>
|
||||||
</div>
|
</div>
|
||||||
</BaseLayout>
|
</BaseLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user