@ng-doc/keywords-loaders 17.6.16 → 18.0.0-beta.1
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/angular/helpers/get-api-url.d.ts +8 -0
- package/angular/helpers/ng-to-keyword.d.ts +2 -1
- package/angular/interfaces/ng-page.d.ts +2 -2
- package/angular/interfaces/ng-response.d.ts +1 -1
- package/angular/types/ng-api-page-type.d.ts +1 -2
- package/index.cjs.js +53 -45
- package/package.json +2 -2
- package/angular/constants/index.d.ts +0 -2
- package/angular/constants/ng-api-page-types.d.ts +0 -1
- package/angular/constants/ng-page-types.d.ts +0 -1
|
@@ -3,7 +3,8 @@ import { NgPage } from '../interfaces';
|
|
|
3
3
|
import { NgVersion } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
|
+
* @param packageName
|
|
6
7
|
* @param page
|
|
7
8
|
* @param version
|
|
8
9
|
*/
|
|
9
|
-
export declare function ngPageToKeyword(page: NgPage, version?: NgVersion): Array<[string, NgDocGlobalKeyword]>;
|
|
10
|
+
export declare function ngPageToKeyword(packageName: string, page: NgPage, version?: NgVersion): Array<[string, NgDocGlobalKeyword]>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export type NgApiPageType = typeof ngPageTypes[number] | typeof ngApiPageTypes[number];
|
|
1
|
+
export type NgApiPageType = 'block' | 'undecorated_class' | 'constant' | 'decorator' | 'directive' | 'element' | 'enum' | 'function' | 'interface' | 'pipe' | 'ng_module' | 'type_alias' | 'initializer_api_function';
|
package/index.cjs.js
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var fetch = require('node-fetch');
|
|
4
4
|
|
|
5
|
-
const ngApiPageTypes = ['class', 'interface', 'function', 'type-alias', 'enum', 'const', 'ngmodule', 'directive', 'pipe', 'decorator'];
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
*
|
|
9
7
|
* @param version
|
|
10
8
|
*/
|
|
11
9
|
function getNgHost(version) {
|
|
12
10
|
const versionEndpoint = version ? `${version}.` : '';
|
|
13
|
-
return `https://${versionEndpoint}angular.
|
|
11
|
+
return `https://${versionEndpoint}angular.dev`;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -18,40 +16,43 @@ function getNgHost(version) {
|
|
|
18
16
|
* @param version
|
|
19
17
|
*/
|
|
20
18
|
async function fetchDocs(version) {
|
|
21
|
-
|
|
19
|
+
const manifestUrl = `${getNgHost(version)}/assets/api/manifest.json`;
|
|
20
|
+
return fetch(manifestUrl).then(response => response.json());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param packageName
|
|
26
|
+
* @param pageName
|
|
27
|
+
* @param version
|
|
28
|
+
*/
|
|
29
|
+
function getApiUrl(packageName, pageName, version) {
|
|
30
|
+
const packageNameWithoutPrefix = packageName.replace('@angular/', '');
|
|
31
|
+
return `${getNgHost(version)}/api/${packageNameWithoutPrefix}/${pageName}`;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
/**
|
|
25
35
|
*
|
|
36
|
+
* @param packageName
|
|
26
37
|
* @param page
|
|
27
38
|
* @param version
|
|
28
39
|
*/
|
|
29
|
-
function ngPageToKeyword(page, version) {
|
|
30
|
-
const
|
|
31
|
-
const isCodeLink = ngApiPageTypes.includes(page.type);
|
|
32
|
-
const key = isCodeLink ? page.title : page.title.replace(/\n/g, '');
|
|
40
|
+
function ngPageToKeyword(packageName, page, version) {
|
|
41
|
+
const url = getApiUrl(packageName, page.name, version);
|
|
33
42
|
const description = `External link the Angular documentation.`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
description
|
|
46
|
-
}]];
|
|
47
|
-
default:
|
|
48
|
-
return [[key, {
|
|
49
|
-
title: page.title,
|
|
50
|
-
url: path,
|
|
51
|
-
isCodeLink,
|
|
52
|
-
description
|
|
53
|
-
}]];
|
|
43
|
+
const keywords = [[page.name, {
|
|
44
|
+
title: page.name,
|
|
45
|
+
url,
|
|
46
|
+
description
|
|
47
|
+
}]];
|
|
48
|
+
if (page.type === 'decorator') {
|
|
49
|
+
keywords.push([`@${page.name}`, {
|
|
50
|
+
title: `@${page.name}`,
|
|
51
|
+
url,
|
|
52
|
+
description
|
|
53
|
+
}]);
|
|
54
54
|
}
|
|
55
|
+
return keywords;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
@@ -63,13 +64,14 @@ function ngPageToKeyword(page, version) {
|
|
|
63
64
|
*/
|
|
64
65
|
function ngKeywordsLoader(options) {
|
|
65
66
|
return async () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
try {
|
|
68
|
+
const packages = await fetchDocs(options?.version);
|
|
69
|
+
const keywords = Object.entries(packages).flatMap(([packageName, pages]) => pages.flatMap(page => ngPageToKeyword(packageName, page, options?.version)));
|
|
70
|
+
return Object.fromEntries(keywords);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(`Failed to load Angular keywords: ${error}`);
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -92,23 +94,29 @@ function ngDocKeywordsLoader(options) {
|
|
|
92
94
|
const assets = options.assetsPath ?? '/assets/ng-doc';
|
|
93
95
|
const keywords = await fetchKeywords(`${endpoint}${assets}`);
|
|
94
96
|
return Object.keys(keywords).reduce((acc, key) => {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
const {
|
|
98
|
+
title,
|
|
99
|
+
path,
|
|
100
|
+
description,
|
|
101
|
+
type
|
|
102
|
+
} = keywords[key];
|
|
103
|
+
const url = `${endpoint}${path}`;
|
|
104
|
+
const isGuideKeyword = key.startsWith('*');
|
|
105
|
+
if (isGuideKeyword && options.loadGuides) {
|
|
98
106
|
const prefix = options.guidesPrefix ?? '';
|
|
99
107
|
const newKey = `*${prefix}${key.replace(/^\*/, '')}`;
|
|
100
108
|
acc[newKey] = {
|
|
101
|
-
title:
|
|
109
|
+
title: title ?? key,
|
|
102
110
|
url,
|
|
103
|
-
description
|
|
104
|
-
|
|
111
|
+
description,
|
|
112
|
+
type
|
|
105
113
|
};
|
|
106
|
-
} else
|
|
114
|
+
} else {
|
|
107
115
|
acc[key] = {
|
|
108
|
-
title:
|
|
116
|
+
title: title ?? key,
|
|
109
117
|
url,
|
|
110
|
-
description
|
|
111
|
-
|
|
118
|
+
description,
|
|
119
|
+
type
|
|
112
120
|
};
|
|
113
121
|
}
|
|
114
122
|
return acc;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ngApiPageTypes: readonly string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ngPageTypes: readonly string[];
|