mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 14:16:28 +03:00
The 'In the wild' section at the bottom of /anti-patterns was
mischaracterizing synthetic fixtures as real examples and was buried
deep in a taxonomy of detection rules. The specimens belong somewhere
that frames them as what they actually are: live pages you can click
into to experience Visual Mode. Split them off into a new top-level
page that also finally gives Visual Mode first-class treatment.
- New /visual-mode page, top-level nav item, single-column layout (no
sidebar). Structure:
1. Editorial header with an "Live detection overlay" eyebrow.
2. Live iframe embed of visual-mode-demo.html inside mac-window
chrome, same preview component the homepage uses.
3. "Three ways to run it" section with three method cards:
- /critique runs the overlay inside its browser pass
- `npx impeccable live` starts a standalone overlay server
- Chrome extension, marked coming soon, with a cream bg
4. "Try it live" gallery of the 11 synthetic specimens as
clickable cards. Each links to /antipattern-examples/{id}.html
where the detector script is already injected so the reader
lands on a live overlay.
- scripts/build-sub-pages.js: new renderVisualModeMain(); visualMode
added to outDirs; generator loop writes /visual-mode/index.html.
- server/index.js: new /visual-mode route serving the generated file.
- Top nav on every page gains 'Visual Mode' between Anti-Patterns
and the GitHub pill. Updated the partial + all 4 hand-authored
HTML pages.
- .gitignore adds public/visual-mode/.
- /anti-patterns: 'In the wild' section and its TOC entry removed.
Replaced with a one-line pointer at the end of the lede: "Want to
see them live on real pages? Try Visual Mode." GALLERY_ITEMS stays
in the catalog file (now used by /visual-mode only).
- public/css/sub-pages.css: new .visual-mode-page-body + .visual-mode-*
classes. Ports the mac-window chrome (dots + mono title) from
main.css, adds three-card method grid, and reuses the existing
.gallery-card styles for the specimen list.
Clean up a few em-dashes in the catalog (block comments + one visible
visual example) so the build-time validator stays clean.
Server restart required to pick up the new /visual-mode route.
211 lines
7.8 KiB
JavaScript
211 lines
7.8 KiB
JavaScript
import { serve, file } from "bun";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import homepage from "../public/index.html";
|
|
import cheatsheet from "../public/cheatsheet.html";
|
|
import gallery from "../public/gallery.html";
|
|
import privacy from "../public/privacy.html";
|
|
import {
|
|
getSkills,
|
|
getCommands,
|
|
getCommandSource,
|
|
getPatterns,
|
|
handleFileDownload,
|
|
handleBundleDownload
|
|
} from "./lib/api-handlers.js";
|
|
import { generateSubPages } from "../scripts/build-sub-pages.js";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const ROOT_DIR = path.resolve(__dirname, "..");
|
|
|
|
// Pre-generate sub-pages so dev + prod share the same output shape.
|
|
console.log("📝 Generating sub-pages for dev server...");
|
|
const { files: subPageFiles } = await generateSubPages(ROOT_DIR);
|
|
console.log(`✓ Generated ${subPageFiles.length} sub-page(s)`);
|
|
|
|
// Helper: serve a generated HTML file by absolute path, 404 if missing.
|
|
async function serveGenerated(pagePath) {
|
|
const f = file(pagePath);
|
|
if (!(await f.exists())) return new Response("Not Found", { status: 404 });
|
|
return new Response(f, {
|
|
headers: {
|
|
"Content-Type": "text/html;charset=utf-8",
|
|
"X-Content-Type-Options": "nosniff",
|
|
"X-Frame-Options": "DENY",
|
|
},
|
|
});
|
|
}
|
|
|
|
const server = serve({
|
|
port: process.env.PORT || 3000,
|
|
|
|
routes: {
|
|
"/": homepage,
|
|
"/cheatsheet": cheatsheet,
|
|
"/gallery": gallery,
|
|
"/privacy": privacy,
|
|
|
|
// Generated sub-pages — served directly from the pre-generated files
|
|
"/skills": () => serveGenerated(path.join(ROOT_DIR, "public/skills/index.html")),
|
|
"/skills/:id": (req) => {
|
|
const id = req.params.id.replace(/[^a-z0-9-]/gi, "");
|
|
return serveGenerated(path.join(ROOT_DIR, `public/skills/${id}.html`));
|
|
},
|
|
"/anti-patterns": () => serveGenerated(path.join(ROOT_DIR, "public/anti-patterns/index.html")),
|
|
"/visual-mode": () => serveGenerated(path.join(ROOT_DIR, "public/visual-mode/index.html")),
|
|
"/tutorials": () => serveGenerated(path.join(ROOT_DIR, "public/tutorials/index.html")),
|
|
"/tutorials/:slug": (req) => {
|
|
const slug = req.params.slug.replace(/[^a-z0-9-]/gi, "");
|
|
return serveGenerated(path.join(ROOT_DIR, `public/tutorials/${slug}.html`));
|
|
},
|
|
|
|
// Static assets - all public subdirectories
|
|
"/assets/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
const filePath = `./public${url.pathname}`;
|
|
const assetFile = file(filePath);
|
|
if (await assetFile.exists()) {
|
|
return new Response(assetFile, {
|
|
headers: { "X-Content-Type-Options": "nosniff", "X-Frame-Options": "DENY" }
|
|
});
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
"/css/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
const filePath = `./public${url.pathname}`;
|
|
const assetFile = file(filePath);
|
|
if (await assetFile.exists()) {
|
|
return new Response(assetFile, {
|
|
headers: { "Content-Type": "text/css", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "DENY" }
|
|
});
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
"/js/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
// Check public/js/ first, then fall back to built artifacts
|
|
const headers = { "Content-Type": "application/javascript", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "DENY" };
|
|
const publicFile = file(`./public${url.pathname}`);
|
|
if (await publicFile.exists()) return new Response(publicFile, { headers });
|
|
// Browser detector served from impeccable package
|
|
if (url.pathname === '/js/detect-antipatterns-browser.js') {
|
|
const pkgFile = file('./src/detect-antipatterns-browser.js');
|
|
if (await pkgFile.exists()) return new Response(pkgFile, { headers });
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
// Test fixtures (for browser visual testing)
|
|
"/fixtures/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
const filePath = `./tests${url.pathname}`;
|
|
const assetFile = file(filePath);
|
|
if (await assetFile.exists()) {
|
|
const ext = url.pathname.split('.').pop();
|
|
const types = { html: 'text/html', css: 'text/css', js: 'application/javascript' };
|
|
return new Response(assetFile, {
|
|
headers: { "Content-Type": types[ext] || "application/octet-stream", "X-Content-Type-Options": "nosniff" }
|
|
});
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
"/antipattern-images/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
const filePath = `./public${url.pathname}`;
|
|
const assetFile = file(filePath);
|
|
if (await assetFile.exists()) {
|
|
return new Response(assetFile, {
|
|
headers: { "X-Content-Type-Options": "nosniff" }
|
|
});
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
"/antipattern-examples/*": async (req) => {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) return new Response("Bad Request", { status: 400 });
|
|
const filePath = `./public${url.pathname}`;
|
|
const assetFile = file(filePath);
|
|
if (await assetFile.exists()) {
|
|
return new Response(assetFile, {
|
|
headers: { "Content-Type": "text/html", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "SAMEORIGIN" }
|
|
});
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
|
|
// API: Get all skills
|
|
"/api/skills": {
|
|
async GET() {
|
|
const skills = await getSkills();
|
|
return Response.json(skills);
|
|
},
|
|
},
|
|
|
|
// API: Get all commands
|
|
"/api/commands": {
|
|
async GET() {
|
|
const commands = await getCommands();
|
|
return Response.json(commands);
|
|
},
|
|
},
|
|
|
|
// API: Get patterns and antipatterns
|
|
"/api/patterns": {
|
|
async GET() {
|
|
const patterns = await getPatterns();
|
|
return Response.json(patterns);
|
|
},
|
|
},
|
|
|
|
// API: Get command source content
|
|
"/api/command-source/:id": async (req) => {
|
|
const { id } = req.params;
|
|
const result = await getCommandSource(id);
|
|
if (result && result.error) {
|
|
return Response.json({ error: result.error }, { status: result.status });
|
|
}
|
|
if (!result) {
|
|
return Response.json({ error: "Command not found" }, { status: 404 });
|
|
}
|
|
return Response.json({ content: result });
|
|
},
|
|
|
|
// API: Download individual file
|
|
"/api/download/:type/:provider/:id": async (req) => {
|
|
const { type, provider, id } = req.params;
|
|
return handleFileDownload(type, provider, id);
|
|
},
|
|
|
|
// API: Download provider bundle ZIP
|
|
"/api/download/bundle/:provider": async (req) => {
|
|
const { provider } = req.params;
|
|
return handleBundleDownload(provider);
|
|
},
|
|
},
|
|
|
|
// Serve root-level static files (og-image.png, favicon, robots.txt, etc.)
|
|
fetch(req) {
|
|
const url = new URL(req.url);
|
|
if (url.pathname.includes('..')) {
|
|
return new Response("Bad Request", { status: 400 });
|
|
}
|
|
const filePath = `./public${url.pathname}`;
|
|
const staticFile = file(filePath);
|
|
if (staticFile.size > 0) {
|
|
return new Response(staticFile);
|
|
}
|
|
return new Response("Not Found", { status: 404 });
|
|
},
|
|
|
|
development: process.env.NODE_ENV !== "production",
|
|
});
|
|
|
|
console.log(`🎨 impeccable.style running at ${server.url}`);
|
|
|