Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline API reference #532

Merged
merged 162 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
4ec9c7d
Pull up module info to site/
KnorpelSenf Oct 25, 2022
b57aa5e
Draft API gen script
KnorpelSenf Oct 25, 2022
9f34a82
Generate API reference on CI
KnorpelSenf Oct 25, 2022
4d52792
Refactorings and improvements, move /api/ to /ref/
KnorpelSenf Nov 13, 2022
09a8904
fix: add escaping
KnorpelSenf Nov 14, 2022
4ba1424
Ignore deno lock
KnorpelSenf Nov 20, 2022
728d8b1
Allow running the script on local modules for testing
KnorpelSenf Nov 20, 2022
fa3e049
Add more details
KnorpelSenf Nov 20, 2022
3766e22
Add TOC
KnorpelSenf Nov 20, 2022
ccfa5c8
Format files after generating them
KnorpelSenf Nov 20, 2022
96ff40f
Replace API reference links to core
KnorpelSenf Nov 20, 2022
9739272
Skip formatting
KnorpelSenf Nov 20, 2022
75f1f7b
Improve links
KnorpelSenf Nov 20, 2022
02c1a14
Increase build RAM
KnorpelSenf Nov 20, 2022
9b90181
Fix missing links
KnorpelSenf Nov 20, 2022
6c1904d
Run `deno fmt`
KnorpelSenf Nov 23, 2022
46de994
Merge branch 'main' into inline-api-ref
KnorpelSenf Jun 15, 2023
0c1530c
Update API reference in menu
KnorpelSenf Jun 15, 2023
2acb3a4
Update package-lock
KnorpelSenf Jun 15, 2023
19c5ae9
Update deps and revert lock file change
KnorpelSenf Jun 15, 2023
a86bd3f
Fix fmt
KnorpelSenf Jun 15, 2023
93a1e11
Update CI config
KnorpelSenf Jun 15, 2023
6a72482
Do not generate lock file
KnorpelSenf Jun 15, 2023
af9d80e
Temporarily disable docsearch
KnorpelSenf Jun 15, 2023
010609e
Link to GH not /x
KnorpelSenf Jun 15, 2023
d305450
Merge branch 'main' into inline-api-ref
rojvv Nov 2, 2023
55b0829
Update package-lock.json
rojvv Nov 3, 2023
24a24ff
Overtake
rojvv Nov 3, 2023
5a8d471
Re-enable modules
rojvv Nov 3, 2023
d79495d
Fix fixable dead links
rojvv Nov 3, 2023
c033984
Disable edit buttons
rojvv Nov 4, 2023
ae2f747
WIP
rojvv Nov 4, 2023
e966af0
Remove extra semi-colons
rojvv Nov 4, 2023
a556839
Fix links
rojvv Nov 4, 2023
43f5b35
Fix unnamed bugs
rojvv Nov 4, 2023
c8c7327
Remove duplicate title
rojvv Nov 4, 2023
dda5039
Fix a render bug in ParamRest
rojvv Nov 4, 2023
337251c
Fix more issues
rojvv Nov 4, 2023
d883902
Fix more things
rojvv Nov 4, 2023
fde91a5
Add missed space
rojvv Nov 4, 2023
cc56983
Change ToC title
rojvv Nov 4, 2023
7ac5a0f
Rename
rojvv Nov 4, 2023
5ab42d4
Revert "Rename"
rojvv Nov 4, 2023
479862f
Fix title
rojvv Nov 4, 2023
f6e2086
Fix things
rojvv Nov 5, 2023
7521b09
Render typePredicate
rojvv Nov 5, 2023
dd1a54a
Show method type params
rojvv Nov 5, 2023
7ffbfd3
Remove extra space
rojvv Nov 5, 2023
71deebd
Show more info of properties
rojvv Nov 5, 2023
c4979de
Cleanup
rojvv Nov 5, 2023
7826dcd
Redirect AbortSignal references to MDN
rojvv Nov 5, 2023
14598b7
Properly display boolean literals
rojvv Nov 5, 2023
6e516f0
Render indexedAccess
rojvv Nov 5, 2023
d71438c
More cleanup
rojvv Nov 5, 2023
539bf15
Fix color
rojvv Nov 5, 2023
c13219f
Fix anchors opening in different tab
rojvv Nov 5, 2023
3efbb4f
Properly render type queries
rojvv Nov 5, 2023
17449ba
Nitpick
rojvv Nov 5, 2023
4a686aa
Fix style
rojvv Nov 5, 2023
c7809cc
Fix colors
rojvv Nov 5, 2023
676e93a
Fix colors
rojvv Nov 5, 2023
704ebd0
Render mapped
rojvv Nov 5, 2023
d47ab10
Cleanup
rojvv Nov 5, 2023
3bbe60f
Add source links
rojvv Nov 5, 2023
8171647
Fix things
rojvv Nov 5, 2023
f3a6950
Make source links functional
rojvv Nov 5, 2023
640ed99
Show what an interface extends
rojvv Nov 6, 2023
7f5fb95
The namespace thing
rojvv Nov 6, 2023
b536438
Support @\inheritdoc
rojvv Nov 11, 2023
f7bc833
Remove doc.json
KnorpelSenf Nov 21, 2023
6fc71b2
Generate API ref for everything
KnorpelSenf Nov 21, 2023
627f312
Remove lost console.log
KnorpelSenf Nov 21, 2023
cf3bcf4
Remove lost comments
KnorpelSenf Nov 21, 2023
4a894b1
Run deno fmt
KnorpelSenf Nov 21, 2023
bc9b163
Merge branch 'main' into inline-api-ref
KnorpelSenf Nov 21, 2023
b85d81a
Remove lost .gitignore entry
KnorpelSenf Nov 21, 2023
73415ea
No lock
KnorpelSenf Nov 21, 2023
c375df3
We no longer use /std
KnorpelSenf Nov 21, 2023
7982694
Support grammy.dev/ref
KnorpelSenf Nov 21, 2023
3b425a7
Add more links
KnorpelSenf Nov 21, 2023
05bb36b
Add stats about number of created files
KnorpelSenf Nov 21, 2023
184c6b9
Fix activeMatch for official plugins in ref
KnorpelSenf Nov 21, 2023
1d4a266
Do not format ref
KnorpelSenf Nov 21, 2023
04a933a
Add link to MDN Error
KnorpelSenf Nov 21, 2023
1319407
Add API ref descs
KnorpelSenf Nov 21, 2023
834f7fb
Add missing trailing /
KnorpelSenf Nov 21, 2023
fe722e8
Replace all links
KnorpelSenf Nov 21, 2023
bf3aeb3
Remove incorrect trailing /
KnorpelSenf Nov 21, 2023
625151f
Fixup dead links
KnorpelSenf Nov 21, 2023
e86b8ba
Update std
KnorpelSenf Nov 21, 2023
80c71c6
Generate ref for the chat-members plugin
KnorpelSenf Nov 21, 2023
1ab6f0d
Fix activeMatch for ref
KnorpelSenf Nov 21, 2023
11a504c
Consistently use links in plugin summary sections
KnorpelSenf Nov 21, 2023
e69c381
Generate ref for auto-retry
KnorpelSenf Nov 21, 2023
8ef4426
Do not display private props and methods (#948)
KnorpelSenf Nov 22, 2023
83d2af6
Remove unnecessary code
rojvv Nov 23, 2023
86e8905
Merge branch 'inline-api-ref' of github.com:grammyjs/website into inl…
rojvv Nov 23, 2023
8d75f76
Update site/docs/.vitepress/config.ts
rojvv Nov 23, 2023
bbd20f7
Merge branch 'main' into inline-api-ref
rojvv Nov 23, 2023
f2bed0a
Merge branch 'main' into inline-api-ref
LWJerri Nov 26, 2023
5a6f8f2
Merge branch 'main' into inline-api-ref
rojvv Dec 11, 2023
66c06f4
fix links to console.log mdn
KnorpelSenf Dec 12, 2023
9935769
Merge branch 'main' into inline-api-ref
rojvv Dec 12, 2023
0728006
Merge branch 'main' into inline-api-ref
KnorpelSenf Dec 14, 2023
ae21d1f
Update std
KnorpelSenf Dec 14, 2023
94f4372
Fix multiple editLink insertions
KnorpelSenf Dec 14, 2023
59efc03
Suppress a build warning
KnorpelSenf Dec 14, 2023
d72168a
Merge branch 'main' into inline-api-ref
quadratz Dec 15, 2023
9a567bc
Merge branch 'main' into inline-api-ref
KnorpelSenf Mar 14, 2024
cad6ec7
fix added ref links
KnorpelSenf Mar 14, 2024
a29d005
fix autoquote docs gen
KnorpelSenf Mar 14, 2024
69b590f
cannot generate docs for modules that use npm: imports
KnorpelSenf Mar 14, 2024
1996e8e
cannot gen docs for modules that are not Deno-first
KnorpelSenf Mar 14, 2024
a0683b1
update api gen deps
KnorpelSenf Mar 14, 2024
fbc67b7
reorder modules, re-add auto-retry
KnorpelSenf Mar 16, 2024
b4b0869
fix missing comma
KnorpelSenf Mar 16, 2024
ab49589
add more progress logs and use deno task
KnorpelSenf Mar 16, 2024
47cc69c
rename file
KnorpelSenf Mar 16, 2024
b90f3a1
Merge branch 'main' into inline-api-ref
KnorpelSenf Mar 16, 2024
8adb224
fix some type errors
rojvv Mar 16, 2024
9bd9de5
mh
rojvv Mar 16, 2024
77ee56b
add overview
KnorpelSenf Mar 17, 2024
a2a6370
fix cross-plugin links
KnorpelSenf Mar 17, 2024
4a177cf
generate overview from short descs
KnorpelSenf Mar 17, 2024
b0d85ed
add links
KnorpelSenf Mar 17, 2024
77710e1
fix fmt
KnorpelSenf Mar 17, 2024
2054760
fix file adapter short desc
KnorpelSenf Mar 17, 2024
5133274
fix bad links
KnorpelSenf Mar 17, 2024
c49ca69
support pages three levels deep
KnorpelSenf Mar 17, 2024
ae5f96c
reduce useless logs
KnorpelSenf Mar 17, 2024
1636eac
Revert "reduce useless logs"
KnorpelSenf Mar 17, 2024
670e3ce
only list public or protected properties
KnorpelSenf Mar 17, 2024
e40d799
improve logs
KnorpelSenf Mar 17, 2024
bc94bef
list ctor props for classes
KnorpelSenf Mar 17, 2024
b687882
rewrite links to internal ones
KnorpelSenf Mar 17, 2024
aea0a91
disable edit link for overview
KnorpelSenf Mar 17, 2024
0c6714f
list functions with overloads only once
rojvv Mar 17, 2024
2f38c01
add doc strings for ctor param props from jsdoc tags
KnorpelSenf Mar 17, 2024
8474f1e
it works, will clean it soon
rojvv Mar 17, 2024
1a45d46
cleaup
rojvv Mar 17, 2024
1a60f05
Yes, but
rojvv Mar 17, 2024
d948838
Done
rojvv Mar 17, 2024
8070fe9
Remove redirects
rojvv Mar 17, 2024
90659f4
yes
rojvv Mar 17, 2024
fa86dbf
yes
rojvv Mar 17, 2024
d4a7d07
navvv
rojvv Mar 17, 2024
01a3528
a
rojvv Mar 17, 2024
3cfba44
fmt
rojvv Mar 17, 2024
2e36be0
my opinion
rojvv Mar 17, 2024
3fc7b2e
fix my opinion
rojvv Mar 17, 2024
6a6ec55
fix
rojvv Mar 17, 2024
f484940
fix
rojvv Mar 17, 2024
243b7fb
above
rojvv Mar 17, 2024
b238109
Docs first
rojvv Mar 17, 2024
f8b52a3
yes
rojvv Mar 17, 2024
92081a6
a
rojvv Mar 17, 2024
7fe3721
a
rojvv Mar 17, 2024
8f7679a
jes
rojvv Mar 17, 2024
10ba1b2
mapset
rojvv Mar 17, 2024
674fc08
a
rojvv Mar 17, 2024
c65326a
a
rojvv Mar 17, 2024
0e6013f
a
rojvv Mar 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
run: npm ci
working-directory: site/

- name: Generate API references
run: npm run docs:genapi
working-directory: site/

- name: Build site
run: npm run docs:build
working-directory: site/
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"./site/docs/id/",
"./site/docs/uk/",
"./site/docs/zh/",
"./site/README.md"
"./site/README.md",
"./site/api/",
"./site/docs/.vuepress/plugins/current-versions/build-index.ts"
]
}
2 changes: 2 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"lock": false,
"tasks": {
"check-links": "deno run -r --allow-env=GITHUB_TOKEN --allow-net --allow-read https://raw.githubusercontent.com/grammyjs/link-checker/main/website_cli.ts --clean-url site/docs"
},
Expand All @@ -9,6 +10,7 @@
"./site/docs/.vitepress/cache/",
"./site/docs/.vitepress/.temp/",
"./site/docs/.vitepress/dist/",
"./site/docs/ref/",
"./site/package-lock.json"
]
}
Expand Down
4 changes: 4 additions & 0 deletions site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ cache/

