Skip to content

Commit b2a1bbb

Browse files
committed
Add metadata to documented interfaces
1 parent 3738979 commit b2a1bbb

File tree

6 files changed

+2604
-19
lines changed

6 files changed

+2604
-19
lines changed

example/example.api.json

Lines changed: 2573 additions & 1 deletion
Large diffs are not rendered by default.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"scripts": {
2525
"unit-test": "",
26-
"build": "webdoc --tutorials ./tutorials --site-root example-documentation --site-domain https://webdoc-labs.github.io",
26+
"build": "webdoc --tutorials ./tutorials --site-root example-documentation --site-domain https://webdoc-labs.github.io --verbose",
2727
"build-next": "cd .. && webdoc && cd example",
2828
"build-pixi-api": "cd ../../pixi-api && webdoc && cd ../webdoc/example",
2929
"build-pixi-api-prod": "cd ../../pixi-api && webdoc --site-root pixi-api && cd ../webdoc/example",

packages/webdoc-cli/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ async function main(argv: yargs.Argv) {
122122
const documentedInterface = external.fromTree(documentTree);
123123
const db = exportTaffy(documentTree);
124124

125+
documentedInterface.metadata.linker = "(unsigned)";
126+
documentedInterface.metadata.siteDomain = config.template.siteDomain;
127+
documentedInterface.metadata.siteRoot = config.template.siteRoot;
128+
125129
const _path = `${getTemplate(config)}/publish`;
126130
// $FlowFixMe[unsupported-syntax]
127131
const template = require(_path);

packages/webdoc-default-template/helper/crawl/crawl.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import type {
1414
RootDoc,
1515
DocType,
1616
} from "@webdoc/types";
17-
18-
import type {
19-
LinkTable,
20-
} from "@webdoc/template-library";
21-
17+
import type {DocumentedInterface} from "@webdoc/externalize";
2218
import type {ExplorerTarget} from './crawl-reference-explorer';
2319
2420
export type CategorizedDocumentList = {
@@ -34,9 +30,13 @@ export type CrawlData = {
3430
declare function crawl(tree: RootDoc, index: string): CrawlData;
3531
*/
3632

33+
function crawl(
34+
documentedInterface /*: DocumentedInterface */,
35+
index /*: string */,
36+
)/*: CrawlData */ {
37+
const tree = documentedInterface.root;
3738

38-
function crawl(tree /*: RootDoc */, index /*: string */)/*: CrawlData */ {
39-
buildLinks(tree);
39+
buildLinks(documentedInterface);
4040

4141
const crawlData /*: CrawlData */ = {
4242
index: buildIndex(tree),
@@ -46,7 +46,7 @@ function crawl(tree /*: RootDoc */, index /*: string */)/*: CrawlData */ {
4646

4747
if (crawlData.reference) {
4848
// Add ClassIndex into explorer after (overview), while preserving order
49-
// $FlowFixMe
49+
// $FlowFixMe[unsupported-syntax]
5050
crawlData.reference.children = Object.assign(...[
5151
...crawlData.reference.children["(overview)"] ? [{
5252
"(overview)": crawlData.reference.children["(overview)"],
@@ -67,22 +67,28 @@ function crawl(tree /*: RootDoc */, index /*: string */)/*: CrawlData */ {
6767

6868
module.exports = ({crawl}/*: {crawl: typeof crawl} */);
6969

70-
function buildLinks(tree /*: RootDoc */) /*: LinkTable */ {
71-
const linkTable = {};
70+
function buildLinks(documentedInterface /*: DocumentedInterface */) /*: void */ {
71+
const registry = documentedInterface.registry;
7272

73-
model.traverse(tree, (doc) => {
73+
model.traverse(documentedInterface.root, (doc) => {
7474
if (doc.type === "RootDoc") {
7575
doc.packages.forEach((packageDoc) => {
76-
linkTable[packageDoc.path] = linker.getURI(packageDoc);
76+
if (!registry[packageDoc.id]) {
77+
registry[packageDoc.id] = {};
78+
}
79+
80+
registry[packageDoc.id].uri = linker.getURI(packageDoc);
7781
});
7882

7983
return;
8084
}
8185

82-
linkTable[doc.path] = linker.getURI(doc);
83-
});
86+
if (!registry[doc.id]) {
87+
registry[doc.id] = {};
88+
}
8489

85-
return linkTable;
90+
registry[doc.id].uri = linker.getURI(doc);
91+
});
8692
}
8793

8894
function buildIndex(

packages/webdoc-default-template/publish.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ exports.publish = async function publish(options /*: PublishOptions */) {
6464
const config = options.config;
6565

6666
linker.siteRoot = config.template.siteRoot;
67+
options.documentedInterface.metadata.linker = "require('@webdoc/template-library').LinkerPlugin";
6768

6869
const docTree = options.documentTree;
6970
const outDir = path.normalize(options.config.opts.destination);
@@ -72,7 +73,7 @@ exports.publish = async function publish(options /*: PublishOptions */) {
7273

7374
fse.ensureDir(outDir);
7475

75-
const crawlData = crawl(docTree, index);
76+
const crawlData = crawl(options.documentedInterface, index);
7677
const appBarItems = _.merge(config.template.appBar.items, {
7778
/* NOTE: config.template.appBar.items is the primary object so we retain the order as the user
7879
desires. */

packages/webdoc-externalize/src/types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export type SerializedReturn = {
2727
export type DocumentedInterface = {
2828
version: string;
2929
metadata: {
30+
siteRoot?: string;
31+
siteDomain?: string;
3032
linker?: "require('@webdoc/template-library').LinkerPlugin" | string;
3133
[string]: string;
3234
};
@@ -36,4 +38,4 @@ export type DocumentedInterface = {
3638
uri: string;
3739
};
3840
};
39-
};
41+
};

0 commit comments

Comments
 (0)