Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-rss): RSS Plugin #851

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-zoos-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspress/plugin-rss": patch
---

Introduce the RSS plugin for rspress
13 changes: 13 additions & 0 deletions e2e/fixtures/plugin-rss/doc/blog/bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Bar but Frontmatter
date: 2024-01-02 08:00:00
category: development
slug: bar
author:
name: Lamperouge
email: [email protected]
---

# Bar but Markdown

This is content
11 changes: 11 additions & 0 deletions e2e/fixtures/plugin-rss/doc/blog/foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
date: 2024-01-01 08:00:00
id: foo
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 @@
---
link-rss: blog
---

Nothing but should have rss <link>
12 changes: 12 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,12 @@
---
date: 2024-01-01 08:00:00
author:
- Lelouch
- Lamperouge
- name: Geass
link: /author/geass
---

# 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": "http://localhost:4173/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"
}
}
32 changes: 32 additions & 0 deletions e2e/fixtures/plugin-rss/rspress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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: {
type: 'rss',
/* use .xml for preview server */
filename: 'blog.xml',
},
},
{
id: 'releases',
test: '/releases/',
title: 'FooBar Releases',
output: { 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"
}
}
99 changes: 99 additions & 0 deletions e2e/tests/plugin-rss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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('`link-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);

await expect(
page.locator('rss>channel>link').textContent(),
).resolves.toBe(fixture.siteUrl);

const foo = page
.locator('rss>channel>item')
// frontmatter.id first
.filter({ has: page.locator('guid:text-is("foo")') });

// frontmatter.summary first
await expect(
foo.locator("xpath=/*[name()='content:encoded']").textContent(),
).resolves.toBe('This is summary\nSecond line of summary\n');

const bar = page
.locator('rss>channel>item')
// frontmatter.slug first
.filter({ has: page.locator('guid:text-is("bar")') });

// frontmatter.category first
await expect(bar.locator('>category').textContent()).resolves.toBe(
'development',
);

// frontmatter.author
await expect(bar.locator('>author').textContent()).resolves.toBe(
'[email protected] (Lamperouge)',
);
});
});
});
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):Generate RSS files with [feed](https://github.com/jpmonette/feed) for the document site.

## Community Plugins

Expand Down
Loading
Loading