@xrow/docusaurus-gitlab 4.161.0

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 ADDED
@@ -0,0 +1,26 @@
1
+ # Docusaurus GitLab helpers
2
+
3
+ GitLab CI helper functions for Docusaurus configuration.
4
+
5
+ ```ts
6
+ import gitlab from '@xrow/docusaurus-gitlab';
7
+
8
+ const pagesUrl = gitlab.gitLabPagesUrl();
9
+
10
+ export default {
11
+ title: gitlab.gitLabTitle(),
12
+ tagline: gitlab.gitLabTagline(),
13
+ url: pagesUrl.url,
14
+ baseUrl: pagesUrl.baseUrl,
15
+ presets: [
16
+ [
17
+ '@docusaurus/preset-classic',
18
+ {
19
+ docs: {
20
+ editUrl: gitlab.gitlabEditUrl(),
21
+ },
22
+ },
23
+ ],
24
+ ],
25
+ };
26
+ ```
package/index.cjs ADDED
@@ -0,0 +1,46 @@
1
+ function envValue(name) {
2
+ return typeof process !== 'undefined' && process.env ? process.env[name] : undefined;
3
+ }
4
+
5
+ function textOrDefault(value, fallback) {
6
+ return typeof value === 'string' && value.trim() ? value : fallback;
7
+ }
8
+
9
+ function gitLabPagesUrl(pagesUrl = envValue('CI_PAGES_URL')) {
10
+ const parsedPagesUrl = new URL(pagesUrl || 'https://example.com/');
11
+
12
+ return {
13
+ url: parsedPagesUrl.origin,
14
+ baseUrl: parsedPagesUrl.pathname.replace(/\/?$/, '/'),
15
+ };
16
+ }
17
+
18
+ function gitLabTitle(title = envValue('CI_PROJECT_TITLE')) {
19
+ return textOrDefault(title, 'Default Project Title');
20
+ }
21
+
22
+ function gitLabTagline(tagline = envValue('CI_PROJECT_DESCRIPTION')) {
23
+ return textOrDefault(tagline, 'Default Project Description');
24
+ }
25
+
26
+ function gitlabEditUrl(
27
+ projectUrl = envValue('CI_PROJECT_URL'),
28
+ defaultBranch = envValue('CI_DEFAULT_BRANCH'),
29
+ ) {
30
+ if (!projectUrl || !defaultBranch) {
31
+ return undefined;
32
+ }
33
+
34
+ const normalizedProjectUrl = projectUrl.replace(/\/+$/, '');
35
+ const encodedBranch = encodeURIComponent(defaultBranch);
36
+
37
+ return `${normalizedProjectUrl}/-/edit/${encodedBranch}/`;
38
+ }
39
+
40
+ module.exports = {
41
+ gitLabPagesUrl,
42
+ gitLabTitle,
43
+ gitLabTagline,
44
+ gitlabEditUrl,
45
+ gitLabEditUrl: gitlabEditUrl,
46
+ };
package/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export interface GitLabPagesUrl {
2
+ url: string;
3
+ baseUrl: string;
4
+ }
5
+
6
+ export function gitLabPagesUrl(pagesUrl?: string): GitLabPagesUrl;
7
+
8
+ export function gitLabTitle(title?: string): string;
9
+
10
+ export function gitLabTagline(tagline?: string): string;
11
+
12
+ export function gitlabEditUrl(projectUrl?: string, defaultBranch?: string): string | undefined;
13
+
14
+ export const gitLabEditUrl: typeof gitlabEditUrl;
15
+
16
+ export interface DocusaurusGitLabHelpers {
17
+ gitLabPagesUrl: typeof gitLabPagesUrl;
18
+ gitLabTitle: typeof gitLabTitle;
19
+ gitLabTagline: typeof gitLabTagline;
20
+ gitlabEditUrl: typeof gitlabEditUrl;
21
+ }
22
+
23
+ declare const gitlab: DocusaurusGitLabHelpers;
24
+
25
+ export default gitlab;
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ function envValue(name) {
2
+ return typeof process !== 'undefined' && process.env ? process.env[name] : undefined;
3
+ }
4
+
5
+ function textOrDefault(value, fallback) {
6
+ return typeof value === 'string' && value.trim() ? value : fallback;
7
+ }
8
+
9
+ export function gitLabPagesUrl(pagesUrl = envValue('CI_PAGES_URL')) {
10
+ const parsedPagesUrl = new URL(pagesUrl || 'https://example.com/');
11
+
12
+ return {
13
+ url: parsedPagesUrl.origin,
14
+ baseUrl: parsedPagesUrl.pathname.replace(/\/?$/, '/'),
15
+ };
16
+ }
17
+
18
+ export function gitLabTitle(title = envValue('CI_PROJECT_TITLE')) {
19
+ return textOrDefault(title, 'Default Project Title');
20
+ }
21
+
22
+ export function gitLabTagline(tagline = envValue('CI_PROJECT_DESCRIPTION')) {
23
+ return textOrDefault(tagline, 'Default Project Description');
24
+ }
25
+
26
+ export function gitlabEditUrl(
27
+ projectUrl = envValue('CI_PROJECT_URL'),
28
+ defaultBranch = envValue('CI_DEFAULT_BRANCH'),
29
+ ) {
30
+ if (!projectUrl || !defaultBranch) {
31
+ return undefined;
32
+ }
33
+
34
+ const normalizedProjectUrl = projectUrl.replace(/\/+$/, '');
35
+ const encodedBranch = encodeURIComponent(defaultBranch);
36
+
37
+ return `${normalizedProjectUrl}/-/edit/${encodedBranch}/`;
38
+ }
39
+
40
+ export const gitLabEditUrl = gitlabEditUrl;
41
+
42
+ const gitlab = {
43
+ gitLabPagesUrl,
44
+ gitLabTitle,
45
+ gitLabTagline,
46
+ gitlabEditUrl,
47
+ };
48
+
49
+ export default gitlab;
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@xrow/docusaurus-gitlab",
3
+ "version": "4.161.0",
4
+ "description": "GitLab CI helper functions for Docusaurus configuration.",
5
+ "type": "module",
6
+ "main": "index.cjs",
7
+ "module": "index.js",
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "require": "./index.cjs"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "test": "node --test"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "index.cjs",
22
+ "index.d.ts"
23
+ ],
24
+ "license": "MIT"
25
+ }