# dist directory
dist/

# generated API reference files
docs/ref/
!docs/ref/README.md
12 changes: 12 additions & 0 deletions site/api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
317 changes: 317 additions & 0 deletions site/api/api_gen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
import { modules } from "../modules.ts";
import * as fs from "std/fs/mod.ts";
import * as path from "std/path/mod.ts";
import { doc } from "deno_doc/mod.ts";
import { renderToString } from "preact-render-to-string";
import { Class } from "./components/Class.tsx";
import { Function } from "./components/Function.tsx";
import {
type DocNode,
DocNodeClass,
DocNodeNamespace,
} from "deno_doc/types.d.ts";
import { ToC } from "./components/ToC.tsx";
import { JSX } from "preact/jsx-runtime";
import { Interface } from "./components/Interface.tsx";
import { Variable } from "./components/Variable.tsx";
import { TypeAlias } from "./components/TypeAlias.tsx";
import { Overview } from "./components/Overview.tsx";
import links from "./external_links.ts";
import { Ref } from "./types.ts";

const out = Deno.args[0];
if (!out) throw new Error("no out!");

const enc = new TextEncoder();

const paths: [string, string, string, string, string, string][] = modules.map(
({
user = "grammyjs",
repo,
branch = "main",
slug,
entrypoint = "src/mod.ts",
name,
description,
shortdescription,
}) => [
`https://raw.githubusercontent.com/${user}/${repo}/${branch}/${entrypoint}`,
path.join(out, slug),
slug,
name,
description,
shortdescription,
],
);

