Skip to content

Commit

Permalink
feat: add github source code link in api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hg-pyun committed Apr 25, 2024
1 parent 98068ae commit f1bd6d1
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 2 deletions.
23 changes: 22 additions & 1 deletion website/markdown-plugin/src/MarkdownFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from "@microsoft/api-documenter";
import { ApiItem } from "@microsoft/api-extractor-model";

import FunctionJson from "./function.json"; // Same file as /website/function.json. Used to judge path inside markdown-plugin, copy inside because of file path issue after build.

import {
FuncParameters,
FuncReturn,
Expand All @@ -33,6 +35,7 @@ type MarkDownType =
class MarkdownFeature extends MarkdownDocumenterFeature {
private _apiItemsWithPages: Set<ApiItem> = new Set<ApiItem>();
private header: string[] = [];
private sourceCodeLink: string[] = [];
private footer: string[] = [];
public onInitialized(): void {
console.log("MarkdownFeature: onInitialized()");
Expand All @@ -48,6 +51,12 @@ class MarkdownFeature extends MarkdownDocumenterFeature {
"<!-- Do not edit this file. It is generated automatically -->",
];

this.sourceCodeLink = [
`[Open Source Code](${this.getSourceCodeLink(
eventArgs.apiItem.displayName,
)})`,
];

this.footer = [];

// remove top title
Expand All @@ -64,7 +73,8 @@ class MarkdownFeature extends MarkdownDocumenterFeature {
eventArgs.pageContent = [
this.header.join("\n"),
splitedPageContent.join("\n\n"),
this.footer.join('\n')
this.sourceCodeLink.join("\n"),
this.footer.join("\n")
].join('\n');
this._apiItemsWithPages.add(eventArgs.apiItem);
}
Expand Down Expand Up @@ -271,6 +281,17 @@ class MarkdownFeature extends MarkdownDocumenterFeature {
),
);
}

private getSourceCodeLink(id: string) {
const path = [];
if (FunctionJson.Lazy.includes(id)) {
path.push("Lazy");
}

path.push(`${id}.ts`);

return `https://github.com/marpple/FxTS/blob/main/src/${path.join("/")}`;
}
}

export default MarkdownFeature;
113 changes: 113 additions & 0 deletions website/markdown-plugin/src/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"Lazy": [
"append",
"chunk",
"compact",
"compress",
"concat",
"concurrent",
"cycle",
"drop",
"dropRight",
"difference",
"differenceBy",
"dropUntil",
"dropWhile",
"entries",
"filter",
"flat",
"flatMap",
"fx",
"intersection",
"intersectionBy",
"keys",
"map",
"peek",
"pipeLazy",
"pluck",
"prepend",
"range",
"reject",
"repeat",
"reverse",
"scan",
"slice",
"split",
"take",
"takeRight",
"takeUntil",
"takeWhile",
"toAsync",
"uniq",
"uniqBy",
"values",
"zip",
"zipWith",
"zipWithIndex"
],
"Strict": [
"add",
"always",
"apply",
"average",
"compactObject",
"consume",
"countBy",
"curry",
"delay",
"each",
"every",
"evolve",
"find",
"findIndex",
"fromEntries",
"groupBy",
"gt",
"gte",
"head",
"identity",
"includes",
"indexBy",
"isArray",
"isBoolean",
"isEmpty",
"isNil",
"isNumber",
"isObject",
"isString",
"isUndefined",
"join",
"juxt",
"last",
"lt",
"lte",
"max",
"memoize",
"min",
"negate",
"noop",
"not",
"nth",
"omit",
"omitBy",
"partition",
"pick",
"pickBy",
"pipe",
"prop",
"props",
"reduce",
"reduceLazy",
"size",
"some",
"sort",
"sortBy",
"sum",
"tap",
"throwError",
"throwIf",
"toArray",
"unicodeToArray",
"unless"
]
}
2 changes: 1 addition & 1 deletion website/markdown-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"node"
] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
"resolveJsonModule": true /* Enable importing .json files */,
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
Expand Down

0 comments on commit f1bd6d1

Please sign in to comment.