docs: add blog rss feed on docs build (#15032)

This commit is contained in:
leimonio 2023-11-20 14:22:10 +00:00 committed by GitHub
parent b9ee620108
commit dc494ad416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 4 deletions

View File

@ -0,0 +1,49 @@
import path from 'path'
import { writeFileSync } from 'fs'
import { Feed } from 'feed'
import { createContentLoader, type SiteConfig } from 'vitepress'
const siteUrl = 'https://vitejs.dev'
const blogUrl = `${siteUrl}/blog`
export const buildEnd = async (config: SiteConfig) => {
const feed = new Feed({
title: 'Vite',
description: 'Next Generation Frontend Tooling',
id: blogUrl,
link: blogUrl,
language: 'en',
image: 'https://vitejs.dev/og-image.png',
favicon: 'https://vitejs.dev/logo.svg',
copyright: 'Copyright © 2019-present Evan You & Vite Contributors',
})
const posts = await createContentLoader('blog/*.md', {
excerpt: true,
render: true,
}).load()
posts.sort(
(a, b) =>
+new Date(b.frontmatter.date as string) -
+new Date(a.frontmatter.date as string),
)
for (const { url, excerpt, frontmatter, html } of posts) {
feed.addItem({
title: frontmatter.title,
id: `${siteUrl}${url}`,
link: `${siteUrl}${url}`,
description: excerpt,
content: html,
author: [
{
name: frontmatter.author.name,
},
],
date: frontmatter.date,
})
}
writeFileSync(path.join(config.outDir, 'blog.rss'), feed.rss2())
}

View File

@ -1,4 +1,5 @@
import { defineConfig, DefaultTheme } from 'vitepress'
import { buildEnd } from './buildEnd.config'
const ogDescription = 'Next Generation Frontend Tooling'
const ogImage = 'https://vitejs.dev/og-image.png'
@ -66,6 +67,10 @@ export default defineConfig({
head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }],
[
'link',
{ rel: 'alternate', type: 'application/rss+xml', href: '/blog.rss' },
],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:title', content: ogTitle }],
['meta', { property: 'og:image', content: ogImage }],
@ -325,4 +330,5 @@ export default defineConfig({
level: [2, 3],
},
},
buildEnd,
})

View File

@ -1,4 +1,7 @@
---
title: Announcing Vite 2.0
author:
- name: The Vite Team
sidebar: false
date: 2021-02-16
head:

View File

@ -1,6 +1,9 @@
---
sidebar: false
title: Vite 3.0 is out!
author:
name: The Vite Team
date: 2022-07-23
sidebar: false
head:
- - meta
- property: og:type

View File

@ -1,6 +1,9 @@
---
sidebar: false
title: Vite 4.3 is out!
author:
name: The Vite Team
date: 2023-04-20
sidebar: false
head:
- - meta
- property: og:type

View File

@ -1,6 +1,9 @@
---
sidebar: false
title: Vite 4.0 is out!
author:
name: The Vite Team
date: 2022-12-09
sidebar: false
head:
- - meta
- property: og:type

View File

@ -1,6 +1,9 @@
---
sidebar: false
title: Vite 5.0 is out!
author:
name: The Vite Team
date: 2023-11-16
sidebar: false
head:
- - meta
- property: og:type

View File

@ -69,6 +69,7 @@
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-regexp": "^2.1.1",
"execa": "^8.0.1",
"feed": "^4.2.2",
"fs-extra": "^11.1.1",
"lint-staged": "^15.1.0",
"npm-run-all2": "^6.1.1",

View File

@ -111,6 +111,9 @@ importers:
execa:
specifier: ^8.0.1
version: 8.0.1
feed:
specifier: ^4.2.2
version: 4.2.2
fs-extra:
specifier: ^11.1.1
version: 11.1.1
@ -6001,6 +6004,13 @@ packages:
dependencies:
reusify: 1.0.4
/feed@4.2.2:
resolution: {integrity: sha512-u5/sxGfiMfZNtJ3OvQpXcvotFpYkL0n9u9mM2vkui2nGo8b4wvDkJ8gAkYqbA8QpGyFCv3RK0Z+Iv+9veCS9bQ==}
engines: {node: '>=0.4.0'}
dependencies:
xml-js: 1.6.11
dev: true
/fetch-blob@3.1.5:
resolution: {integrity: sha512-N64ZpKqoLejlrwkIAnb9iLSA3Vx/kjgzpcDhygcqJ2KKjky8nCgUQ+dzXtbrLaWZGZNmNfQTsiQ0weZ1svglHg==}
engines: {node: ^12.20 || >= 14.13}
@ -10120,6 +10130,13 @@ packages:
optional: true
dev: true
/xml-js@1.6.11:
resolution: {integrity: sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==}
hasBin: true
dependencies:
sax: 1.3.0
dev: true
/xtend@4.0.2:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}