diff --git a/src/components/APIArguments.astro b/src/components/APIArguments.astro new file mode 100644 index 0000000..3d454ff --- /dev/null +++ b/src/components/APIArguments.astro @@ -0,0 +1,61 @@ +--- +const {args} = Astro.props; +--- + +{(args && args.length) ? ( +

Arguments

+ + + {args.map(arg=>( + + + + + ))} + +
+ {arg.name} +
+ + {!arg.is_required && ( + "optional " + )} + {arg.type} + +
+ {arg.description} +
+) : ''} + \ No newline at end of file diff --git a/src/components/APIExamples.astro b/src/components/APIExamples.astro new file mode 100644 index 0000000..54a720d --- /dev/null +++ b/src/components/APIExamples.astro @@ -0,0 +1,71 @@ +--- +import { Code } from "astro/components"; + +const {examples, cmd} = Astro.props; + +if (!examples) return; + +// Treat title and output as metadata and remove from examples +const title = examples.title; +const output = examples.output; +delete examples.title; +delete examples.output; + +function setExample(example, cmd){ + console.log(example, cmd); + document.body.classList.toggle(example); + } + +--- + +
+ {examples ? ( +
+

Examples

+

{title}

+ {Object.keys(examples).map(example=>( + + ))} + {Object.keys(examples).map(example=>( +
+

{example}

+ +
+ ))} +
+ + ) : ''} +
+ \ No newline at end of file diff --git a/src/components/Header.astro b/src/components/Header.astro index 2f6b06c..22a071d 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -8,6 +8,7 @@ const links = [ { name: "Overview", href: "/overview" }, { name: "Playground", href: "/playground" }, { name: "Resources", href: "/resources"}, + { name: "API", href: "/api"}, { name: "Tutorials", href: "/tutorials"}, { name: "Community", href: "/community"} ] diff --git a/src/config.js b/src/config.js index 033205e..cfbdadb 100644 --- a/src/config.js +++ b/src/config.js @@ -88,4 +88,9 @@ export const REDIRECTS = { "/specification": "/spec", "/tour": "/playground", "/whitepaper": "/spec" +} + +export const API_REPOS = { + "lbry-sdk": "docs/api.json", + "lbrycrd": "contrib/devtools/generated/api_v1.json" } \ No newline at end of file diff --git a/src/pages/api.astro b/src/pages/api.astro new file mode 100644 index 0000000..6d55c94 --- /dev/null +++ b/src/pages/api.astro @@ -0,0 +1,19 @@ +--- +import Layout from '../layouts/Layout.astro'; + +import * as config from "../config.js"; + +--- + + + +
+
    + {Object.keys(config.API_REPOS).map(repo=>( +
  • + {repo} +
  • + ))} +
+
+
\ No newline at end of file diff --git a/src/pages/api/[repo].astro b/src/pages/api/[repo].astro index 4d384d9..536962d 100644 --- a/src/pages/api/[repo].astro +++ b/src/pages/api/[repo].astro @@ -1,14 +1,15 @@ --- import Layout from '../../layouts/Layout.astro'; +import TableOfContents from '../../components/TableOfContents.astro'; +import APIArguments from '../../components/APIArguments.astro'; +import APIExamples from '../../components/APIExamples.astro'; + import * as config from "../../config.js"; import { Code } from 'astro:components'; export function getStaticPaths() { - const repos = [ - "lbry-sdk", - ] - const paths = repos.map(repo=>{ + const paths = Object.keys(config.API_REPOS).map(repo=>{ return {params: {repo}}; }); @@ -20,44 +21,127 @@ const { repo } = Astro.params; const tags = (await (await fetch(`https://data.jsdelivr.com/v1/packages/gh/${config.GITHUB_ORG}/${repo}`)).json()).versions; tags.unshift({version: "master"}); -const docs = (await (await fetch(`https://cdn.jsdelivr.net/gh/${config.GITHUB_ORG}/${repo}/docs/api.json`)).json()); -console.log(docs); +const tag = tags[0]; +let docs = (await (await fetch(`https://cdn.jsdelivr.net/gh/${config.GITHUB_ORG}/${repo}@${tag.version}/${config.API_REPOS[repo]}`)).json()); + + +// Convert lbrycrd docs to the same structure as lbry-sdk +if (repo === 'lbrycrd') { + const crd = {}; + for (let i in docs) { + if (!crd[docs[i].namespace]) crd[docs[i].namespace] = { + doc: docs[i].namespace, + commands: [] + }; + crd[docs[i].namespace].commands.push(docs[i]); + console.log(docs[i]); + + //docs.main[i].command = docs.main[i].name; + } + docs = crd; +} + +const headings: Array = []; + +// Generate headings +Object.keys(docs).forEach(group=>{ + headings.push({ + slug: group, + text: group.charAt(0).toUpperCase() + group.substr(1).toLowerCase(), + depth: 2 + }); + + docs[group].commands.forEach(cmd=>{ + headings.push({ + slug: cmd.name, + text: cmd.name, + depth: 3 + }); + }) + +}); --- -
Looking at repo: {repo}!
- + + +
\ No newline at end of file