From 22a9114f7d9eff62d1624aa1aaca0fdfbde53461 Mon Sep 17 00:00:00 2001 From: Pigges Date: Wed, 23 Apr 2025 02:31:18 +0200 Subject: [PATCH] migrate to hono and bun --- Dockerfile | 6 +- app/client.js | 100 +- app/components/api/header-blockchain.js | 3 +- app/components/api/header-sdk.js | 3 +- app/components/ecosystem/index.js | 14 +- .../ecosystem/module-applications.js | 6 +- app/components/ecosystem/module-lbry.js | 6 +- app/components/ecosystem/module-lbrycrd.js | 6 +- .../ecosystem/submodule-chainquery.js | 6 +- .../ecosystem/submodule-lighthouse.js | 6 +- .../ecosystem/submodule-reflector.js | 6 +- app/components/ecosystem/submodule-wallet.js | 6 +- app/components/edit-link.js | 6 +- app/components/footer.js | 10 +- app/components/glossary-toc.js | 2 +- app/components/head.js | 21 +- app/components/link-grid.js | 4 +- app/components/markdown.js | 15 +- app/components/mission-statement.js | 3 +- app/components/navigation.js | 3 +- app/components/overview.js | 18 +- app/components/playground.js | 9 +- app/components/resources-link-grid.js | 8 +- app/components/wrapper.js | 23 +- app/helpers/fetch-metadata.js | 16 +- app/helpers/github.js | 15 +- app/index.js | 132 +- app/modules/markdown-it-sup.js | 2 +- app/modules/relative-date.js | 3 +- app/sockets.js | 14 +- app/views/404.js | 6 +- app/views/api.js | 41 +- app/views/home.js | 9 +- app/views/redirect.js | 26 +- app/views/spec.js | 16 +- bun.lock | 949 ++++ config.js | 2 +- index.js | 14 - package-lock.json | 4157 +---------------- package.json | 29 +- 40 files changed, 1412 insertions(+), 4309 deletions(-) mode change 100755 => 100644 app/client.js mode change 100755 => 100644 app/index.js create mode 100644 bun.lock delete mode 100755 index.js diff --git a/Dockerfile b/Dockerfile index 33f8cd4..7054366 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ -FROM node:22 +FROM oven/bun:1.2.10-alpine WORKDIR /app COPY package.json package.json COPY package-lock.json package-lock.json -RUN npm install --force +RUN bun install COPY . . EXPOSE 8080 -CMD [ "npm", "start", "--force" ] \ No newline at end of file +CMD [ "bun", "run", "start" ] \ No newline at end of file diff --git a/app/client.js b/app/client.js old mode 100755 new mode 100644 index 388c0e8..0e69d05 --- a/app/client.js +++ b/app/client.js @@ -1,71 +1,33 @@ -"use strict"; +import { Hono } from "hono"; + +import head from "./components/head.js"; +import wrapper from "./components/wrapper.js"; + +import home from "./views/home.js"; +import api from "./views/api.js"; +import spec from "./views/spec.js"; +import redirect from "./views/redirect.js"; + +const app = new Hono(); + +app.get("/", page(home)); + +app.get("/api/:wildcard", page(api)); +app.get("/spec", page(spec)); +app.get("*", page(redirect)); + +function page(view) { + return async (c, emit) => { + return c.html(` + + + ${head(c)} + ${await wrapper(view)(c)} + + `); + }; + } + - -// I M P O R T S - -import async from "choo-async"; -import asyncHtml from "choo-async/html"; -import choo from "choo"; -import ssr from "choo-ssr"; - -// U T I L S - -import head from "./components/head"; -import wrapper from "./components/wrapper"; - - - -// P R O G R A M - -function main() { - const app = async(choo()); - - const page = view => ( - shell( - ssr.head( - head, - ssr.state() - ), - ssr.body(wrapper(view)) - ) - ); - - app.use(ssr()); - - app.route("/", page(require("./views/home"))); - app.route("/api/*", page(require("./views/api"))); - app.route("/spec", page(require("./views/spec"))); - app.route("/*", page(require("./views/redirect"))); - - app.mount("html"); - - return app; -} - -if (typeof window !== "undefined") main(); - - - -// E X P O R T - -module.exports = exports = main; - - - -// H E L P E R - -function shell(head, body) { - return (state, emit) => { - const bodyPromise = Promise.resolve(body(state, emit)); - const headPromise = bodyPromise.then(() => head(state, emit)); // resolve `head` once `body` is resolved - - return asyncHtml` - - - ${headPromise} - ${bodyPromise} - - `; - }; -} +export default app; \ No newline at end of file diff --git a/app/components/api/header-blockchain.js b/app/components/api/header-blockchain.js index e7b1f27..a8be7da 100644 --- a/app/components/api/header-blockchain.js +++ b/app/components/api/header-blockchain.js @@ -4,7 +4,8 @@ // I M P O R T -import html from "choo/html"; +import { html } from 'hono/html' + diff --git a/app/components/api/header-sdk.js b/app/components/api/header-sdk.js index c4008ed..72a44bc 100644 --- a/app/components/api/header-sdk.js +++ b/app/components/api/header-sdk.js @@ -4,7 +4,8 @@ // I M P O R T -import html from "choo/html"; +import { html } from 'hono/html' + diff --git a/app/components/ecosystem/index.js b/app/components/ecosystem/index.js index 4b0be3c..cfc2049 100644 --- a/app/components/ecosystem/index.js +++ b/app/components/ecosystem/index.js @@ -4,13 +4,13 @@ // U T I L S -import applications from "./module-applications"; -import chainquery from "./submodule-chainquery"; -import lbry from "./module-lbry"; -import lbrycrd from "./module-lbrycrd"; -import lighthouse from "./submodule-lighthouse"; -import reflector from "./submodule-reflector"; -import wallet from "./submodule-wallet"; +import applications from "./module-applications.js"; +import chainquery from "./submodule-chainquery.js"; +import lbry from "./module-lbry.js"; +import lbrycrd from "./module-lbrycrd.js"; +import lighthouse from "./submodule-lighthouse.js"; +import reflector from "./submodule-reflector.js"; +import wallet from "./submodule-wallet.js"; diff --git a/app/components/ecosystem/module-applications.js b/app/components/ecosystem/module-applications.js index 2eff060..d3d8788 100644 --- a/app/components/ecosystem/module-applications.js +++ b/app/components/ecosystem/module-applications.js @@ -4,13 +4,13 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `
× @@ -28,7 +28,7 @@ export default () => `
- ${markdown("./documents/partials/overview/applications.md")} + ${await markdown("./documents/partials/overview/applications.md")}
`; diff --git a/app/components/ecosystem/module-lbry.js b/app/components/ecosystem/module-lbry.js index c74ce99..13913e6 100644 --- a/app/components/ecosystem/module-lbry.js +++ b/app/components/ecosystem/module-lbry.js @@ -4,13 +4,13 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `
× @@ -27,7 +27,7 @@ export default () => `
- ${markdown("./documents/partials/overview/lbrysdk.md")} + ${await markdown("./documents/partials/overview/lbrysdk.md")}
`; diff --git a/app/components/ecosystem/module-lbrycrd.js b/app/components/ecosystem/module-lbrycrd.js index ab8f76a..8b79ae8 100644 --- a/app/components/ecosystem/module-lbrycrd.js +++ b/app/components/ecosystem/module-lbrycrd.js @@ -4,13 +4,13 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `
× @@ -27,7 +27,7 @@ export default () => `
- ${markdown("./documents/partials/overview/lbrycrd.md")} + ${await markdown("./documents/partials/overview/lbrycrd.md")}
`; diff --git a/app/components/ecosystem/submodule-chainquery.js b/app/components/ecosystem/submodule-chainquery.js index f5ebb8e..79e2958 100644 --- a/app/components/ecosystem/submodule-chainquery.js +++ b/app/components/ecosystem/submodule-chainquery.js @@ -4,19 +4,19 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `

chainquery

- ${markdown("./documents/partials/overview/chainquery.md")} + ${await markdown("./documents/partials/overview/chainquery.md")}
    diff --git a/app/components/ecosystem/submodule-lighthouse.js b/app/components/ecosystem/submodule-lighthouse.js index 45dece8..5360972 100644 --- a/app/components/ecosystem/submodule-lighthouse.js +++ b/app/components/ecosystem/submodule-lighthouse.js @@ -4,19 +4,19 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `

    lighthouse

    - ${markdown("./documents/partials/overview/lighthouse.md")} + ${await markdown("./documents/partials/overview/lighthouse.md")}
      diff --git a/app/components/ecosystem/submodule-reflector.js b/app/components/ecosystem/submodule-reflector.js index 2693fd3..21731b8 100644 --- a/app/components/ecosystem/submodule-reflector.js +++ b/app/components/ecosystem/submodule-reflector.js @@ -4,19 +4,19 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `

      reflector

      - ${markdown("./documents/partials/overview/reflector.md")} + ${await markdown("./documents/partials/overview/reflector.md")}
        diff --git a/app/components/ecosystem/submodule-wallet.js b/app/components/ecosystem/submodule-wallet.js index b8101d3..7f6773e 100644 --- a/app/components/ecosystem/submodule-wallet.js +++ b/app/components/ecosystem/submodule-wallet.js @@ -4,19 +4,19 @@ // U T I L -import markdown from "../../components/markdown"; +import markdown from "../../components/markdown.js"; // E X P O R T -export default () => ` +export default async () => `

        wallet server

        - ${markdown("./documents/partials/overview/wallet-server.md")} + ${await markdown("./documents/partials/overview/wallet-server.md")}
          diff --git a/app/components/edit-link.js b/app/components/edit-link.js index c933251..cced56f 100644 --- a/app/components/edit-link.js +++ b/app/components/edit-link.js @@ -4,11 +4,13 @@ // I M P O R T -import html from "choo/html"; +// import html from "choo/html"; +import { html } from "hono/html" + // U T I L -import config from "../../config"; +import config from "../../config.js"; diff --git a/app/components/footer.js b/app/components/footer.js index 08055e3..19e6e1a 100644 --- a/app/components/footer.js +++ b/app/components/footer.js @@ -4,18 +4,18 @@ // I M P O R T -import html from "choo/html"; +import { html } from "hono/html" // U T I L S -import editLink from "./edit-link"; +import editLink from "./edit-link.js"; // E X P O R T -export default state => { - if (state.hideFooter) +export default context => { + if (context.hideFooter) return ""; return html` @@ -24,7 +24,7 @@ export default state => {
          • ← LBRY.org | - ${editLink(state.href)} + ${editLink(context.req.url)}
          • Overview
          • diff --git a/app/components/glossary-toc.js b/app/components/glossary-toc.js index 499e932..e5a2734 100644 --- a/app/components/glossary-toc.js +++ b/app/components/glossary-toc.js @@ -13,7 +13,7 @@ const titleRegex = /(>.*<)/g; // E X P O R T -export default (state, emit, markdown) => { +export default (context, emit, markdown) => { const collectionOfTocElements = []; const tocElements = markdown.match(renderedHeaderRegex); diff --git a/app/components/head.js b/app/components/head.js index 06cf200..b6f4d3e 100644 --- a/app/components/head.js +++ b/app/components/head.js @@ -1,21 +1,19 @@ -"use strict"; - - - // I M P O R T -import html from "choo/html"; +// import html from "choo/html"; +import { html } from 'hono/html' + // U T I L -import config from "../../config"; +import config from "../../config.js"; // E X P O R T -export default (state, emit) => { - const newMetadata = state.lbry; +export default (context) => { + const newMetadata = context.var.lbry; const description = newMetadata && newMetadata.description ? newMetadata.description : config.meta.description; @@ -24,11 +22,6 @@ export default (state, emit) => { newMetadata.title + " - lbry.tech" : "lbry.tech - " + config.meta.tagline; - if (state.title !== title) - emit(state.events.DOMTITLECHANGE, title); - - state.page = state.page || { }; - return html` ${title} @@ -48,7 +41,7 @@ export default (state, emit) => { - + diff --git a/app/components/link-grid.js b/app/components/link-grid.js index 8e73ed9..edeae5a 100644 --- a/app/components/link-grid.js +++ b/app/components/link-grid.js @@ -4,8 +4,8 @@ // I M P O R T -import html from "choo/html"; - +// import html from "choo/html"; +import { html, raw } from 'hono/html' // E X P O R T diff --git a/app/components/markdown.js b/app/components/markdown.js index 2965229..7fbd63c 100644 --- a/app/components/markdown.js +++ b/app/components/markdown.js @@ -7,12 +7,11 @@ // import decamelize from "decamelize"; import fs from "fs"; import fm from "front-matter"; -import html from "choo/html"; +import { html, raw } from 'hono/html' import m from "markdown-it"; import markdownAnchor from "markdown-it-anchor"; -import markdownSup from "../modules/markdown-it-sup"; +import markdownSup from "../modules/markdown-it-sup.js"; import path from "path"; -import raw from "choo/html/raw"; // U T I L S @@ -43,11 +42,11 @@ const md = m({ // E X P O R T -export default path => { +export default async path => { const markdownFile = fs.readFileSync(path, "utf-8"); const markdownFileDetails = fm(markdownFile); const renderedMarkdown = md.render(markdownFileDetails.body); - const updatedMarkdown = wikiFinder(partialFinder(renderedMarkdown)); + const updatedMarkdown = wikiFinder(await partialFinder(renderedMarkdown)); return html` ${raw(updatedMarkdown)} @@ -58,7 +57,7 @@ export default path => { // H E L P E R S -function partialFinder(markdownBody) { +async function partialFinder(markdownBody) { const regexToFindPartials = /<\w+ ?\/>/g; const partials = markdownBody.match(regexToFindPartials); @@ -73,10 +72,10 @@ function partialFinder(markdownBody) { markdownBody = markdownBody.replace(partial, ""); else { - const partialFunction = require(path.join(__dirname, "..", `./components/${filename}.js`)); + const { default: partialFunction } = await import(import.meta.resolve(`../components/${filename}.js`)); if (filename === "glossary-toc") markdownBody = markdownBody.replace(partial, partialFunction.default); - else markdownBody = markdownBody.replace(partial, `
        ${partialFunction.default()}
        `); + else markdownBody = markdownBody.replace(partial, `
        ${await partialFunction()}
        `); } } } diff --git a/app/components/mission-statement.js b/app/components/mission-statement.js index 34b4a78..335b2b7 100644 --- a/app/components/mission-statement.js +++ b/app/components/mission-statement.js @@ -4,7 +4,8 @@ // I M P O R T -import html from "choo/html"; +import { html } from 'hono/html' + diff --git a/app/components/navigation.js b/app/components/navigation.js index 39f96b3..ff1960c 100644 --- a/app/components/navigation.js +++ b/app/components/navigation.js @@ -4,7 +4,8 @@ // I M P O R T -import html from "choo/html"; +import { html } from "hono/html" + diff --git a/app/components/overview.js b/app/components/overview.js index 2f523dc..2778f42 100644 --- a/app/components/overview.js +++ b/app/components/overview.js @@ -12,28 +12,28 @@ import { lighthouse, reflector, wallet -} from "./ecosystem"; +} from "./ecosystem/index.js"; // E X P O R T -export default () => ` +export default async () => `
        - ${lbrycrd()} - ${lbry()} - ${applications()} + ${await lbrycrd()} + ${await lbry()} + ${await applications()}
        `; diff --git a/app/components/playground.js b/app/components/playground.js index 6c749cc..dbe4cc5 100644 --- a/app/components/playground.js +++ b/app/components/playground.js @@ -1,13 +1,6 @@ -"use strict"; - - - // I M P O R T S -import html from "choo/html"; -import raw from "choo/html/raw"; - - +import { html, raw } from 'hono/html' // E X P O R T diff --git a/app/components/resources-link-grid.js b/app/components/resources-link-grid.js index 9dcffb7..9164e9e 100644 --- a/app/components/resources-link-grid.js +++ b/app/components/resources-link-grid.js @@ -1,12 +1,6 @@ -"use strict"; - - - // U T I L -import linkGrid from "./link-grid"; - - +import linkGrid from "./link-grid.js"; // E X P O R T diff --git a/app/components/wrapper.js b/app/components/wrapper.js index 04a6378..d6f8e2d 100644 --- a/app/components/wrapper.js +++ b/app/components/wrapper.js @@ -1,33 +1,30 @@ -"use strict"; - - - // I M P O R T -import asyncHtml from "choo-async/html"; +import { html } from "hono/html" + // U T I L S -import config from "../../config"; -import footer from "./footer"; -import navigation from "./navigation"; +import config from "../../config.js"; +import footer from "./footer.js"; +import navigation from "./navigation.js"; // E X P O R T -export default children => (state, emit) => { - return asyncHtml` +export default children => async (context) => { + return html`
        - ${navigation(state.href)} + ${navigation(context.req.url)} - ${children.default(state, emit)} - ${footer(state, emit)} + ${await children(context)} + ${footer(context)}
        `; }; diff --git a/app/helpers/fetch-metadata.js b/app/helpers/fetch-metadata.js index 358ae13..3fe888e 100644 --- a/app/helpers/fetch-metadata.js +++ b/app/helpers/fetch-metadata.js @@ -1,20 +1,16 @@ -"use strict"; - - - // I M P O R T S import prism from "prismjs"; -import raw from "choo/html/raw"; +import { raw } from 'hono/html' // U T I L S -import publishMeme from "./publish-meme"; -import lbrytvAPI from "../helpers/lbrytv-sdk"; +import publishMeme from "./publish-meme.js"; +import lbrytvAPI from "../helpers/lbrytv-sdk.js"; -import randomString from "./random-string"; -import { send } from "../sockets"; -import uploadImage from "./upload-image"; +import randomString from "./random-string.js"; +import { send } from "../sockets.js"; +import uploadImage from "./upload-image.js"; const allowedQueryMethods = [ "support_create", diff --git a/app/helpers/github.js b/app/helpers/github.js index 8ba7c44..3caea66 100644 --- a/app/helpers/github.js +++ b/app/helpers/github.js @@ -7,7 +7,7 @@ // U T I L S -import relativeDate from "../modules/relative-date"; +import relativeDate from "../modules/relative-date.js"; let githubFeed; @@ -266,10 +266,7 @@ async function generateGitHubFeed(displayGitHubFeed) { displayGitHubFeed(`

        GitHub

        -
        Last updated: ${lastGithubFeedUpdate.format("YYYY-MM-DD") - .replace(/-/g, "·")} at ${lastGithubFeedUpdate - .format("UTC:H:mm:ss A") - .toLowerCase()} UTC
        +
        Last updated: ${lastGithubFeedUpdate.date} at ${lastGithubFeedUpdate.time} UTC
        ${renderedEvents.join("")} `); @@ -324,7 +321,13 @@ async function updateGithubFeed() { } githubFeed = await response.json(); - lastGithubFeedUpdate = new Date(); + const now = new Date(); + lastGithubFeedUpdate = { + date: now.toISOString().split("T")[0], + time: now.toLocaleTimeString('en-US', { + timeZone: 'UTC' + }) + }; } diff --git a/app/index.js b/app/index.js old mode 100755 new mode 100644 index d69be24..83c08c6 --- a/app/index.js +++ b/app/index.js @@ -1,65 +1,89 @@ -"use strict"; +import { Hono } from "hono"; +import { serve } from "@hono/node-server"; +import { createBunWebSocket } from 'hono/bun'; +import { serveStatic } from "@hono/node-server/serve-static"; +import { secureHeaders } from 'hono/secure-headers'; +import { readFileSync } from 'fs'; + +import client from "./client.js"; +import handleSocketMessages from "./sockets.js"; + +import dotenv from "dotenv"; + + +if (!process.versions.bun) dotenv.config(); + + +const { upgradeWebSocket, websocket } = + createBunWebSocket() -// P A C K A G E S +const redirects = JSON.parse(readFileSync('./app/data/redirects.json', 'utf8')); -import compress from "fastify-compress"; -import fastify from "fastify"; -import ssr from "choo-ssr/fastify"; -import statik from "fastify-static"; -import websockets from "fastify-ws"; +const app = new Hono({ strict: true }); -// U T I L S - -import handleSocketMessages from "./sockets"; -import redirects from "./data/redirects.json"; - -const server = fastify({ - logger: { - level: "warn", - prettyPrint: process.env.NODE_ENV === "development", +// Own trimTrailingSlash function because hono's middleware doesn't work? +app.use(async (c, next)=>{ + if ((c.req.method === "GET" || c.req.method === "HEAD") && c.req.path !== "/" && c.req.path.at(-1) === "/") { + const url = new URL(c.req.url); + url.pathname = url.pathname.substring(0, url.pathname.length - 1); + c.res = c.redirect(url.toString(), 301); } -}); + await next(); +}) +app.use(secureHeaders()) - -// P R O G R A M - -server - .register(compress) - .register(websockets) - .register(statik, { - prefix: "/assets/", - root: `${__dirname}/dist/` +// Mount websocket +app.get( + '/', + upgradeWebSocket((c) => { + return { + onMessage(event, ws) { + return handleSocketMessages(ws, JSON.parse(event.data)); + }, + onClose: () => { + // console.log('Connection closed') + }, + } }) - .register(ssr, { - app: require("./client") +); + +// Mount static files +app.get( + "/assets/*", + serveStatic({ + root: "./app/dist", + rewriteRequestPath: (path) => { + // return path + return path.replace(/^\/assets/, "/"); + } + }) +) + +// Mount redirects +app.use('*', async (c, next)=>{ + if (Object.keys(redirects).includes(c.req.path)) return c.redirect(redirects[c.req.path]) + await next(); +}) + + + + +app.route("/", client); + + +if (!process.versions.bun) { + serve({ + fetch: app.fetch, + port: process.env.PORT || 8080 }) - .addHook("preHandler", (request, reply, next) => { - if (redirects[request.raw.originalUrl]) - reply.redirect(301, redirects[request.raw.originalUrl]); + process.stdout.write(`\n— ⚡ ${process.env.PORT || 8080}\n`); +} - next(); - }) - .ready(err => { - if (err) - throw err; - - server.ws.on("connection", socket => { - socket.on("message", data => { - data = JSON.parse(data); - return handleSocketMessages(socket, data); - }); - - socket.on("close", () => socket.terminate()); - }); - }); - - - -// B E G I N - -server.listen(process.env.PORT || 8080, process.env.IP || "0.0.0.0", async() => { - process.stdout.write(`\n— ⚡ ${server.server.address().port}\n`); -}); +export default { + fetch: app.fetch, + websocket, + port: process.env.PORT || 8080 +} \ No newline at end of file diff --git a/app/modules/markdown-it-sup.js b/app/modules/markdown-it-sup.js index ac2c580..5aa0f1a 100644 --- a/app/modules/markdown-it-sup.js +++ b/app/modules/markdown-it-sup.js @@ -86,6 +86,6 @@ function superscript(state, silent) { // E X P O R T -module.exports = exports = function sup_plugin(md) { // eslint-disable-line camelcase +export default function sup_plugin(md) { // eslint-disable-line camelcase md.inline.ruler.after("emphasis", "sup", superscript); }; diff --git a/app/modules/relative-date.js b/app/modules/relative-date.js index 7a981f7..498e9b2 100644 --- a/app/modules/relative-date.js +++ b/app/modules/relative-date.js @@ -52,5 +52,4 @@ const relativeDate = (() => { // E X P O R T -if (typeof module !== "undefined" && module.exports) - module.exports = exports = relativeDate; +export default relativeDate; \ No newline at end of file diff --git a/app/sockets.js b/app/sockets.js index 180f2a6..ba799ce 100644 --- a/app/sockets.js +++ b/app/sockets.js @@ -1,17 +1,13 @@ -"use strict"; - - - // I M P O R T S -import html from "choo/html"; +import { html } from 'hono/html' // U T I L S -import apiPage from "./views/api"; -import fetchMetadata from "./helpers/fetch-metadata"; -import lbrytvAPI from "./helpers/lbrytv-sdk"; -import { generateGitHubFeed } from "./helpers/github"; +import apiPage from "./views/api.js"; +import fetchMetadata from "./helpers/fetch-metadata.js"; +import lbrytvAPI from "./helpers/lbrytv-sdk.js"; +import { generateGitHubFeed } from "./helpers/github.js"; import { URL } from "url"; diff --git a/app/views/404.js b/app/views/404.js index 328b8a0..df0e58f 100644 --- a/app/views/404.js +++ b/app/views/404.js @@ -1,10 +1,6 @@ -"use strict"; - - - // I M P O R T -import html from "choo/html"; +import { html } from 'hono/html' diff --git a/app/views/api.js b/app/views/api.js index 0ec5ad6..ae822cb 100644 --- a/app/views/api.js +++ b/app/views/api.js @@ -1,16 +1,15 @@ -"use strict"; - - - // I M P O R T S -import asyncHtml from "choo-async/html"; +import { html } from 'hono/html' // U T I L S -import headerBlockchain from "../components/api/header-blockchain"; -import headerSdk from "../components/api/header-sdk"; -import redirects from "../data/redirects.json"; +import headerBlockchain from "../components/api/header-blockchain.js"; +import headerSdk from "../components/api/header-sdk.js"; +import { readFileSync } from 'fs'; +// import redirects from './app/data/redirects.json' assert { type: 'json' }; + +const redirects = JSON.parse(readFileSync('./app/data/redirects.json', 'utf8')); const cache = new Map(); const filePathBlockchain = "/contrib/devtools/generated/api_v1.json"; @@ -21,15 +20,15 @@ const rawGitHubBase = "https://cdn.jsdelivr.net/gh/lbryfoundation/"; // E X P O R T -export default async(state) => { - const { tag } = state; - const { wildcard } = state.params; +export default async(context) => { + const { tag } = context; + const wildcard = context.req.param('wildcard'); const repository = wildcard === "sdk" ? "lbry-sdk" : "lbrycrd"; - state.lbry = { + context.var.lbry = { title: tag ? tag + " API Documentation" : "API Documentation", description: "See API documentation, signatures, and sample calls for the LBRY APIs." }; @@ -40,11 +39,11 @@ export default async(state) => { try { const apiResponse = await parseApiFile({ repo: repository, tag: currentTag }); - return asyncHtml` + return html`
        @@ -63,11 +62,11 @@ export default async(state) => {
        - ${asyncHtml(createApiHeader(wildcard, currentTag))} - ${asyncHtml(wildcard === "sdk" ? createSdkContent(apiResponse) : createApiContent(apiResponse))} + ${html(await createApiHeader(wildcard, currentTag))} + ${html(await wildcard === "sdk" ? createSdkContent(apiResponse) : createApiContent(apiResponse))}
        @@ -86,9 +85,9 @@ export default async(state) => { `; } catch(error) { console.log(error); - const redirectUrl = redirects[state.href]; + const redirectUrl = redirects[context.req.url]; - return asyncHtml` + return html(await `