Deno.stdout.writeSync(
enc.encode(`Generating docs for ${paths.length} modules`),
);
const dot = enc.encode(".");
const refs: Array<Ref> = await Promise
.all(
paths.map(
async ([id, path, slug, name, description, shortdescription]) => {
const nodes = await doc(id);
Deno.stdout.writeSync(dot);
return [
nodes.sort((a, b) => a.name.localeCompare(b.name)),
path,
slug,
name,
description,
shortdescription,
];
},
),
);
Deno.stdout.writeSync(enc.encode("done\n"));

function namespaceGetLink(
slug: string,
namespace: DocNodeNamespace,
getLink: (typeRef: string) => string | null,
): typeof getLink {
return (typeRef) => {
const node_ = namespace.namespaceDef.elements.find((v) =>
v.name == typeRef
);
if (node_ !== undefined) {
return "/ref/" + slug + "/" + namespace.name + "/" +
encodeURIComponent(typeRef);
} else {
return getLink(typeRef);
}
};
}

function createDoc(
node: DocNode,
path_: string,
getLink: (repr: string) => string | null,
slug: string,
namespace?: DocNodeNamespace,
classParent?: DocNodeClass,
overloadCount?: number,
) {
let component: JSX.Element | null = null;
switch (node.kind) {
case "class":
component = <Class getLink={getLink} parent={classParent}>{node}</Class>;
break;
case "variable":
component = <Variable getLink={getLink}>{node}</Variable>;
break;
case "function":
component = (
<Function
getLink={getLink}
overloadCount={overloadCount}
>
{node}
</Function>
);
break;
case "interface":
component = (
<Interface
getLink={namespace !== undefined
? namespaceGetLink(slug, namespace, getLink)
: getLink}
namespace={namespace}
>
{node}
</Interface>
);
break;
case "typeAlias":
component = (
<TypeAlias
getLink={namespace !== undefined
? namespaceGetLink(slug, namespace, getLink)
: getLink}
namespace={namespace}
>
{node}
</TypeAlias>
);
break;
}
if (component != null) {
const filename = path.join(path_, `${node.name}.md`);
let contents = renderToString(component);
fs.ensureDirSync(path.dirname(filename));
if (!fs.exists(filename, { isFile: true })) {
contents = "---\neditLink: false\n---\n\n" + contents;
}
Deno.writeTextFileSync(filename, contents, { append: true });
return true;
}
return false;
}

