From 33e0609cc6551a8c0d0349ffd9142ef417253f58 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 3 Jun 2022 22:09:22 +0800 Subject: [PATCH] feat: rename feed plugin --- docs/feed/package.json | 2 +- docs/feed/src/.vuepress/config.ts | 2 +- docs/feed/src/README.md | 10 +- docs/feed/src/guide.md | 2 +- docs/feed/src/zh/README.md | 10 +- docs/feed/src/zh/guide.md | 2 +- docs/theme/src/config/plugin/README.md | 2 +- docs/theme/src/guide/README.md | 2 +- docs/theme/src/guide/feature/README.md | 2 +- docs/theme/src/guide/feature/feed.md | 4 +- docs/theme/src/zh/config/plugin/README.md | 2 +- docs/theme/src/zh/guide/README.md | 2 +- docs/theme/src/zh/guide/feature/README.md | 2 +- docs/theme/src/zh/guide/feature/feed.md | 2 +- package.json | 2 +- packages/feed/README.md | 8 +- .../__tests__/__snapshots__/atom.spec.ts.snap | 2 +- .../__tests__/__snapshots__/rss.spec.ts.snap | 10 +- packages/feed/package.json | 2 +- packages/feed/src/node/atom/index.ts | 3 +- packages/feed/src/node/generator.ts | 10 +- packages/feed/src/node/json/index.ts | 2 +- packages/feed/src/node/options.ts | 23 ++-- packages/feed/src/node/page.ts | 24 ++-- packages/feed/src/node/plugin.ts | 16 +-- packages/feed/src/node/rss/index.ts | 4 +- packages/feed/src/node/utils.ts | 111 +----------------- packages/theme-types/package.json | 2 +- packages/theme-types/types/index.d.ts | 2 +- packages/theme/node/plugins.ts | 4 +- packages/theme/package.json | 2 +- packages/theme/types/extend.d.ts | 2 +- packages/theme/types/theme/plugin.d.ts | 2 +- pnpm-lock.yaml | 12 +- 34 files changed, 92 insertions(+), 197 deletions(-) diff --git a/docs/feed/package.json b/docs/feed/package.json index 21978e36e..7108c5a17 100644 --- a/docs/feed/package.json +++ b/docs/feed/package.json @@ -2,7 +2,7 @@ "name": "feed-docs", "version": "1.30.0", "private": true, - "description": "Docs for @mr-hope/vuepress-plugin-feed", + "description": "Docs for vuepress-plugin-feed1", "license": "MIT", "author": { "name": "Mr.Hope", diff --git a/docs/feed/src/.vuepress/config.ts b/docs/feed/src/.vuepress/config.ts index fa8c14e19..8d1c2332e 100644 --- a/docs/feed/src/.vuepress/config.ts +++ b/docs/feed/src/.vuepress/config.ts @@ -157,7 +157,7 @@ export default hope.config({ color: "#ffffff", }, manifest: { - name: "@mr-hope/vuepress-plugin-feed", + name: "vuepress-plugin-feed1", short_name: "feed plugin", icons: [ { diff --git a/docs/feed/src/README.md b/docs/feed/src/README.md index 60ea83f2e..58b7b1c6e 100644 --- a/docs/feed/src/README.md +++ b/docs/feed/src/README.md @@ -3,7 +3,7 @@ home: true title: Home icon: home heroImage: /logo.svg -heroText: "@mr-hope/vuepress-plugin-feed" +heroText: "vuepress-plugin-feed1" tagline: Feed plugin for vuepress action: - text: Guide 💡 @@ -26,7 +26,7 @@ copyrightText: false ::: code-group-item yarn ```bash -yarn add -D @mr-hope/vuepress-plugin-feed +yarn add -D vuepress-plugin-feed1 ``` ::: @@ -34,7 +34,7 @@ yarn add -D @mr-hope/vuepress-plugin-feed ::: code-group-item npm ```bash -npm i -D @mr-hope/vuepress-plugin-feed +npm i -D vuepress-plugin-feed1 ``` ::: @@ -52,7 +52,7 @@ npm i -D @mr-hope/vuepress-plugin-feed export default { plugins: [ [ - "@mr-hope/feed", + "feed1", { // your options }, @@ -70,7 +70,7 @@ export default { module.exports = { plugins: [ [ - "@mr-hope/feed", + "feed1", { // your options }, diff --git a/docs/feed/src/guide.md b/docs/feed/src/guide.md index 778836aaa..b14c9f13e 100644 --- a/docs/feed/src/guide.md +++ b/docs/feed/src/guide.md @@ -5,7 +5,7 @@ icon: creative ## Usage -The `@mr-hope/vuepress-plugin-feed` plugin can generate feed files in the following three formats for you: +The `vuepress-plugin-feed1` plugin can generate feed files in the following three formats for you: - Atom 1.0 - JSON 1.1 diff --git a/docs/feed/src/zh/README.md b/docs/feed/src/zh/README.md index 0870d195f..bcb04fe9e 100644 --- a/docs/feed/src/zh/README.md +++ b/docs/feed/src/zh/README.md @@ -3,7 +3,7 @@ home: true title: 主页 icon: home heroImage: /logo.svg -heroText: "@mr-hope/vuepress-plugin-feed" +heroText: "vuepress-plugin-feed1" tagline: 为 VuePress 提供 Feed 生成 action: - text: 快速上手 💡 @@ -26,7 +26,7 @@ copyrightText: false ::: code-group-item yarn ```bash -yarn add -D @mr-hope/vuepress-plugin-feed +yarn add -D vuepress-plugin-feed1 ``` ::: @@ -34,7 +34,7 @@ yarn add -D @mr-hope/vuepress-plugin-feed ::: code-group-item npm ```bash -npm i -D @mr-hope/vuepress-plugin-feed +npm i -D vuepress-plugin-feed1 ``` ::: @@ -48,7 +48,7 @@ npm i -D @mr-hope/vuepress-plugin-feed module.exports = { plugins: [ [ - "@mr-hope/feed", + "feed1", { // 你的选项 }, @@ -66,7 +66,7 @@ module.exports = { export default { plugins: [ [ - "@mr-hope/feed", + "feed1", { // 你的选项 }, diff --git a/docs/feed/src/zh/guide.md b/docs/feed/src/zh/guide.md index d15b24b5d..ad5d91554 100644 --- a/docs/feed/src/zh/guide.md +++ b/docs/feed/src/zh/guide.md @@ -5,7 +5,7 @@ icon: creative ## 使用 -`@mr-hope/vuepress-plugin-feed` 插件可为你生成以下三种格式的 feed 文件: +`vuepress-plugin-feed1` 插件可为你生成以下三种格式的 feed 文件: - Atom 1.0 - JSON 1.1 diff --git a/docs/theme/src/config/plugin/README.md b/docs/theme/src/config/plugin/README.md index 6bd5764b1..cee787e9c 100644 --- a/docs/theme/src/config/plugin/README.md +++ b/docs/theme/src/config/plugin/README.md @@ -21,7 +21,7 @@ tags: - [vuepress-plugin-copy-code1][copy-code]: Provide copy button for code blocks -- [@mr-hope/vuepress-plugin-feed][feed]: Feed generation support +- [vuepress-plugin-feed1][feed]: Feed generation support - [@mr-hope/vuepress-plugin-git][git]: Info plugin based on git diff --git a/docs/theme/src/guide/README.md b/docs/theme/src/guide/README.md index b85ff7438..d22410ffe 100644 --- a/docs/theme/src/guide/README.md +++ b/docs/theme/src/guide/README.md @@ -121,7 +121,7 @@ The theme also includes the following plugins, you can use them in other themes - [vuepress-plugin-copy-code1][copy-code]: Provide copy button for code blocks -- [@mr-hope/vuepress-plugin-feed][feed]: Feed support +- [vuepress-plugin-feed1][feed]: Feed support - [@mr-hope/vuepress-plugin-git][git]: Info plugin based on git diff --git a/docs/theme/src/guide/feature/README.md b/docs/theme/src/guide/feature/README.md index c6fc8aeb6..39572869d 100644 --- a/docs/theme/src/guide/feature/README.md +++ b/docs/theme/src/guide/feature/README.md @@ -44,7 +44,7 @@ The theme includes the following plugins, you can use them directly in other the - [vuepress-plugin-copy-code1][copy-code]: Provide copy button for code blocks -- [@mr-hope/vuepress-plugin-feed][feed]: Feed support +- [vuepress-plugin-feed1][feed]: Feed support - [@mr-hope/vuepress-plugin-git][git]: Info based on git diff --git a/docs/theme/src/guide/feature/feed.md b/docs/theme/src/guide/feature/feed.md index dc46aa3d0..8d95ad94b 100644 --- a/docs/theme/src/guide/feature/feed.md +++ b/docs/theme/src/guide/feature/feed.md @@ -7,9 +7,9 @@ tags: - feed --- -The theme will enable feed generation support using [`@mr-hope/vuepress-plugin-feed`](https://vuepress-theme-hope.github.io/v1/feed/) by default. +The theme will enable feed generation support using [`vuepress-plugin-feed1`](https://vuepress-theme-hope.github.io/v1/feed/) by default. -`@mr-hope/vuepress-plugin-feed` plugin will automatically generate feed in the following three formats for you +`vuepress-plugin-feed1` plugin will automatically generate feed in the following three formats for you - Atom 1.0 (Default output: atom.xml) - JSON 1.1 (Default output: feed.json) diff --git a/docs/theme/src/zh/config/plugin/README.md b/docs/theme/src/zh/config/plugin/README.md index 0812a88e1..3ac7d03f2 100644 --- a/docs/theme/src/zh/config/plugin/README.md +++ b/docs/theme/src/zh/config/plugin/README.md @@ -21,7 +21,7 @@ tags: - [vuepress-plugin-copy-code1][copy-code]: 提供一键复制代码块功能。 -- [@mr-hope/vuepress-plugin-feed][feed]: 提供 Feed 生成 +- [vuepress-plugin-feed1][feed]: 提供 Feed 生成 - [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件 diff --git a/docs/theme/src/zh/guide/README.md b/docs/theme/src/zh/guide/README.md index 05b947568..085fc7d0a 100644 --- a/docs/theme/src/zh/guide/README.md +++ b/docs/theme/src/zh/guide/README.md @@ -121,7 +121,7 @@ tags: - [vuepress-plugin-copy-code1][copy-code]: 提供一键复制代码块功能。 -- [@mr-hope/vuepress-plugin-feed][feed]: Feed 支持 +- [vuepress-plugin-feed1][feed]: Feed 支持 - [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件 diff --git a/docs/theme/src/zh/guide/feature/README.md b/docs/theme/src/zh/guide/feature/README.md index 4975b356d..96edf9496 100644 --- a/docs/theme/src/zh/guide/feature/README.md +++ b/docs/theme/src/zh/guide/feature/README.md @@ -44,7 +44,7 @@ tags: - [vuepress-plugin-copy-code1][copy-code]: 提供一键复制代码块功能。 -- [@mr-hope/vuepress-plugin-feed][feed]: Feed 支持 +- [vuepress-plugin-feed1][feed]: Feed 支持 - [@mr-hope/vuepress-plugin-git][git]: 基于 Git 的页面信息插件 diff --git a/docs/theme/src/zh/guide/feature/feed.md b/docs/theme/src/zh/guide/feature/feed.md index 686d97dcd..6f6307671 100644 --- a/docs/theme/src/zh/guide/feature/feed.md +++ b/docs/theme/src/zh/guide/feature/feed.md @@ -7,7 +7,7 @@ tags: - feature --- -`vuepress-theme-hope` 通过内置 [`@mr-hope/vuepress-plugin-feed`](https://vuepress-theme-hope.github.io/v1/feed/zh/) 插件来为你提供 feed 支持。 +`vuepress-theme-hope` 通过内置 [`vuepress-plugin-feed1`](https://vuepress-theme-hope.github.io/v1/feed/zh/) 插件来为你提供 feed 支持。 主题会自动为你生成以下三种格式的 feed 文件: diff --git a/package.json b/package.json index f9cc55b4b..33d0c6231 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "@commitlint/cli": "17.0.2", "@commitlint/config-conventional": "17.0.2", "@mr-hope/vuepress-plugin-components": "workspace:*", - "@mr-hope/vuepress-plugin-feed": "workspace:*", "@mr-hope/vuepress-plugin-git": "workspace:*", "@mr-hope/vuepress-plugin-pwa": "workspace:*", "@mr-hope/vuepress-plugin-reading-time": "workspace:*", @@ -101,6 +100,7 @@ "vuepress-plugin-add-this": "workspace:*", "vuepress-plugin-comment1": "workspace:*", "vuepress-plugin-copy-code1": "workspace:*", + "vuepress-plugin-feed1": "workspace:*", "vuepress-plugin-md-enhance": "workspace:*", "vuepress-plugin-photo-swipe": "workspace:*", "vuepress-shared": "workspace:*", diff --git a/packages/feed/README.md b/packages/feed/README.md index 15a32bef5..3aa4623ae 100644 --- a/packages/feed/README.md +++ b/packages/feed/README.md @@ -2,10 +2,10 @@

-

@mr-hope/vuepress-plugin-feed

+

vuepress-plugin-feed1

VuePress feed plugin 📡 / VuePress Feed 插件 📡

-[![Version](https://img.shields.io/npm/v/@mr-hope/vuepress-plugin-feed.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@mr-hope/vuepress-plugin-feed.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/@mr-hope/vuepress-plugin-feed?style=flat-square&logo=npm)](https://www.npmjs.com/package/@mr-hope/vuepress-plugin-feed) +[![Version](https://img.shields.io/npm/v/vuepress-plugin-feed1.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/vuepress-plugin-feed1.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/vuepress-plugin-feed1?style=flat-square&logo=npm)](https://www.npmjs.com/package/vuepress-plugin-feed1) @@ -22,11 +22,11 @@ VuePress 2 is recommanded to start new project. You should use [`vuepress-plugin ## Usage / 使用 ```bash -npm i -D @mr-hope/vuepress-plugin-feed +npm i -D vuepress-plugin-feed1 ``` or ```bash -yarn add -D @mr-hope/vuepress-plugin-feed +yarn add -D vuepress-plugin-feed1 ``` diff --git a/packages/feed/__tests__/__snapshots__/atom.spec.ts.snap b/packages/feed/__tests__/__snapshots__/atom.spec.ts.snap index 3505153ae..8c01dd2ab 100644 --- a/packages/feed/__tests__/__snapshots__/atom.spec.ts.snap +++ b/packages/feed/__tests__/__snapshots__/atom.spec.ts.snap @@ -12,7 +12,7 @@ exports[`Atom 1.0 > should generate a valid feed 1`] = ` https://example.com/johndoe?link=sanitized&value=2 2013-07-13T23:00:00.000Z - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 diff --git a/packages/feed/__tests__/__snapshots__/rss.spec.ts.snap b/packages/feed/__tests__/__snapshots__/rss.spec.ts.snap index eefc9ec34..5371408a3 100644 --- a/packages/feed/__tests__/__snapshots__/rss.spec.ts.snap +++ b/packages/feed/__tests__/__snapshots__/rss.spec.ts.snap @@ -11,7 +11,7 @@ exports[`RSS 2.0 > should generate a valid feed 1`] = ` en Wed, 10 Jul 2013 23:00:00 GMT Sat, 13 Jul 2013 23:00:00 GMT - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 https://validator.w3.org/feed/docs/rss2.html All rights reserved 2013, John Doe 60 @@ -49,7 +49,7 @@ exports[`RSS 2.0 > should generate a valid feed with audio 1`] = ` en Wed, 10 Jul 2013 23:00:00 GMT Sat, 13 Jul 2013 23:00:00 GMT - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 https://validator.w3.org/feed/docs/rss2.html All rights reserved 2013, John Doe 60 @@ -126,7 +126,7 @@ exports[`RSS 2.0 > should generate a valid feed with enclosure 1`] = ` en Wed, 10 Jul 2013 23:00:00 GMT Sat, 13 Jul 2013 23:00:00 GMT - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 https://validator.w3.org/feed/docs/rss2.html All rights reserved 2013, John Doe 60 @@ -190,7 +190,7 @@ exports[`RSS 2.0 > should generate a valid feed with image properties 1`] = ` en Wed, 10 Jul 2013 23:00:00 GMT Sat, 13 Jul 2013 23:00:00 GMT - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 https://validator.w3.org/feed/docs/rss2.html All rights reserved 2013, John Doe 60 @@ -241,7 +241,7 @@ exports[`RSS 2.0 > should generate a valid feed with video 1`] = ` en Wed, 10 Jul 2013 23:00:00 GMT Sat, 13 Jul 2013 23:00:00 GMT - @mr-hope/vuepress-plugin-feed + vuepress-plugin-feed1 https://validator.w3.org/feed/docs/rss2.html All rights reserved 2013, John Doe 60 diff --git a/packages/feed/package.json b/packages/feed/package.json index 0ff94a7f1..711c5b404 100644 --- a/packages/feed/package.json +++ b/packages/feed/package.json @@ -1,5 +1,5 @@ { - "name": "@mr-hope/vuepress-plugin-feed", + "name": "vuepress-plugin-feed1", "version": "1.30.0", "description": "Feed plugin for vuepress-theme-hope", "keywords": [ diff --git a/packages/feed/src/node/atom/index.ts b/packages/feed/src/node/atom/index.ts index e04e597f4..bac805a80 100644 --- a/packages/feed/src/node/atom/index.ts +++ b/packages/feed/src/node/atom/index.ts @@ -1,5 +1,6 @@ +import { encodeCDATA, encodeXML } from "vuepress-shared"; import { js2xml } from "xml-js"; -import { encodeCDATA, encodeXML, FEED_GENERATOR } from "../utils"; +import { FEED_GENERATOR } from "../utils"; import type { Feed } from "../feed"; import type { FeedAuthor, FeedCategory } from "../../types"; diff --git a/packages/feed/src/node/generator.ts b/packages/feed/src/node/generator.ts index 98f53593b..c773692c1 100644 --- a/packages/feed/src/node/generator.ts +++ b/packages/feed/src/node/generator.ts @@ -5,7 +5,7 @@ import { dirname, resolve } from "path"; import { Feed } from "./feed"; import { getFeedChannelOption, getFilename, getFeedLinks } from "./options"; import { FeedPage } from "./page"; -import { compareDate, success } from "./utils"; +import { compareDate, logger } from "./utils"; import type { Context, Page } from "vuepress-typings"; import type { ResolvedFeedOptionsMap } from "./options"; @@ -78,7 +78,7 @@ export class FeedGenerator { } } - success( + logger.succeed( `added ${cyan(`${count} page(s)`)} as feed item(s) in route ${cyan( localePath )}` @@ -105,7 +105,7 @@ export class FeedGenerator { await ensureDir(dirname(filePath)); await outputFile(filePath, feed.atom()); - success( + logger.succeed( `Atom feed file generated and saved to ${cyan( atomOutputFilename )}` @@ -119,7 +119,7 @@ export class FeedGenerator { await ensureDir(dirname(filePath)); await outputFile(filePath, feed.json()); - success( + logger.succeed( `JSON feed file generated and saved to ${cyan( jsonOutputFilename )}` @@ -133,7 +133,7 @@ export class FeedGenerator { await ensureDir(dirname(filePath)); await outputFile(filePath, feed.rss()); - success( + logger.succeed( `RSS feed file generated and saved to ${cyan(rssOutputFilename)}` ); } diff --git a/packages/feed/src/node/json/index.ts b/packages/feed/src/node/json/index.ts index 864614f61..4bab63c98 100644 --- a/packages/feed/src/node/json/index.ts +++ b/packages/feed/src/node/json/index.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { stripTags } from "../stripTags"; +import { stripTags } from "vuepress-shared"; import type { Feed } from "../feed"; import type { FeedAuthor } from "../../types"; diff --git a/packages/feed/src/node/options.ts b/packages/feed/src/node/options.ts index fb5bf91fb..d303eb4fb 100644 --- a/packages/feed/src/node/options.ts +++ b/packages/feed/src/node/options.ts @@ -1,4 +1,10 @@ -import { deepAssign, getRootLang } from "vuepress-shared"; +import { + deepAssign, + getRootLang, + removeEndingSlash, + removeLeadingSlash, +} from "vuepress-shared"; + import { compareDate, resolveUrl } from "./utils"; import type { Context, Page } from "vuepress-typings"; @@ -16,7 +22,7 @@ export type ResolvedFeedOptionsMap = Record; export const ensureHostName = (options: Partial): boolean => { // make sure hostname do not end with `/` if (options.hostname) { - options.hostname = options.hostname.replace(/\/$/u, ""); + options.hostname = removeEndingSlash(options.hostname); return true; } @@ -34,7 +40,7 @@ export const checkOutput = (options: Partial): boolean => Boolean(options.atom || options.json || options.rss); export const getFeedOptions = ( - context: Context, + { siteConfig }: Context, options: FeedOptions ): ResolvedFeedOptionsMap => Object.fromEntries( @@ -42,7 +48,7 @@ export const getFeedOptions = ( // root locale must exists // eslint-disable-next-line @typescript-eslint/naming-convention "/": {}, - ...context.siteConfig.locales, + ...siteConfig.locales, }).map((localePath) => [ localePath, { @@ -112,22 +118,21 @@ export const getFilename = ( jsonOutputFilename: string; rssOutputFilename: string; } => ({ - atomOutputFilename: `${prefix.replace(/^\//, "")}${ + atomOutputFilename: `${removeLeadingSlash(prefix)}${ options.atomOutputFilename || "atom.xml" }`, - jsonOutputFilename: `${prefix.replace(/^\//, "")}${ + jsonOutputFilename: `${removeLeadingSlash(prefix)}${ options.jsonOutputFilename || "feed.json" }`, - rssOutputFilename: `${prefix.replace(/^\//, "")}${ + rssOutputFilename: `${removeLeadingSlash(prefix)}${ options.rssOutputFilename || "rss.xml" }`, }); export const getFeedLinks = ( - context: Context, + { base }: Context, options: FeedOptions ): FeedLinks => { - const { base } = context; const { hostname } = options; const { atomOutputFilename, jsonOutputFilename, rssOutputFilename } = getFilename(options); diff --git a/packages/feed/src/node/page.ts b/packages/feed/src/node/page.ts index 45e8abdf9..a6bf87dc7 100644 --- a/packages/feed/src/node/page.ts +++ b/packages/feed/src/node/page.ts @@ -1,16 +1,9 @@ -import { - getImageMineType, - resolveHTML, - resolveUrl, - getAuthor, - getCategory, - isAbsoluteUrl, - isUrl, -} from "./utils"; +import { getAuthor, getCategory, isAbsoluteUrl, isUrl } from "vuepress-shared"; +import { getImageMineType, resolveHTML, resolveUrl } from "./utils"; +import type { AuthorInfo } from "vuepress-shared"; import type { Context, Page, PageFrontmatter } from "vuepress-typings"; import type { Feed } from "./feed"; -import type { AuthorInfo } from "./utils"; import type { FeedAuthor, FeedCategory, @@ -102,7 +95,7 @@ export class FeedPage { if (typeof this.pageFeedOptions.category === "object") return [this.pageFeedOptions.category]; - const { category } = this.frontmatter; + const { categories, category = categories } = this.frontmatter; return getCategory(category).map((item) => ({ name: item })); } @@ -165,19 +158,18 @@ export class FeedPage { if (typeof this.getter.image === "function") return this.getter.image(this.page); - const banner = this.frontmatter["banner"] as string | undefined; - const cover = this.frontmatter["cover"] as string | undefined; + const { banner, cover } = this.frontmatter; if (banner) { if (isAbsoluteUrl(banner)) - return resolveUrl(this.options.hostname, this.context.base, banner); + return resolveUrl(this.options.hostname, this.base, banner); if (isUrl(banner)) return banner; } if (cover) { if (isAbsoluteUrl(cover)) - return resolveUrl(this.options.hostname, this.context.base, cover); + return resolveUrl(this.options.hostname, this.base, cover); if (isUrl(cover)) return cover; } @@ -188,7 +180,7 @@ export class FeedPage { if (result) { if (isAbsoluteUrl(result[1])) - return resolveUrl(this.options.hostname, this.context.base, result[1]); + return resolveUrl(this.options.hostname, this.base, result[1]); if (isUrl(result[1])) return result[1]; } diff --git a/packages/feed/src/node/plugin.ts b/packages/feed/src/node/plugin.ts index 86706c2c6..961fa479f 100644 --- a/packages/feed/src/node/plugin.ts +++ b/packages/feed/src/node/plugin.ts @@ -1,28 +1,28 @@ -import chalk from "chalk"; +import { magenta } from "chalk"; import { covertOptions } from "./compact"; +import { checkOutput, ensureHostName, getFeedOptions } from "./options"; import { injectLinkstoHead } from "./injectHead"; import { FeedGenerator } from "./generator"; -import { checkOutput, ensureHostName, getFeedOptions } from "./options"; -import { error, info } from "./utils"; +import { logger } from "./utils"; import type { Plugin, PluginEntry } from "vuepress-typings"; import type { FeedOptions } from "../types"; export const feedPlugin: Plugin = (options, context) => { + covertOptions(options as FeedOptions & Record); + const plugin: PluginEntry = { - name: "@mr-hope/vuepress-plugin-feed", + name: "vuepress-plugin-feed1", }; - covertOptions(options as FeedOptions & Record); - if (!ensureHostName(options)) { - error(`Option ${chalk.magenta("hostname")} is required!`); + logger.error(`Option ${magenta("hostname")} is required!`); return plugin; } if (!checkOutput(options)) { - info("No requested output, the plugin won’t start!"); + logger.info("No requested output, the plugin won’t start!"); return plugin; } diff --git a/packages/feed/src/node/rss/index.ts b/packages/feed/src/node/rss/index.ts index ccd76578d..f33a01b88 100644 --- a/packages/feed/src/node/rss/index.ts +++ b/packages/feed/src/node/rss/index.ts @@ -1,6 +1,6 @@ +import { encodeCDATA, encodeXML, isUrl, stripTags } from "vuepress-shared"; import { js2xml } from "xml-js"; -import { stripTags } from "../stripTags"; -import { FEED_GENERATOR, encodeCDATA, encodeXML, isUrl } from "../utils"; +import { FEED_GENERATOR } from "../utils"; import type { Feed } from "../feed"; import type { FeedCategory, FeedEnclosure, FeedItemOption } from "../../types"; diff --git a/packages/feed/src/node/utils.ts b/packages/feed/src/node/utils.ts index fd23d8b2e..6c6eb509b 100644 --- a/packages/feed/src/node/utils.ts +++ b/packages/feed/src/node/utils.ts @@ -1,19 +1,6 @@ -import { black, blue } from "chalk"; +import { Logger, removeLeadingSlash } from "vuepress-shared"; -export const wait = (message: string): void => - console.log(blue("Feed:"), black.bgYellowBright("wait"), message); - -export const warn = (message: string): void => - console.log(blue("Feed:"), black.bgYellow("warn"), message); - -export const info = (message: string): void => - console.log(blue("Feed:"), black.bgBlue("Info"), message); - -export const error = (message: string): void => - console.log(blue("Feed:"), black.bgRed("Error"), message); - -export const success = (message: string): void => - console.log(blue("Feed:"), black.bgGreen("Success"), message); +export const logger = new Logger("vuepress-plugin-feed1"); export const compareDate = ( dateA: Date | string | undefined, @@ -58,36 +45,8 @@ export const resolveHTML = ( // remove tex .replace(//gu, "Content not supported"); -/** - * check if string is a valid url - */ -export const isUrl = (test: string): boolean => { - if (typeof test !== "string" || test === "") return false; - - // url Math - const result = /^(?:\w+:)?\/\/(\S+)$/u.exec(test); - - if (!result) return false; - - const address = result[1]; - - if (!address) return false; - - return ( - // address with localhost - /^localhost[:?\d]*(?:[^:?\d]\S*)?$/u.test(address) || - // address without localhost - /^[^\s.]+\.\S{2,}$/u.test(address) - ); -}; - -export const isAbsoluteUrl = (test: string): boolean => test.startsWith("/"); - export const resolveUrl = (hostname: string, base = "", path = ""): string => - `${hostname}${base}${ - // make sure path does not start with '/' - path.replace(/^\//u, "") - }`; + `${hostname}${base}${removeLeadingSlash(path)}`; export const getImageMineType = (ext = ""): string => `image/${ @@ -104,66 +63,4 @@ export const getImageMineType = (ext = ""): string => : "" }`; -/** - * @see https://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml - */ -export const encodeCDATA = (content: string): string => - content.replace(/]]>/g, "]]]]>"); - -export const encodeXML = (content: string): string => - content - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); - -export const FEED_GENERATOR = "@mr-hope/vuepress-plugin-feed"; - -export type AuthorInfo = { name: string; url?: string }; - -export type Author = string | string[] | AuthorInfo | AuthorInfo[]; - -export const getAuthor = ( - author: Author | false | undefined, - canDisable = false -): AuthorInfo[] => { - if (author) { - if (Array.isArray(author)) { - return author.map((item) => - typeof item === "string" ? { name: item } : item - ); - } - - if (typeof author === "string") return [{ name: author }]; - - if (typeof author === "object" && author.name) return [author]; - - console.error( - `Expect 'author' to be \`AuthorInfo[] | AuthorInfo | string[] | string ${ - canDisable ? "" : "| false" - } | undefined\`, but got`, - author - ); - - return []; - } - - return []; -}; - -export const getCategory = ( - category: string[] | string | undefined -): string[] => { - if (category) { - if (Array.isArray(category)) return category; - if (typeof category === "string") return [category]; - - console.error( - `Expect 'category' to be \`string[] | string | undefined\`, but got`, - category - ); - } - - return []; -}; +export const FEED_GENERATOR = "vuepress-plugin-feed2"; diff --git a/packages/theme-types/package.json b/packages/theme-types/package.json index a79057749..4697d9426 100644 --- a/packages/theme-types/package.json +++ b/packages/theme-types/package.json @@ -26,11 +26,11 @@ }, "types": "types/index.d.ts", "dependencies": { - "@mr-hope/vuepress-plugin-feed": "workspace:*", "@mr-hope/vuepress-plugin-git": "workspace:*", "@mr-hope/vuepress-plugin-pwa": "workspace:*", "@mr-hope/vuepress-plugin-reading-time": "workspace:*", "vuepress-plugin-comment1": "workspace:*", + "vuepress-plugin-feed1": "workspace:*", "vuepress-plugin-md-enhance": "workspace:*", "vuepress-plugin-photo-swipe": "workspace:*", "vuepress-theme-hope": "workspace:*", diff --git a/packages/theme-types/types/index.d.ts b/packages/theme-types/types/index.d.ts index f409b60f8..e8107df70 100644 --- a/packages/theme-types/types/index.d.ts +++ b/packages/theme-types/types/index.d.ts @@ -2,7 +2,7 @@ /// -/// +/// /// diff --git a/packages/theme/node/plugins.ts b/packages/theme/node/plugins.ts index 19c6fd764..a297a3894 100644 --- a/packages/theme/node/plugins.ts +++ b/packages/theme/node/plugins.ts @@ -7,7 +7,7 @@ import type { AddThisOptions } from "vuepress-plugin-add-this"; import type { CommentOptions } from "vuepress-plugin-comment1"; import type { ComponentOptions } from "@mr-hope/vuepress-plugin-components"; import type { CopyCodeOptions } from "vuepress-plugin-copy-code1"; -import type { FeedOptions } from "@mr-hope/vuepress-plugin-feed"; +import type { FeedOptions } from "vuepress-plugin-feed1"; import type { PWAOptions } from "@mr-hope/vuepress-plugin-pwa"; import type { SeoOptions } from "@mr-hope/vuepress-plugin-seo"; import type { SitemapOptions } from "@mr-hope/vuepress-plugin-sitemap"; @@ -129,7 +129,7 @@ export const getPluginConfig = ( ["@mr-hope/components", resolveComponentsOptions(themeConfig)], - ["@mr-hope/feed", resolveFeedOptions(themeConfig)], + ["feed1", resolveFeedOptions(themeConfig)], ["@mr-hope/git", themeConfig.git], diff --git a/packages/theme/package.json b/packages/theme/package.json index 16d5175ab..161d2f78d 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -33,7 +33,6 @@ "@docsearch/css": "^3.1.0", "@docsearch/js": "^3.1.0", "@mr-hope/vuepress-plugin-components": "workspace:*", - "@mr-hope/vuepress-plugin-feed": "workspace:*", "@mr-hope/vuepress-plugin-git": "workspace:*", "@mr-hope/vuepress-plugin-pwa": "workspace:*", "@mr-hope/vuepress-plugin-seo": "workspace:*", @@ -52,6 +51,7 @@ "vuepress-plugin-container": "^2.1.5", "vuepress-plugin-copy-code1": "workspace:*", "vuepress-plugin-copyright": "^1.0.2", + "vuepress-plugin-feed1": "workspace:*", "vuepress-plugin-md-enhance": "workspace:*", "vuepress-plugin-photo-swipe": "workspace:*", "vuepress-plugin-typescript": "^0.3.1", diff --git a/packages/theme/types/extend.d.ts b/packages/theme/types/extend.d.ts index 54cc45bc3..e3b7b8123 100644 --- a/packages/theme/types/extend.d.ts +++ b/packages/theme/types/extend.d.ts @@ -7,7 +7,7 @@ import { ResolvedHopeThemeConfig, } from "./theme"; import { PageInfo } from "vuepress-plugin-comment1"; -import { FeedFrontmatterOption } from "@mr-hope/vuepress-plugin-feed"; +import { FeedFrontmatterOption } from "vuepress-plugin-feed1"; declare module "vue/types/vue" { export interface Vue { diff --git a/packages/theme/types/theme/plugin.d.ts b/packages/theme/types/theme/plugin.d.ts index a3177ef58..9831dba99 100644 --- a/packages/theme/types/theme/plugin.d.ts +++ b/packages/theme/types/theme/plugin.d.ts @@ -2,7 +2,7 @@ import { ActiveHashOptions } from "vuepress-plugin-active-hash"; import { CommentOptions } from "vuepress-plugin-comment1"; import type { ComponentOptions } from "@mr-hope/vuepress-plugin-components"; import { CopyCodeOptions } from "vuepress-plugin-copy-code1"; -import { FeedOptions } from "@mr-hope/vuepress-plugin-feed"; +import { FeedOptions } from "vuepress-plugin-feed1"; import { GitOptions } from "@mr-hope/vuepress-plugin-git"; import { MarkdownEnhanceOptions } from "vuepress-plugin-md-enhance"; import { PWAOptions } from "@mr-hope/vuepress-plugin-pwa"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 714030ef3..f5a5fbe37 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,7 +12,7 @@ importers: '@commitlint/cli': 17.0.2 '@commitlint/config-conventional': 17.0.2 '@mr-hope/vuepress-plugin-components': workspace:* - '@mr-hope/vuepress-plugin-feed': workspace:* + 'vuepress-plugin-feed1': workspace:* '@mr-hope/vuepress-plugin-git': workspace:* '@mr-hope/vuepress-plugin-pwa': workspace:* '@mr-hope/vuepress-plugin-reading-time': workspace:* @@ -65,7 +65,7 @@ importers: '@commitlint/cli': 17.0.2 '@commitlint/config-conventional': 17.0.2 '@mr-hope/vuepress-plugin-components': link:packages/components - '@mr-hope/vuepress-plugin-feed': link:packages/feed + 'vuepress-plugin-feed1': link:packages/feed '@mr-hope/vuepress-plugin-git': link:packages/git '@mr-hope/vuepress-plugin-pwa': link:packages/pwa '@mr-hope/vuepress-plugin-reading-time': link:packages/reading-time @@ -518,7 +518,7 @@ importers: '@docsearch/css': ^3.1.0 '@docsearch/js': ^3.1.0 '@mr-hope/vuepress-plugin-components': workspace:* - '@mr-hope/vuepress-plugin-feed': workspace:* + 'vuepress-plugin-feed1': workspace:* '@mr-hope/vuepress-plugin-git': workspace:* '@mr-hope/vuepress-plugin-pwa': workspace:* '@mr-hope/vuepress-plugin-seo': workspace:* @@ -546,7 +546,7 @@ importers: '@docsearch/css': 3.1.0 '@docsearch/js': 3.1.0_@types+react@18.0.10 '@mr-hope/vuepress-plugin-components': link:../components - '@mr-hope/vuepress-plugin-feed': link:../feed + 'vuepress-plugin-feed1': link:../feed '@mr-hope/vuepress-plugin-git': link:../git '@mr-hope/vuepress-plugin-pwa': link:../pwa '@mr-hope/vuepress-plugin-seo': link:../seo @@ -573,7 +573,7 @@ importers: packages/theme-types: specifiers: - '@mr-hope/vuepress-plugin-feed': workspace:* + 'vuepress-plugin-feed1': workspace:* '@mr-hope/vuepress-plugin-git': workspace:* '@mr-hope/vuepress-plugin-pwa': workspace:* '@mr-hope/vuepress-plugin-reading-time': workspace:* @@ -583,7 +583,7 @@ importers: vuepress-theme-hope: workspace:* vuepress-typings: workspace:* dependencies: - '@mr-hope/vuepress-plugin-feed': link:../feed + 'vuepress-plugin-feed1': link:../feed '@mr-hope/vuepress-plugin-git': link:../git '@mr-hope/vuepress-plugin-pwa': link:../pwa '@mr-hope/vuepress-plugin-reading-time': link:../reading-time