jazz it up

This commit is contained in:
Chris Wanstrath 2025-07-28 09:57:29 -07:00
parent 2613e241fa
commit 11b693c5cb

View File

@ -9,10 +9,15 @@ import { Layout } from "./components/Layout"
import { Project } from "./components/Project"
const PROJECTS_DIR = ".."
const WORKSHOP_REPO = "https://github.com/probablycorey/the-rabbit-hole"
const WORKSHOP_REPO = "https://github.com/probablycorey/the-workshop"
const CUBBY_DIR = "./cubby"
// ----------------------------------------------------------------------------
// Setup
// ----------------------------------------------------------------------------
const app = new Hono()
const api = new Hono()
app.use("*", async (c, next) => {
const start = Date.now()
@ -26,17 +31,9 @@ app.use('/js/*', serveStatic({ root: './public' }))
app.use('/src/css/*', serveStatic({ root: '.' }))
app.use('/src/js/*', serveStatic({ root: '.' }))
async function projects(): Promise<string[]> {
const subdirs = readdirSync(PROJECTS_DIR, { withFileTypes: true })
.filter((entry: any) => entry.isDirectory())
.map((entry: any) => entry.name).sort()
return subdirs
}
function tsx(node: any) {
return "<!DOCTYPE html>" + render(<Layout>{node}</Layout>)
}
// ----------------------------------------------------------------------------
// Web routes
// ----------------------------------------------------------------------------
app.get("/", async (c) => {
const names = await projects()
@ -122,6 +119,37 @@ app.delete('/:id/delete/:filename', async c => {
}
})
// ----------------------------------------------------------------------------
// API routes
// ----------------------------------------------------------------------------
api.get('/projects', async c => {
const names = await projects()
return c.json(names)
})
// ----------------------------------------------------------------------------
// Helper functions
// ----------------------------------------------------------------------------
async function projects(): Promise<string[]> {
const subdirs = readdirSync(PROJECTS_DIR, { withFileTypes: true })
.filter((entry: any) => entry.isDirectory())
.map((entry: any) => entry.name).sort()
return subdirs
}
function tsx(node: any) {
return "<!DOCTYPE html>" + render(<Layout>{node}</Layout>)
}
// ----------------------------------------------------------------------------
// Server
// ----------------------------------------------------------------------------
app.route('/api', api)
export default {
port: process.env.PORT || 3000,
fetch: app.fetch,