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..5977cb1 --- /dev/null +++ b/src/components/APIArguments.astro @@ -0,0 +1,56 @@ +--- +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..c16383c --- /dev/null +++ b/src/components/APIExamples.astro @@ -0,0 +1,101 @@ +--- +import { Code } from "astro/components"; +import Collapsible from "./Collapsible.astro"; + +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; + +const options = (Object.keys(examples).map(example=> `.${example}`)).join(', '); + +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}

*/} + +
+ ))} +
+ {output && ( + + Output: + + + )} +
+ + ) : ''} + + \ No newline at end of file diff --git a/src/components/Collapsible.astro b/src/components/Collapsible.astro new file mode 100644 index 0000000..3b6f32d --- /dev/null +++ b/src/components/Collapsible.astro @@ -0,0 +1,49 @@ +--- +const {open} = Astro.props; +--- + +
+ +

+

+
+
+ +
+
+ \ 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..3260b8d 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,35 @@ 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": { + "api": "docs/api.json", + "description": "The LBRY SDK for building decentralized, censorship resistant, monetized, digital content apps.", + "playground": true + }, + "lbrycrd": { + "api": "contrib/devtools/generated/api_v1.json", + "description": "The blockchain that provides the digital content namespace for the LBRY protocol" + } +} \ No newline at end of file diff --git a/src/pages/api.astro b/src/pages/api.astro new file mode 100644 index 0000000..801a857 --- /dev/null +++ b/src/pages/api.astro @@ -0,0 +1,95 @@ +--- +import Layout from '../layouts/Layout.astro'; + +import * as config from "../config.js"; + +--- + + + +
+

Exlore the APIs

+
    + {Object.keys(config.API_REPOS).map(repo=>( +
  • +

    {repo}

    +
    +

    {config.API_REPOS[repo].description}

    + + {config.API_REPOS[repo].playground && ( +

    Available in Playground

    + )} +
  • + ))} +
+
+ +
\ 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..c2f6418 --- /dev/null +++ b/src/pages/api/[repo].astro @@ -0,0 +1,213 @@ +--- +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 Collapsible from '../../components/Collapsible.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].api}`)).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 diff --git a/src/styles/global.scss b/src/styles/global.scss index fa1a6ea..870a2d3 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -107,4 +107,13 @@ a { .button-primary:hover { transform: scale(1.1); +} + +// API Docs Examples +body:not(.curl, .lbrynet, .python, .cli) .commands .example:first-of-type { + display: block; +} + +body.curl .example.curl, body.lbrynet .example.lbrynet, body.python .example.python, body.cli .example.cli { + display: block; } \ No newline at end of file