Skip to content

Commit

Permalink
feat(plugin-rss): add rss plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
xc2 committed Mar 27, 2024
1 parent 5b98eaa commit 836e9fe
Show file tree
Hide file tree
Showing 37 changed files with 900 additions and 2 deletions.
6 changes: 6 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"clientKind": "git",
"defaultBranch": "main",
"useIgnoreFile": true
},
"javascript": {
"formatter": {
"quoteStyle": "single",
Expand Down
8 changes: 8 additions & 0 deletions e2e/fixtures/plugin-rss/doc/blog/bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Bar but Frontmatter
date: 2024-01-02 08:00:00
---

# Bar but Markdown

This is content
10 changes: 10 additions & 0 deletions e2e/fixtures/plugin-rss/doc/blog/foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
date: 2024-01-01 08:00:00
summary: |
This is summary
Second line of summary
---

# Foo

This is content
5 changes: 5 additions & 0 deletions e2e/fixtures/plugin-rss/doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
show-rss: blog
---

Nothing but should have rss <link>
7 changes: 7 additions & 0 deletions e2e/fixtures/plugin-rss/doc/releases/1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
date: 2024-01-01 08:00:00
---

# Release 1.0.0

Nothing Happened
5 changes: 5 additions & 0 deletions e2e/fixtures/plugin-rss/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"base": "/sub/",
"siteUrl": "https://example.com/sub/",
"title": "FooBar"
}
17 changes: 17 additions & 0 deletions e2e/fixtures/plugin-rss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@rspress-fixture/doc-plugin-rss",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
"preview": "rspress preview"
},
"dependencies": {
"@rspress/plugin-rss": "workspace:*",
"rspress": "workspace:*"
},
"devDependencies": {
"@types/node": "^14"
}
}
31 changes: 31 additions & 0 deletions e2e/fixtures/plugin-rss/rspress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as NodePath from 'path';
import { pluginRss } from '@rspress/plugin-rss';
import { defineConfig } from 'rspress/config';
import fixture from './fixture.json';

export default defineConfig({
root: NodePath.resolve(__dirname, 'doc'),
title: fixture.title,
base: fixture.base,
plugins: [
pluginRss({
siteUrl: fixture.siteUrl,
feed: [
{
id: 'blog',
test: /^\/blog\//,
output: {
/* use .xml for preview server */
filename: 'blog.xml',
},
},
{
id: 'releases',
test: /^\/releases\//,
title: 'FooBar Releases',
output: { type: 'atom', filename: 'feed.xml', dir: 'releases' },
},
],
}),
],
});
8 changes: 8 additions & 0 deletions e2e/fixtures/plugin-rss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"module": "Node16"
}
}
70 changes: 70 additions & 0 deletions e2e/tests/plugin-rss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import path from 'path';
import { expect, test } from '@playwright/test';
import fixture from '../fixtures/plugin-rss/fixture.json';
import {
getPort,
killProcess,
runBuildCommand,
runPreviewCommand,
} from '../utils/runCommands';

const appDir = path.resolve(__dirname, '../fixtures/plugin-rss');
const { siteUrl } = fixture;

