diff --git a/astro.config.mjs b/astro.config.mjs index 0baf00a..265352f 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,6 +1,7 @@ import { defineConfig } from 'astro/config'; import codeblocks from "@thewebforge/astro-code-blocks"; import preload from "astro-preload"; +import * as config from './src/config.js'; import mdx from "@astrojs/mdx"; @@ -11,5 +12,6 @@ export default defineConfig({ // Copy Button Options copyButtonTitle: 'Copy', copyButtonTooltip: 'Copied to clipboard', -}), mdx()] + }), mdx()], + redirects: config.REDIRECTS, }); \ No newline at end of file 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 f261fb7..7bd4c3c 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 ce13e63..5078fe0 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,7 @@ export const AWESOME_LBRY = "https://github.com/LBRYFoundation/Awesome-LBRY"; export const EDIT_PAGE = "Edit this page"; export const REPOSITORY = "LBRYFoundation/lbry-tech"; +export const GITHUB_ORG = "LBRYFoundation"; export const features = [ { @@ -68,4 +69,28 @@ export const featured = [ title: "Podcatcher", description: "Audio media crawler for lbry." } -] \ No newline at end of file +] + +export const REDIRECTS = { + // "/api/blockchain": "/api/lbrycrd", + // "/api/lbry": "/api/sdk", + // "/api/protocol": "/api/sdk", + // "/play": "/playground", + // "/repository-standards": "/resources/repository-standards", + // "/resources/lbry-claimtrie": "/spec#claimtrie", + // "/resources/schema": "/spec#metadata", + // "/resources/signing-claim": "/resources/claim-signing", + // "/resources/uri": "/spec#urls", + // "/resources/video-lbryandroid": "https://odysee.com/video-2018-10-15053403:e", + // "/resources/video-lbrycrd": "https://odysee.com/intro-to-LBRYcrd:5", + // "/resources/video-lbrydesktop": "https://odysee.com/LBRYAppDesign:7", + // "/resources/video-lbrysdk": "https://odysee.com/@lbrytech:1/lbrynet-dev-setup:9", + // "/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 new file mode 100644 index 0000000..0c64144 --- /dev/null +++ b/src/pages/api/[repo].astro @@ -0,0 +1,188 @@ +--- +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 paths = Object.keys(config.API_REPOS).map(repo=>{ + return {params: {repo}}; + }); + + return paths; +} + +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 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 + }); + }) + +}); + +--- + + + +
+ + + + +
+

{repo} {tag.version}

+

Methods and signatures provided by {repo} are documented below. To build, download, or run the daemon, see the project + README. +

+
+ {Object.keys(docs).map(header=>( +
+

{header}

+ {docs[header].commands.map(cmd=>( +
+

{cmd.name}

+

{cmd.description}

+ + +

Returns

+ +
+
+ ))} +
+ ))} +
+
+
+ + + +
\ No newline at end of file