mirror of
https://github.com/prometheus/docs.git
synced 2026-02-06 00:46:09 +01:00
Merge pull request #2666 from sysadmind/blog-feed
Update blog RSS feed with rendered content
This commit is contained in:
16
package-lock.json
generated
16
package-lock.json
generated
@@ -30,6 +30,7 @@
|
||||
"rehype-autolink-headings": "^7.1.0",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"rehype-slug": "^6.0.0",
|
||||
"rehype-stringify": "^10.0.1",
|
||||
"remark-frontmatter": "^5.0.0",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"semver": "^7.7.1",
|
||||
@@ -8173,6 +8174,21 @@
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/rehype-stringify": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/rehype-stringify/-/rehype-stringify-10.0.1.tgz",
|
||||
"integrity": "sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0",
|
||||
"hast-util-to-html": "^9.0.0",
|
||||
"unified": "^11.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/remark-frontmatter": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/remark-frontmatter/-/remark-frontmatter-5.0.0.tgz",
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"rehype-autolink-headings": "^7.1.0",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"rehype-slug": "^6.0.0",
|
||||
"rehype-stringify": "^10.0.1",
|
||||
"remark-frontmatter": "^5.0.0",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"semver": "^7.7.1",
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
import { getAllPosts } from "@/blog-helpers";
|
||||
import { getAllPosts, getPostFileContent } from "@/blog-helpers";
|
||||
import { Feed } from "feed";
|
||||
|
||||
import {unified} from 'unified';
|
||||
import remarkParse from 'remark-parse';
|
||||
import remarkFrontmatter from "remark-frontmatter";
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkRehype from 'remark-rehype';
|
||||
import rehypeStringify from 'rehype-stringify';
|
||||
|
||||
import docsConfig from "../../../../docs-config";
|
||||
|
||||
function processPostContent(content: string): string {
|
||||
const processor = unified()
|
||||
.use(remarkParse)
|
||||
.use(remarkFrontmatter) // Parse YAML frontmatter
|
||||
.use(remarkGfm) // GitHub Flavored Markdown
|
||||
.use(remarkRehype) // Convert Markdown to HTML
|
||||
.use(rehypeStringify); // Convert HTML to string
|
||||
|
||||
const result = processor.processSync(content);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
export const dynamic = "force-static";
|
||||
export async function GET() {
|
||||
const allPosts = getAllPosts();
|
||||
@@ -30,7 +50,11 @@ export async function GET() {
|
||||
},
|
||||
});
|
||||
|
||||
allPosts.forEach(({ frontmatter, path }) => {
|
||||
allPosts.forEach(({ frontmatter, path, params }) => {
|
||||
// Get the content for the post and render the markdown to HTML
|
||||
const rawContent = getPostFileContent(params);
|
||||
const renderedContent = processPostContent(rawContent);
|
||||
|
||||
feed.addItem({
|
||||
title: frontmatter.title,
|
||||
id: `${docsConfig.siteUrl}${path}`,
|
||||
@@ -44,7 +68,7 @@ export async function GET() {
|
||||
link: `${docsConfig.siteUrl}/blog/`,
|
||||
},
|
||||
],
|
||||
// TODO: Include rendered Markdown as content.
|
||||
content: renderedContent,
|
||||
});
|
||||
});
|
||||
const xml = feed.atom1();
|
||||
|
||||
Reference in New Issue
Block a user