mirror of
https://github.com/fmhy/edit.git
synced 2026-02-18 09:11:33 +11:00
improve
This commit is contained in:
parent
c7f6b4a0be
commit
a290a25c8e
1 changed files with 27 additions and 26 deletions
|
|
@ -1,11 +1,7 @@
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { writeFileSync } from 'node:fs'
|
import { writeFileSync } from 'node:fs'
|
||||||
import { Feed } from 'feed'
|
import { Feed } from 'feed'
|
||||||
import {
|
import { createContentLoader, type ContentData, type SiteConfig } from 'vitepress'
|
||||||
createContentLoader,
|
|
||||||
type ContentData,
|
|
||||||
type SiteConfig
|
|
||||||
} from 'vitepress'
|
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import { meta } from '../constants'
|
import { meta } from '../constants'
|
||||||
|
|
||||||
|
|
@ -21,29 +17,34 @@ export async function generateFeed(config: SiteConfig): Promise<void> {
|
||||||
copyright: `Copyright (c) 2023-present FMHY`
|
copyright: `Copyright (c) 2023-present FMHY`
|
||||||
})
|
})
|
||||||
|
|
||||||
const posts: ContentData[] = await createContentLoader('posts/*.md', {
|
try {
|
||||||
excerpt: true,
|
const posts: ContentData[] = await createContentLoader('posts/*.md', {
|
||||||
render: true,
|
excerpt: true,
|
||||||
transform: (rawData) => {
|
render: true,
|
||||||
return rawData.sort((a, b) => {
|
transform: (rawData) => {
|
||||||
return (
|
return rawData.sort((a, b) => {
|
||||||
Number(new Date(b.frontmatter.date)) -
|
return (
|
||||||
Number(new Date(a.frontmatter.date))
|
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!
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}).load()
|
|
||||||
|
|
||||||
for (const { url, frontmatter, html } of posts) {
|
writeFileSync(path.join(config.outDir, 'feed.rss'), feed.rss2())
|
||||||
feed.addItem({
|
console.log('Generated rss feed.')
|
||||||
title: frontmatter.title as string,
|
} catch (error) {
|
||||||
id: `${meta.hostname}${url.replace(/\/\d+\./, '/')}`,
|
consola.error('Error generating rss feed:', error)
|
||||||
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.')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue