Skip to content

Commit

Permalink
refactor(rss): use micromark instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yeskunall committed Jun 4, 2024
1 parent 8a6088e commit c0a5d1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"eslint-plugin-typescript-sort-keys": "3.2.0",
"markdown-it": "14.1.0",
"mdast-util-to-string": "4.0.0",
"micromark": "4.0.0",
"micromark-extension-gfm": "3.0.0",
"postcss": "8.4.38",
"postcss-import": "16.1.0",
"prettier": "3.2.5",
Expand Down
15 changes: 9 additions & 6 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import type { APIContext } from "astro";

import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import MarkdownIt from "markdown-it";
import { micromark } from "micromark";
import { gfm, gfmHtml } from "micromark-extension-gfm";
import sanitizeHtml from "sanitize-html";

import { siteConfig } from "~/config/site-config";
import { sortByDate } from "~/lib/post";
import { siteConfig } from "~/site-config";

// TODO(yeskunall): Replace with [`micromark`](https://github.com/micromark/micromark) maybe?
const parser = new MarkdownIt();

export const GET = async (context: APIContext) => {
const posts = await getCollection("post");
Expand All @@ -18,7 +16,12 @@ export const GET = async (context: APIContext) => {
return rss({
description: siteConfig.description,
items: allPostsByDate.map(post => ({
content: sanitizeHtml(parser.render(post.body)),
content: sanitizeHtml(
micromark(post.body, {
extensions: [gfm()],
htmlExtensions: [gfmHtml()],
}),
),
description: post.data.description,
link: `writing/${post.slug}`,
pubDate: post.data.publishDate,
Expand Down

0 comments on commit c0a5d1b

Please sign in to comment.