Skip to content

Commit

Permalink
feat: support RSS subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
hacxy committed Jan 10, 2025
1 parent 32bf174 commit 32e042f
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 47 deletions.
5 changes: 5 additions & 0 deletions packages/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default defineConfigWithTheme<ThemeConfig>({
darkTheme: 'catppuccin_macchiato',
lightTheme: 'catppuccin_latte'
},
rss: {
title: 'Hacxy',
baseUrl: 'http://localhost:4173',
copyright: 'Copyright (c) 2024-present, Hacxy'
},
logo: '/logo.png',
search: {
provider: 'local',
Expand Down
22 changes: 21 additions & 1 deletion packages/theme/node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import type { DefaultTheme, RawConfigExports } from 'vitepress';
import type { DefaultTheme, Plugin, RawConfigExports, SiteConfig } from 'vitepress';
import { fileURLToPath } from 'node:url';
import { transformerTwoslash } from '@shikijs/vitepress-twoslash';
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
import { RssPlugin } from 'vitepress-plugin-rss';
import { NOT_ARTICLE_LAYOUTS } from './src/constants';
import { imgToImage, insertDocsHeaderInfo } from './src/utils/node/markdown';

function rss(): Plugin {
let resolveConfig: any;
return {
name: 'vitepress-plugin-rss',
enforce: 'pre',
configResolved(config: any) {
if (resolveConfig) {
return;
}
resolveConfig = config;
// 拿到用户的主题配置, 手动调用hook
const VPConfig: SiteConfig = config.vitepress;
return RssPlugin(VPConfig.site.themeConfig.rss).configResolved(config);
}
};
}

const baseConfig: RawConfigExports<DefaultTheme.Config> = {
markdown: {
config(md) {
Expand All @@ -19,6 +37,7 @@ const baseConfig: RawConfigExports<DefaultTheme.Config> = {
pageData.frontmatter.sidebar = false;
}
},

vite: {
ssr: {
noExternal: ['naive-ui']
Expand All @@ -35,6 +54,7 @@ const baseConfig: RawConfigExports<DefaultTheme.Config> = {
},
plugins: [
groupIconVitePlugin(),
rss()
],
build: {
chunkSizeWarningLimit: 2048
Expand Down
1 change: 1 addition & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"tinyglobby": "^0.2.10",
"typed.js": "^2.1.0",
"vitepress-plugin-group-icons": "^1.3.2",
"vitepress-plugin-rss": "^0.3.0",
"vue": "^3.4.21"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true,
"baseUrl": "./",
"rootDir": "./",
Expand Down
3 changes: 3 additions & 0 deletions packages/theme/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GiscusProps, Theme as GiscusTheme } from '@giscus/vue';
import type { DefaultTheme, Theme } from 'vitepress';
import type { RSSOptions } from 'vitepress-plugin-rss';
import Layout from '../src/Layout.vue';

export interface SidebarAutoMulti {
Expand All @@ -21,6 +22,8 @@ declare interface ThemeConfig extends Omit<DefaultTheme.Config, 'sidebar'> {
* Giscus Comment
*/
comment?: Comment

rss?: RSSOptions
// /**
// * Is the progress bar enabled
// * @default true
Expand Down
Loading

0 comments on commit 32e042f

Please sign in to comment.