rspress-plugin-gh-pages 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,45 +1,66 @@
1
- import path from 'node:path';
2
-
3
1
  import chalk from 'chalk';
4
2
  import ghpages from 'gh-pages';
5
3
  import { logger } from '@rspress/shared/logger';
6
4
 
7
- import { PresetConfigMutator, type StrictOmit } from 'rspress-plugin-devkit';
5
+ import type { MarkRequired } from 'rspress-plugin-devkit';
8
6
  import type { RspressPlugin } from '@rspress/shared';
9
7
 
10
- export const componentsPath = path.join(__dirname, './components');
11
-
12
8
  const DefaultDocBuildOutput = 'doc_build';
13
9
 
14
- interface RspressPluginGHPagesOptions extends ghpages.PublishOptions {
10
+ interface RspressPluginGHPagesOptions
11
+ extends MarkRequired<ghpages.PublishOptions, 'repo'> {
15
12
  directory?: string;
16
13
  silent?: boolean;
14
+ siteBase?: string;
17
15
  }
18
16
 
17
+ const logPrefix = chalk.green('[gh-pages]');
18
+
19
19
  export default function rspressPluginGHPages(
20
- options: RspressPluginGHPagesOptions = {},
20
+ options: RspressPluginGHPagesOptions,
21
21
  ): RspressPlugin {
22
22
  const {
23
- directory,
24
23
  repo,
24
+ directory,
25
25
  branch = 'gh-pages',
26
26
  silent = false,
27
+ siteBase = '',
27
28
  ...publishOptions
28
29
  } = options;
29
30
 
30
31
  return {
31
32
  name: 'rspress-plugin-gh-pages',
32
33
  config(config) {
33
- config.base = '/rspress-plugins/';
34
- return new PresetConfigMutator(config).toConfig();
34
+ let baseFromRepo = repo.includes('github.io')
35
+ ? '/'
36
+ : /\/([^\/]+)\.git$/.exec(repo)?.[1];
37
+
38
+ // Use || here to as ?? will consider '' as a valid value
39
+ const base = siteBase || baseFromRepo || '';
40
+
41
+ if (!base) {
42
+ logger.warn(
43
+ `${logPrefix} Failed to parse base from repo, site base path will not be updated.`,
44
+ );
45
+
46
+ return config;
47
+ }
48
+
49
+ config.base = `/${base}/`;
50
+
51
+ return config;
35
52
  },
36
53
  async afterBuild(config, isBuild) {
54
+ if (!repo) {
55
+ logger.error(
56
+ `Option ${chalk.cyan('repo')} is required for rspress-plugin-gh-pages.`,
57
+ );
58
+ }
59
+
37
60
  if (!isBuild) return;
38
61
 
39
62
  const publishDir = directory ?? config.outDir ?? DefaultDocBuildOutput;
40
63
 
41
- const logPrefix = chalk.green('[rspress-plugin-gh-pages]');
42
-
43
64
  if (!silent) {
44
65
  logger.info(
45
66
  `${logPrefix} Publish directory: ${chalk.cyan(publishDir)}`,
@@ -1 +0,0 @@
1
- [{"id":0,"title":"RSPress x GH Pages","content":"#","routePath":"/rspress-plugins/","lang":"","toc":[],"domain":"","frontmatter":{},"version":""}]