Skip to content

Commit

Permalink
feat(theme): make copyright2 feed2 and pwa2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Dec 27, 2023
1 parent 25d4445 commit 70aae43
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 29 deletions.
1 change: 1 addition & 0 deletions docs/copyright2/package.json
Expand Up @@ -23,6 +23,7 @@
"docs-shared": "workspace:*",
"sass-loader": "13.3.2",
"vue": "3.3.13",
"vuepress-plugin-copyright2": "workspace:*",
"vuepress-vite": "2.0.0-rc.0",
"vuepress-webpack": "2.0.0-rc.0"
}
Expand Down
2 changes: 2 additions & 0 deletions docs/theme/package.json
Expand Up @@ -30,6 +30,8 @@
"vue": "3.3.13",
"vuepress-plugin-components": "workspace:*",
"vuepress-plugin-copy-code2": "workspace:*",
"vuepress-plugin-copyright2": "workspace:*",
"vuepress-plugin-feed2": "workspace:*",
"vuepress-plugin-md-enhance": "workspace:*",
"vuepress-shared": "workspace:*",
"vuepress-theme-hope": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/guide/advanced/feed.md
Expand Up @@ -9,7 +9,7 @@ tag:
- Feed
---

The theme adds feed support using <ProjectLink name="feed2">`vuepress-plugin-feed2`</ProjectLink>.
The theme adds feed support with <ProjectLink name="feed2">`vuepress-plugin-feed2`</ProjectLink>. To use it, install `vuepress-plugin-feed2` manually in your project.

::: info

Expand Down
5 changes: 3 additions & 2 deletions docs/theme/src/guide/advanced/pwa.md
Expand Up @@ -9,13 +9,14 @@ tag:
- PWA
---

The theme provides progressive web app support [^pwa-intro] via built-in <ProjectLink name="pwa2">`vuepress-plugin-pwa2`</ProjectLink>, and it's disabled by default.
The theme provides progressive web app support [^pwa-intro] via <ProjectLink name="pwa2">`vuepress-plugin-pwa2`</ProjectLink>. To use it, install `vuepress-plugin-pwa2` manually in your project.

::: info

If you are using this plugin, we recommend you to set `shouldPrefetch: false` in your VuePress config file.

`vuepress-theme-hope` passes `plugins.pwa` in theme options as plugin options to `vuepress-plugin-pwa2`, so every options mentioned below is under it.
`vuepress-theme-hope` provides `plugins.pwa` in theme options to `vuepress-plugin-pwa2`.
Every options mentioned below is under `plugin.pwa`.

:::

Expand Down
7 changes: 3 additions & 4 deletions docs/theme/src/guide/feature/copyright.md
Expand Up @@ -10,13 +10,12 @@ copy:
minLength: 40
---

Sometimes, you may not want some of your articles to be copied by others, or you want others to automatically generate a piece of copyright information to the clipboard when copying.

`vuepress-theme-hope` use <ProjectLink name="copyright2">vuepress-plugin-copyright2</ProjectLink> to provide related features.
You may not want some of your articles to be copied by others, or you want copyright information appended to the clipboard when copying.
`vuepress-theme-hope` use <ProjectLink name="copyright2">vuepress-plugin-copyright2</ProjectLink> to provide this feature. To use it, install `vuepress-plugin-copyright2` manually in your project.

::: info

`vuepress-theme-hope` passes `plugins.copyright` in theme options as plugin options to `vuepress-plugin-copyright2`.
`vuepress-theme-hope` passes `plugins.copyright` in theme options to `vuepress-plugin-copyright2`.

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/theme/src/zh/guide/advanced/feed.md
Expand Up @@ -9,7 +9,7 @@ tag:
- Feed
---

`vuepress-theme-hope` 通过内置 <ProjectLink name="feed2" path="/zh/">`vuepress-plugin-feed2`</ProjectLink> 插件来为你提供 feed 支持。
`vuepress-theme-hope` 通过内置 <ProjectLink name="feed2" path="/zh/">`vuepress-plugin-feed2`</ProjectLink> 插件来为你提供 feed 支持。想使用它,你应该手动在你的项目中安装 `vuepress-plugin-feed2`

