rspress-plugin-gh-pages 0.1.1 → 0.1.3
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/README.md +17 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +10 -4
- package/package.json +1 -1
- package/src/index.ts +12 -6
package/README.md
CHANGED
|
@@ -27,3 +27,20 @@ export default defineConfig({
|
|
|
27
27
|
],
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
|
+
|
|
31
|
+
## Configure
|
|
32
|
+
|
|
33
|
+
## repo
|
|
34
|
+
|
|
35
|
+
- Type: `string`
|
|
36
|
+
- `Required`
|
|
37
|
+
|
|
38
|
+
The repository to deploy to, you can also specify another repository to deploy to.
|
|
39
|
+
|
|
40
|
+
## siteBase
|
|
41
|
+
|
|
42
|
+
- Type: `string`
|
|
43
|
+
|
|
44
|
+
Deploying to repositories other than the `<user>.github.io` repository requires specifying the `siteBase` option, as an example, deploying to repository `<user>/awesome-plugins` will require setting `siteBase` to `/awesome-plugins`, as the page will be hosted at `https://<user>.github.io/awesome-plugins`.
|
|
45
|
+
|
|
46
|
+
By default, `rspress-plugin-gh-pages` will try to parse the `repo` option to get a `siteBase` value(if repo is a `github.io` repository, the `siteBase` will be `/`, otherwise, the `siteBase` will be `/<repo-name>`), you can also specify the `siteBase` option to override the default value.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import ghpages from 'gh-pages';
|
|
2
2
|
import type { MarkRequired } from 'rspress-plugin-devkit';
|
|
3
3
|
import type { RspressPlugin } from '@rspress/shared';
|
|
4
|
-
export declare const componentsPath: string;
|
|
5
4
|
interface RspressPluginGHPagesOptions extends MarkRequired<ghpages.PublishOptions, 'repo'> {
|
|
6
5
|
directory?: string;
|
|
7
6
|
silent?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
2
|
import ghpages from 'gh-pages';
|
|
4
3
|
import { logger } from '@rspress/shared/logger';
|
|
5
|
-
export const componentsPath = path.join(__dirname, './components');
|
|
6
4
|
const DefaultDocBuildOutput = 'doc_build';
|
|
7
5
|
const logPrefix = chalk.green('[gh-pages]');
|
|
6
|
+
function normalizeBase(base) {
|
|
7
|
+
return base === '/' || base === ''
|
|
8
|
+
? '/'
|
|
9
|
+
: `/${base.replace(/^\/+|\/+$/g, '')}/`;
|
|
10
|
+
}
|
|
8
11
|
export default function rspressPluginGHPages(options) {
|
|
9
12
|
const { repo, directory, branch = 'gh-pages', silent = false, siteBase = '', ...publishOptions } = options;
|
|
10
13
|
return {
|
|
11
14
|
name: 'rspress-plugin-gh-pages',
|
|
12
15
|
config(config) {
|
|
13
16
|
var _a;
|
|
17
|
+
let baseFromRepo = repo.includes('github.io')
|
|
18
|
+
? '/'
|
|
19
|
+
: (_a = /\/([^\/]+)\.git$/.exec(repo)) === null || _a === void 0 ? void 0 : _a[1];
|
|
14
20
|
// Use || here to as ?? will consider '' as a valid value
|
|
15
|
-
const base = siteBase ||
|
|
21
|
+
const base = siteBase || baseFromRepo || '';
|
|
16
22
|
if (!base) {
|
|
17
23
|
logger.warn(`${logPrefix} Failed to parse base from repo, site base path will not be updated.`);
|
|
18
24
|
return config;
|
|
19
25
|
}
|
|
20
|
-
config.base =
|
|
26
|
+
config.base = normalizeBase(base);
|
|
21
27
|
return config;
|
|
22
28
|
},
|
|
23
29
|
async afterBuild(config, isBuild) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
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';
|
|
@@ -7,8 +5,6 @@ import { logger } from '@rspress/shared/logger';
|
|
|
7
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
10
|
interface RspressPluginGHPagesOptions
|
|
@@ -20,6 +16,12 @@ interface RspressPluginGHPagesOptions
|
|
|
20
16
|
|
|
21
17
|
const logPrefix = chalk.green('[gh-pages]');
|
|
22
18
|
|
|
19
|
+
function normalizeBase(base: string): string {
|
|
20
|
+
return base === '/' || base === ''
|
|
21
|
+
? '/'
|
|
22
|
+
: `/${base.replace(/^\/+|\/+$/g, '')}/`;
|
|
23
|
+
}
|
|
24
|
+
|
|
23
25
|
export default function rspressPluginGHPages(
|
|
24
26
|
options: RspressPluginGHPagesOptions,
|
|
25
27
|
): RspressPlugin {
|
|
@@ -35,8 +37,12 @@ export default function rspressPluginGHPages(
|
|
|
35
37
|
return {
|
|
36
38
|
name: 'rspress-plugin-gh-pages',
|
|
37
39
|
config(config) {
|
|
40
|
+
let baseFromRepo = repo.includes('github.io')
|
|
41
|
+
? '/'
|
|
42
|
+
: /\/([^\/]+)\.git$/.exec(repo)?.[1];
|
|
43
|
+
|
|
38
44
|
// Use || here to as ?? will consider '' as a valid value
|
|
39
|
-
const base = siteBase ||
|
|
45
|
+
const base = siteBase || baseFromRepo || '';
|
|
40
46
|
|
|
41
47
|
if (!base) {
|
|
42
48
|
logger.warn(
|
|
@@ -46,7 +52,7 @@ export default function rspressPluginGHPages(
|
|
|
46
52
|
return config;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
config.base =
|
|
55
|
+
config.base = normalizeBase(base);
|
|
50
56
|
|
|
51
57
|
return config;
|
|
52
58
|
},
|