目前,我在将 MDX 转换为 HTML 时遇到问题。
我正在为Tailwind 博客做这件事
Github 上的完整代码 → https://github.com/tailwindlabs/blog.tailwindcss.com
以下是相关代码:
脚本/build-rss.js
import fs from 'fs'
import path from 'path'
import getAllPostPreviews from '../src/getAllPostPreviews'
import RSS from 'rss'
const siteUrl = 'https://blog.tailwindcss.com'
const feed = new RSS({
title: 'Blog – Tailwind CSS',
site_url: siteUrl,
feed_url: `${siteUrl}/feed.xml`,
})
getAllPostPreviews().forEach(({ link, module: { meta, default: html } }) => {
console.log(html)
const postText = `<div style="margin-top=55px; font-style: italic;">(The post <a href="${siteUrl + link}">${meta.title}</a> appeared first on <a href="${siteUrl}">Tailwind CSS Blog</a>.)</div>`;
feed.item({
title: meta.title,
guid: link,
url: `https://blog.tailwindcss.com${link}`,
date: meta.date,
description: meta.description,
custom_elements: [{
"content:encoded": html + postText
}].concat(meta.authors.map((author) => ({ author: [{ name: author.name }] }))),
})
})
fs.writeFileSync('./out/feed.xml', feed.xml({ indent: true }))
html
变量记录到控制台:
[Function: MDXContent] { isMDXComponent: true }
如何获得纯 HTML?