::: info

Expand Down
5 changes: 3 additions & 2 deletions docs/theme/src/zh/guide/advanced/pwa.md
Expand Up @@ -9,13 +9,14 @@ tag:
- PWA
---

该主题将通过内置 <ProjectLink name="pwa2" path="/zh/">`vuepress-plugin-pwa2`</ProjectLink> 提供渐进式 Web 应用程序支持[^pwa-intro],该功能默认禁用
该主题将通过 <ProjectLink name="pwa2" path="/zh/">`vuepress-plugin-pwa2`</ProjectLink> 提供渐进式 Web 应用程序支持[^pwa-intro]。想使用它,你应该手动在你的项目中安装 `vuepress-plugin-pwa2`

::: info

如果你正在使用此插件,我们推荐在你的 VuePress 配置文件中设置 `shouldPrefetch: false`

`vuepress-theme-hope` 将主题选项中的 `plugins.pwa` 作为插件选项提供给 `vuepress-plugin-pwa2`,后文指出的选项都位于此选项下。
`vuepress-theme-hope` 将主题选项中的 `plugins.pwa` 提供给 `vuepress-plugin-pwa2`
后文提及的选项都位于 `plugin.pwa` 下。

:::

Expand Down
7 changes: 3 additions & 4 deletions docs/theme/src/zh/guide/feature/copyright.md
Expand Up @@ -10,13 +10,12 @@ copy:
triggerLength: 40
---

有些时候,你可能不想让你的某些文章被他人复制,或者你想让他人在复制时,自动生成一段版权信息到剪切板中。

`vuepress-theme-hope` 为应对此场景引入了 <ProjectLink name="copyright2" path="/zh/">vuepress-plugin-copyright2</ProjectLink>。
你可能不想让你的某些文章被他人复制,或者你想版权信息在复制时自动附加。
`vuepress-theme-hope` 通过 <ProjectLink name="copyright2" path="/zh/">vuepress-plugin-copyright2</ProjectLink> 提供此功能。想要使用它,你需要在你的项目中手动安装 `vuepress-plugin-copyright2`

::: info

`vuepress-theme-hope` 将主题选项中的 `plugins.copyright` 作为插件选项提供给 `vuepress-plugin-copyright2`
`vuepress-theme-hope` 将主题选项中的 `plugins.copyright` 提供给 `vuepress-plugin-copyright2`

:::

Expand Down
18 changes: 15 additions & 3 deletions packages/theme/package.json
Expand Up @@ -100,11 +100,8 @@
"vuepress-plugin-comment2": "workspace:*",
"vuepress-plugin-components": "workspace:*",
"vuepress-plugin-copy-code2": "workspace:*",
"vuepress-plugin-copyright2": "workspace:*",
"vuepress-plugin-feed2": "workspace:*",
"vuepress-plugin-md-enhance": "workspace:*",
"vuepress-plugin-photo-swipe": "workspace:*",
"vuepress-plugin-pwa2": "workspace:*",
"vuepress-plugin-reading-time2": "workspace:*",
"vuepress-plugin-rtl": "workspace:*",
"vuepress-plugin-sass-palette": "workspace:*",
Expand All @@ -118,6 +115,9 @@
"nodejs-jieba": "^0.1.2",
"sass-loader": "^13.3.2",
"vuepress": "2.0.0-rc.0",
"vuepress-plugin-copyright2": "workspace:*",
"vuepress-plugin-feed2": "workspace:*",
"vuepress-plugin-pwa2": "workspace:*",
"vuepress-plugin-search-pro": "workspace:*",
"vuepress-vite": "2.0.0-rc.0",
"vuepress-webpack": "2.0.0-rc.0"
Expand All @@ -138,6 +138,15 @@
"vuepress": {
"optional": true
},
"vuepress-plugin-copyright2": {
"optional": true
},
"vuepress-plugin-feed2": {
"optional": true
},
"vuepress-plugin-pwa2": {
"optional": true
},
"vuepress-plugin-search-pro": {
"optional": true
},
Expand All @@ -154,6 +163,9 @@
"@vuepress/markdown": "2.0.0-rc.0",
"@vuepress/plugin-docsearch": "2.0.0-rc.0",
"@vuepress/plugin-search": "2.0.0-rc.0",
"vuepress-plugin-copyright2": "workspace:*",
"vuepress-plugin-feed2": "workspace:*",
"vuepress-plugin-pwa2": "workspace:*",
"vuepress-plugin-search-pro": "workspace:*"
}
}
19 changes: 18 additions & 1 deletion packages/theme/src/node/plugins/copyright.ts
@@ -1,12 +1,21 @@
import type { Page, Plugin } from "@vuepress/core";
import { colors } from "@vuepress/utils";
import type { CopyrightOptions } from "vuepress-plugin-copyright2";
import { copyrightPlugin } from "vuepress-plugin-copyright2";
import { getAuthor, isPlainObject } from "vuepress-shared/node";

