Skip to content

Curated website design inspiration gallery, open zero-auth MCP server for AI agents, and shareable moodboard lists.

7.1 KB
Raw Blame
import { existsSync } from "node:fs";
import { mkdir, rm, cp, readFile, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { join } from "node:path";
import sharp from "sharp";
import { build } from "esbuild";
import {
  gallery,
  detail,
  info,
  notFound,
  ORIGIN,
  slug,
} from "../apps/gallery/render.mjs";
import { validateSites } from "./gallery-catalog.mjs";

const root = fileURLToPath(new URL("../apps/gallery/", import.meta.url)),
  out = join(root, "out");
const sites = await validateSites(
  JSON.parse(await readFile(join(root, "sites.json"), "utf8")),
  root,
);
await rm(out, { recursive: true, force: true });
await mkdir(join(out, "images"), { recursive: true });
await mkdir(join(out, "assets"), { recursive: true });
await mkdir(join(out, "fonts"), { recursive: true });

for (const name of [
  "geist-variable.woff2",
  "geist-mono-variable.woff2",
  "OFL.txt",
])
  await cp(join(root, "fonts", name), join(out, "fonts", name));
await cp(join(root, "favicon.svg"), join(out, "favicon.svg"));
const faviconBuf = await readFile(join(root, "favicon.svg"));
await Promise.all([
  sharp(faviconBuf, { density: 384 })
    .resize(180, 180)
    .png({ compressionLevel: 9 })
    .toFile(join(out, "apple-touch-icon.png")),
  sharp(faviconBuf, { density: 384 })
    .resize(192, 192)
    .png({ compressionLevel: 9 })
    .toFile(join(out, "icon-192.png")),
  sharp(faviconBuf, { density: 512 })
    .resize(512, 512)
    .png({ compressionLevel: 9 })
    .toFile(join(out, "icon-512.png")),
]);
await cp(join(root, "gallery.css"), join(out, "gallery.css"));
await build({
  entryPoints: [join(root, "gallery.js"), join(root, "share-studio.js")],
  bundle: true,
  minify: true,
  format: "esm",
  target: "es2022",
  outdir: out,
});

async function page(path, html) {
  const dir = join(out, path);
  await mkdir(dir, { recursive: true });
  await writeFile(join(dir, "index.html"), html);
}

await page("", gallery(sites));
await page("about", info("about"));
await page("submit", info("submit"));
await page("mcp", info("mcp"));
await writeFile(join(out, "404.html"), notFound());
const categories = [...new Set(sites.map((x) => x.category))];
for (const category of categories)
  await page("categories/" + slug(category), gallery(sites, { category }));

// Process detail pages and responsive image derivatives in parallel chunks.
const CONCURRENCY = 8;
let cursor = 0;
async function processSiteWorker() {
  while (cursor < sites.length) {
    const site = sites[cursor++];
    const image = join(root, site.image);
    const tasks = [
      cp(image, join(out, site.image)),
      page("sites/" + site.id, detail(site, sites)),
      // Lightweight 16:10 card thumbnail for mobile/touch (prevents iOS Safari Jetsam OOM).
      sharp(image)
        .resize(640, 400, { fit: "cover", position: "top" })
        .jpeg({ quality: 80, mozjpeg: true })
        .toFile(join(out, "images", `${site.id}-thumb.jpg`)),
      // Scrollable desktop card preview (capped height to keep GPU textures lean).
      sharp(image)
        .resize({
          width: 720,
          height: 2200,
          fit: "cover",
          position: "top",
          withoutEnlargement: true,
        })
        .jpeg({ quality: 76, mozjpeg: true })
        .toFile(join(out, "images", `${site.id}-720.jpg`)),
      // Social OpenGraph image.
      sharp(image)
        .resize(1200, 630, { fit: "cover", position: "top" })
        .jpeg({ quality: 85 })
        .toFile(join(out, "images", `${site.id}-og.jpg`)),
    ];
    if (site.video) {
      tasks.push(cp(join(root, site.video), join(out, site.video)));
    }
    await Promise.all(tasks);
  }
}
await Promise.all(
  Array.from({ length: Math.min(CONCURRENCY, sites.length || 1) }, processSiteWorker),
);

const staticOg = join(root, "og.jpg");
if (existsSync(staticOg)) {
  await cp(staticOg, join(out, "og.jpg"));
} else {
  const cover = Buffer.from(
    `<svg width="1200" height="630" xmlns="http://www.w3.org/2000/svg"><defs><radialGradient id="ga" cx="35%" cy="0%" r="65%"><stop offset="0%" stop-color="#818cf8" stop-opacity="0.28"/><stop offset="100%" stop-color="#0b0b0b" stop-opacity="0"/></radialGradient><radialGradient id="gb" cx="75%" cy="10%" r="55%"><stop offset="0%" stop-color="#f472b6" stop-opacity="0.16"/><stop offset="100%" stop-color="#0b0b0b" stop-opacity="0"/></radialGradient></defs><rect width="1200" height="630" fill="#0b0b0b"/><rect width="1200" height="630" fill="url(#ga)"/><rect width="1200" height="630" fill="url(#gb)"/><rect x="64" y="60" width="52" height="52" rx="14" fill="#17171a" stroke="#ffffff" stroke-opacity="0.18" stroke-width="2"/><text x="78" y="99" fill="#ffffff" font-family="Arial,sans-serif" font-size="36" font-weight="bold">d</text><circle cx="104" cy="72" r="4" fill="#ff4d6d"/><text x="134" y="96" fill="#f3f3f5" font-family="Arial,sans-serif" font-size="30" font-weight="bold">designtaste.wtf</text><text x="64" y="308" fill="#f3f3f5" font-family="Arial,sans-serif" font-size="92" font-weight="bold" letter-spacing="-4">Curated website</text><text x="64" y="408" fill="#a1a1aa" font-family="Arial,sans-serif" font-size="92" font-weight="bold" letter-spacing="-4">design inspiration.</text><text x="66" y="546" fill="#71717a" font-family="Arial,sans-serif" font-size="24">Hover to scroll full pages · Save favorites · Submit any URL</text></svg>`,
  );
  await sharp(cover).jpeg({ quality: 90 }).toFile(join(out, "og.jpg"));
}
const paths = [
  "/",
  "/about/",
  "/submit/",
  "/mcp/",
  ...categories.map((c) => `/categories/${slug(c)}/`),
  ...sites.map((s) => `/sites/${s.id}/`),
];
await writeFile(
  join(out, "sitemap.xml"),
  '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' +
    paths.map((p) => `<url><loc>${ORIGIN + p}</loc></url>`).join("") +
    "</urlset>",
);
await writeFile(
  join(out, "robots.txt"),
  process.env.VERCEL_ENV === "preview"
    ? "User-agent: *\nDisallow: /\n"
    : `User-agent: *\nAllow: /\nSitemap: ${ORIGIN}/sitemap.xml\n`,
);
await writeFile(join(out, "catalog.json"), JSON.stringify(sites, null, 2));
await writeFile(
  join(out, "llms.txt"),
  `# DesignTaste\n\nAn independent, MIT open-source gallery of website design inspiration.\n\n- [Gallery](${ORIGIN}/): Browse ${sites.length} curated websites.\n- [Open MCP](${ORIGIN}/mcp/): Zero-auth remote MCP server at \`${ORIGIN}/api/mcp/\` (tools: search_sites, get_site, list_categories, get_saved_list, create_saved_list, submit_site).\n- [Catalog JSON](${ORIGIN}/catalog.json): Full machine-readable catalog with URLs, categories, tags, dates, credits, and editorial observations.\n- [Submit](${ORIGIN}/submit/): Submit any public HTTPS website URL for curation.\n- [About](${ORIGIN}/about/): Credits, privacy, and removal requests.\n\nScreenshots are historical captures, not live embeds. Designs and trademarks belong to their creators. Editorial observations are opinions, not objective quality measurements.\n`,
);
await writeFile(
  join(out, "release.json"),
  JSON.stringify({
    product: "gallery",
    sourceCommit:
      process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA || null,
    sites: sites.length,
  }),
);
console.log(
  `Built ${paths.length} static pages and ${sites.length} references.`,
);