console.log("Purging output folder", out);
try {
Deno.removeSync(out, {
recursive: true,
// Why is this missing from Deno?
/* allowNotExists: true */
});
} catch (err) {
// ignore if missing
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
}

console.log("Creating files");
const allNodes = refs.map(([nodes]) => nodes).flat();
// replace all external links to grammy.dev by internal links
for (const v of allNodes) {
const doc = v.jsDoc;
if (doc !== undefined) {
if (doc.doc !== undefined) {
doc.doc = doc.doc
.replaceAll("https://grammy.dev/", "/");
}
}
}
const coreNodes = refs.find(([, , slug]) => slug === "core")?.[0];
if (coreNodes === undefined) throw new Error("No core ref found!"); // never happens
const typesNodes = refs.find(([, , slug]) => slug === "types")?.[0];
if (typesNodes === undefined) throw new Error("No types ref found!"); // never happens

let count = 0;

for (const [nodes, path_, slug, name, description] of refs) {
/** Defines how to obtain a link to a symbol */
const getLink = (repr: string): string | null => {
// Try getting the link from the current plugin page.
const node = nodes.find((v) => v.name == repr);
if (node !== undefined) {
return "/ref/" + slug + "/" + encodeURIComponent(repr);
}
// Try getting the link from the core ref.
const coreNode = coreNodes.find((v) => v.name === repr);
if (coreNode !== undefined) {
return "/ref/core/" + encodeURIComponent(repr);
}
// Try getting the link from the types ref.
const typesNode = typesNodes.find((v) => v.name === repr);
if (typesNode !== undefined) {
return "/ref/types/" + encodeURIComponent(repr);
}
// Try getting the link externally.
if (repr in links) {
return links[repr]!;
}
// Do not include a link.
return null;
};
const getOverloadCount = (node: DocNode, nodes: DocNode[]) => {
let overloadCount = node.kind == "function"
? nodes.filter((v) => v.kind == "function" && v.name == node.name).length
: undefined;
if (overloadCount == 1) {
overloadCount = undefined;
} else if (overloadCount && overloadCount > 1) {
overloadCount = nodes.filter((v) =>
v.kind == "function" && v.name == node.name
).findIndex((v) => v == node) + 1;
}
return overloadCount;
};

for (const node of nodes) {
if (node.kind == "namespace") {
for (const el of node.namespaceDef.elements) {
createDoc(
el,
path.join(path_, node.name),
namespaceGetLink(slug, node, getLink),
slug,
undefined,
((el.kind == "class" && el.classDef.extends !== undefined)
? node.namespaceDef.elements.find((v) =>
v.kind == "class" &&
v.name == (el as DocNodeClass).classDef.extends
) ?? allNodes.find((v) =>
v.kind == "class" &&
v.name == (el as DocNodeClass).classDef.extends
)
: undefined) as DocNodeClass | undefined,
getOverloadCount(node, nodes),
) && ++count;
}
} else {
let overloadCount = node.kind == "function"
? nodes.filter((v) => v.kind == "function" && v.name == node.name)
.length
: undefined;
if (overloadCount == 1) {
overloadCount = undefined;
} else if (overloadCount && overloadCount > 1) {
overloadCount = nodes.filter((v) =>
v.kind == "function" && v.name == node.name
).findIndex((v) => v == node) + 1;
}
if (node.name == "webhookCallback") {
console.log(overloadCount);
}
createDoc(
node,
path_,
getLink,
slug,
(node.kind == "typeAlias" || node.kind == "interface")
? nodes.filter((v): v is DocNodeNamespace => v.kind == "namespace")
.find((v) => v.name == node.name)
: undefined,
((node.kind == "class" && node.classDef.extends !== undefined)
? allNodes.find((v) =>
v.kind == "class" &&
v.name == (node as DocNodeClass).classDef.extends
)
: undefined) as DocNodeClass | undefined,
getOverloadCount(node, nodes),
) && ++count;
}
}
{
const filename = path.join(path_, "README.md");
const content = `---
editLink: false
---

${
renderToString(
<ToC
name={name + " Reference"}
description={description}
getLink={getLink}
>
{nodes}
</ToC>,
)
}`;

Deno.writeTextFileSync(filename, content);
count++;
}
console.log("Wrote", path_);
}

const overviewPath = path.join(out, "README.md");
Deno.writeTextFileSync(
overviewPath,
`---
editLink: false
---

${renderToString(<Overview refs={refs} />)}
`,
);
count++;
console.log("Wrote overview to", overviewPath);

console.log("Done writing", count, "files.");
Loading
Loading