import type {
ThemeData,
ThemeNormalPageFrontmatter,
} from "../../shared/index.js";
import { logger } from "../utils.js";

let copyrightPlugin: (options: CopyrightOptions, legacy?: boolean) => Plugin;

try {
({ copyrightPlugin } = await import("vuepress-plugin-copyright2"));
} catch (e) {
// do nothing
}

/**
* @private
Expand All @@ -21,6 +30,14 @@ export const getCopyrightPlugin = (
): Plugin | null => {
if (!options) return null;

if (!copyrightPlugin) {
logger.error(
`${colors.cyan("vuepress-plugin-copyright2")} is not installed!`,
);

return null;
}

return copyrightPlugin(
<CopyrightOptions>{
canonical: hostname,
Expand Down
17 changes: 16 additions & 1 deletion packages/theme/src/node/plugins/feed.ts
@@ -1,6 +1,6 @@
import type { Plugin } from "@vuepress/core";
import { colors } from "@vuepress/utils";
import type { FeedOptions } from "vuepress-plugin-feed2";
import { feedPlugin } from "vuepress-plugin-feed2";
import {
deepAssign,
entries,
Expand All @@ -10,6 +10,15 @@ import {
} from "vuepress-shared/node";

import type { ThemeData } from "../../shared/index.js";
import { logger } from "../utils.js";

let feedPlugin: (options: FeedOptions, legacy?: boolean) => Plugin;

try {
({ feedPlugin } = await import("vuepress-plugin-feed2"));
} catch (e) {
// do nothing
}

/**
* @private
Expand All @@ -26,6 +35,12 @@ export const getFeedPlugin = (
// disable feed if no options for feed plugin
if (!keys(options).length) return null;

if (!feedPlugin) {
logger.error(`${colors.cyan("vuepress-plugin-feed2")} is not installed!`);

return null;
}

const globalAuthor = getAuthor(themeData.author);

const defaultOptions: FeedOptions = {
Expand Down
17 changes: 16 additions & 1 deletion packages/theme/src/node/plugins/pwa.ts
@@ -1,8 +1,17 @@
import type { Plugin } from "@vuepress/core";
import { colors } from "@vuepress/utils";
import type { PWAOptions } from "vuepress-plugin-pwa2";
import { pwaPlugin } from "vuepress-plugin-pwa2";
import { isPlainObject } from "vuepress-shared/node";

import { logger } from "../utils.js";

let pwaPlugin: (options: PWAOptions, legacy?: boolean) => Plugin;

try {
({ pwaPlugin } = await import("vuepress-plugin-pwa2"));
} catch (e) {
// do nothing
}
/**
* @private
*
Expand All @@ -15,6 +24,12 @@ export const getPWAPlugin = (
): Plugin | null => {
if (!options) return null;

if (!pwaPlugin) {
logger.error(`${colors.cyan("vuepress-plugin-pwa2")} is not installed!`);

return null;
}

return pwaPlugin(
{
...(favicon ? { favicon } : {}),
Expand Down
27 changes: 18 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70aae43

Please sign in to comment.