test.describe('plugin rss test', async () => {
let appPort: number;
let app: unknown;
let prefix: string;
test.beforeAll(async () => {
appPort = await getPort();
await runBuildCommand(appDir);
app = await runPreviewCommand(appDir, appPort);
prefix = `http://localhost:${appPort}${fixture.base}`;
});

test.afterAll(async () => {
if (app) {
await killProcess(app);
}
});

test('`show-rss` should add rss <link> to this page', async ({ page }) => {
await page.goto(`${prefix}`, { waitUntil: 'networkidle' });

const link = page.locator('link[rel="alternative"]', {});

await expect(link.getAttribute('href')).resolves.toBe(
`${siteUrl}rss/blog.xml`,
);
});

test('should add rss <link> to pages matched', async ({ page }) => {
await page.goto(`${prefix}blog/foo`, { waitUntil: 'networkidle' });

const link = page.locator('link[rel="alternative"]', {});

await expect(link.getAttribute('href')).resolves.toBe(
`${siteUrl}rss/blog.xml`,
);
});

test('should change output dir if dir is given', async ({ page }) => {
// for: output.dir, output.type
await page.goto(`${prefix}releases/feed.xml`, { waitUntil: 'networkidle' });

const feed = page.locator('feed>id');

await expect(feed.textContent()).resolves.toBe('releases');
});

test.describe('rss content', async () => {
// todo: add more tests for rss content
test('should has expected content', async ({ page }) => {
await page.goto(`${prefix}rss/blog.xml`, { waitUntil: 'networkidle' });

await expect(
page.locator('rss>channel>title').textContent(),
).resolves.toBe(fixture.title);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"typedoc",
"preview",
"playground",
"rss",
"shiki"
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Official plugins include:
- [@rspress/plugin-preview](./preview): Support preview of code blocks in Markdown/MDX.
- [@rspress/plugin-playground](./playground): Provide a real-time playground to preview the code blocks in Markdown/MDX files.
- [@rspress/plugin-shiki](./shiki): Integrates [Shiki](https://github.com/shikijs/shiki) for code syntax highlighting.
- [@rspress/plugin-rss](./rss):todo(xc2)

## Community Plugins

Expand Down
11 changes: 11 additions & 0 deletions packages/document/docs/en/plugin/official-plugins/rss.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @rspress/plugin-rss

import { SourceCode, PackageManagerTabs } from 'rspress/theme';

<SourceCode href="https://github.com/web-infra-dev/rspress/tree/main/packages/plugin-rss" />

todo(xc2)

## Installation

<PackageManagerTabs command="add @rspress/plugin-rss -D" />
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"typedoc",
"preview",
"playground",
"rss",
"shiki"
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [@rspress/plugin-preview](./preview):支持代码块中的组件预览。
- [@rspress/plugin-playground](./playground):支持代码块中的组件预览,并提供实时 Playground。
- [@rspress/plugin-shiki](./shiki):集成 [Shiki](https://github.com/shikijs/shiki) 来进行代码高亮的插件。
- [@rspress/plugin-rss](./rss):todo(xc2)

## 社区插件

Expand Down
11 changes: 11 additions & 0 deletions packages/document/docs/zh/plugin/official-plugins/rss.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @rspress/plugin-rss

import { SourceCode, PackageManagerTabs } from 'rspress/theme';

<SourceCode href="https://github.com/web-infra-dev/rspress/tree/main/packages/plugin-rss" />

todo(xc2)

## Installation

<PackageManagerTabs command="add @rspress/plugin-rss -D" />
21 changes: 21 additions & 0 deletions packages/plugin-rss/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-present Bytedance, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions packages/plugin-rss/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @rspress/plugin-rss

> RSS plugin for rspress
[Documentation](https://rspress.dev/plugin/official-plugins/rss)
34 changes: 34 additions & 0 deletions packages/plugin-rss/modern.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
PartialBaseBuildConfig,
defineConfig,
moduleTools,
} from '@modern-js/module-tools';

const base = {
buildType: 'bundle',
format: 'cjs',
sourceMap: true,
target: 'es2020',
} satisfies PartialBaseBuildConfig;

// https://modernjs.dev/module-tools/en/api
export default defineConfig({
buildConfig: [
{
...base,
format: 'cjs',
dts: false,
esbuildOptions: options => ({
...options,
outExtension: { '.js': '.cjs' },
}),
},
{ ...base, format: 'esm', dts: false, autoExtension: true },
{
...base,
format: 'esm',
dts: { respectExternal: false, only: true },
},
],
plugins: [moduleTools()],
});
67 changes: 67 additions & 0 deletions packages/plugin-rss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "@rspress/plugin-rss",
"version": "1.16.1",
"description": "A plugin for rss generation for rspress",
"bugs": "https://github.com/web-infra-dev/rspress/issues",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rspress",
"directory": "packages/plugin-rss"
},
"license": "MIT",
"jsnext:source": "./src/index.ts",
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"exports": {
".": {
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
},
"./FeedsAnnotations": "./static/global-components/FeedsAnnotations"
},
"scripts": {
"dev": "modern build -w",
"build": "modern build",
"reset": "rimraf ./**/node_modules",
"lint": "modern lint",
"change": "modern change",
"bump": "modern bump",
"pre": "modern pre",
"change-status": "modern change-status",
"gen-release-note": "modern gen-release-note",
"release": "modern release",
"new": "modern new",
"test": "vitest run --passWithNoTests",
"upgrade": "modern upgrade"
},
"engines": {
"node": ">=14.17.6"
},
"dependencies": {
"feed": "^4.2.2"
},
"devDependencies": {
"@types/node": "^18.11.17",
"@types/react": "^18",
"@rspress/shared": "workspace:*",
"@rspress/runtime": "workspace:*",
"react": "^18",
"typescript": "^5"
},
"peerDependencies": {
"react": ">=17.0.0",
"@types/react": ">=17.0.0",
"@rspress/runtime": "^1.0.0"
},
"files": [
"dist",
"static"
],
"publishConfig": {
"access": "public",
"provenance": true,
"registry": "https://registry.npmjs.org/"
}
}
5 changes: 5 additions & 0 deletions packages/plugin-rss/src/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PluginName = '@rspress/plugin-rss';

export const PluginComponents = {
FeedsAnnotations: '@rspress/plugin-rss/FeedsAnnotations',
} as const;
Loading

0 comments on commit 836e9fe

Please sign in to comment.