-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9baef43
commit f8572d0
Showing
9 changed files
with
103 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
|
||
export * from "./meta"; | ||
export * from "./opengraph"; | ||
export * from "./rss"; | ||
export * from "./satoriConfig"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import path from "node:path"; | ||
import { writeFileSync } from "node:fs"; | ||
import { Feed } from "feed"; | ||
import { createContentLoader, type ContentData, type SiteConfig } from "vitepress"; | ||
import consola from "consola"; | ||
import { meta } from "../constants"; | ||
|
||
export async function generateFeed(config: SiteConfig): Promise<void> { | ||
const feed: Feed = new Feed({ | ||
id: meta.hostname, | ||
link: meta.hostname, | ||
title: `FMHY blog`, | ||
description: meta.description, | ||
language: "en-US", | ||
image: "https://github.com/fmhy.png", | ||
favicon: `${meta.hostname}/favicon.ico`, | ||
copyright: `Copyright (c) 2023-present FMHY`, | ||
}); | ||
|
||
const posts: ContentData[] = await createContentLoader("posts/*.md", { | ||
excerpt: true, | ||
render: true, | ||
transform: (rawData) => { | ||
return rawData.sort((a, b) => { | ||
return Number(new Date(b.frontmatter.date)) - Number(new Date(a.frontmatter.date)); | ||
}); | ||
}, | ||
}).load(); | ||
|
||
for (const { url, frontmatter, html } of posts) { | ||
feed.addItem({ | ||
title: frontmatter.title as string, | ||
id: `${meta.hostname}${url.replace(/\/\d+\./, "/")}`, | ||
link: `${meta.hostname}${url.replace(/\/\d+\./, "/")}`, | ||
date: frontmatter.date, | ||
content: html!, | ||
}); | ||
} | ||
|
||
writeFileSync(path.join(config.outDir, "feed.rss"), feed.rss2()); | ||
return consola.info("Generated rss feed."); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.