Skip to content

Commit a49ddb0

Browse files
committed
Make img previews 9 wide not 6, and improve GHPages embedding static previews
1 parent e81efef commit a49ddb0

12 files changed

Lines changed: 50 additions & 24 deletions

File tree

website/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@
3838
var query = pathname.slice(q);
3939
return (pathOnly.endsWith("/") ? pathOnly : pathOnly + "/") + query;
4040
};
41+
var stripIndexHtml = function(pathname) {
42+
return pathname.replace(/\/index\.html\/?$/i, "/");
43+
};
4144

4245
if (configuredBase !== "/" && l.pathname === baseNoSlash) {
4346
l.replace(base + l.search + l.hash);
4447
return;
4548
}
4649
if (hasAppBase) {
47-
var collapsed = collapseTrailingSlashes(l.pathname);
48-
if (collapsed !== l.pathname) {
49-
l.replace(collapsed + l.search + l.hash);
50+
var canonicalPath = stripIndexHtml(collapseTrailingSlashes(l.pathname));
51+
if (canonicalPath !== l.pathname) {
52+
l.replace(canonicalPath + l.search + l.hash);
5053
return;
5154
}
5255
}

website/package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "vite build",
9-
"build:dev": "vite build --mode development",
8+
"build": "vite build && node scripts/generate-route-indexes.mjs",
9+
"build:dev": "vite build --mode development && node scripts/generate-route-indexes.mjs",
1010
"sync:map-colors": "node scripts/sync-map-colors.mjs",
1111
"preview": "vite preview"
1212
},
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import process from "node:process";
4+
5+
const cwd = process.cwd();
6+
const distDir = path.resolve(cwd, "dist");
7+
const srcToolPages = path.resolve(cwd, "src/lib/toolPages.ts");
8+
const indexPath = path.join(distDir, "index.html");
9+
10+
const html = await fs.readFile(indexPath, "utf8");
11+
const toolPagesSource = await fs.readFile(srcToolPages, "utf8");
12+
const routeMatches = [...toolPagesSource.matchAll(/path:\s*"([^"]+)"/g)];
13+
const routes = [...new Set(routeMatches.map(([, route]) => route).filter(route => route && route !== "/"))];
14+
if (!routes.length) throw new Error("No tool routes found while generating route index pages.");
15+
16+
for (const route of routes) {
17+
const rel = route.replace(/^\/+|\/+$/g, "");
18+
if (!rel) continue;
19+
const routeDir = path.join(distDir, rel);
20+
await fs.mkdir(routeDir, { recursive: true });
21+
await fs.writeFile(path.join(routeDir, "index.html"), html);
22+
}
23+
24+
console.log(`Generated ${routes.length} route index page(s).`);

website/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import DatToPng from "@/pages/DatToPng";
77
import NbtToPng from "@/pages/NbtToPng";
88
import CacheToPng from "@/pages/CacheToPng";
99
import MapHasher from "@/pages/MapHasher";
10-
import { TOOL_PAGES, type ToolPageId } from "@/lib/toolPages";
10+
import { TOOL_PAGES } from "@/lib/toolPages";
11+
12+
type ToolPageId = (typeof TOOL_PAGES)[number]["id"];
1113

1214
const routeElements: Record<ToolPageId, ReactElement> = {
1315
pngToDat: <PngToDat />,

website/src/components/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function Layout() {
1111
return (
1212
<div className="min-h-screen">
1313
<nav className="border-b border-border bg-background/80 backdrop-blur sticky top-0 z-10">
14-
<div className="mx-auto max-w-6xl flex items-center justify-between px-4 h-12">
14+
<div className="flex h-12 w-full items-center justify-between px-4">
1515
<div className="flex items-center gap-4 overflow-x-auto">
1616
<a href={import.meta.env.BASE_URL} className="shrink-0 hover:opacity-80 transition-opacity" title="EvMod Tools">
1717
<img src={siteIcon} alt="EvMod Tools" className="w-7 h-7" />
@@ -50,7 +50,7 @@ export default function Layout() {
5050
</button>
5151
</div>
5252
</nav>
53-
<main className="mx-auto max-w-6xl p-6">
53+
<main className="w-full p-6">
5454
<Outlet />
5555
</main>
5656
</div>

website/src/components/MapImageGallery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function MapImageGallery({ images, zipName, summaryLabel }: MapIm
2020
</button>
2121
)}
2222
</div>
23-
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-5 lg:grid-cols-6">
23+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-9">
2424
{images.map(img => (
2525
<button key={img.url} onClick={() => downloadUrl(img.url, img.name)} className="group overflow-hidden rounded-lg border border-border transition-colors hover:border-accent" title={`Download ${img.name}`}>
2626
<img src={img.url} alt={img.name} className="aspect-square w-full object-contain bg-muted" style={{ imageRendering: "pixelated" }} />

website/src/lib/javaDeserialize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import { dashedUuidFromLongs, parseDashedUuid, type DashedUuid } from "@/lib/uuid";
88
import type { LockedMapData, MapData } from "@/lib/map";
99

10-
export type MapStateData = LockedMapData;
10+
type MapStateData = LockedMapData;
1111

12-
export type CacheExtractResult =
12+
type CacheExtractResult =
1313
| { kind: "id"; maps: [id: number, map: MapStateData][] }
1414
| { kind: "name"; maps: [name: string, map: MapStateData][] }
1515
| { kind: "slot"; containers: [uuid: DashedUuid, maps: [slot: number, map: MapStateData][]][] };

website/src/lib/mapDat.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
import pako from "pako";
66
import type { LockedMapData, MapData } from "@/lib/map";
7-
export type DatFileData = LockedMapData;
87

98
const inflateIfNeeded = (buffer: ArrayBuffer): Uint8Array => {
109
let data: Uint8Array;
@@ -64,7 +63,7 @@ export function encodeMapDataToDat(mapData: MapData, locked = true): Blob {
6463
return new Blob([pako.gzip(new Uint8Array(out))], { type: "application/octet-stream" });
6564
}
6665

67-
export function parseMapDataFromDat(buffer: ArrayBuffer): DatFileData {
66+
export function parseMapDataFromDat(buffer: ArrayBuffer): LockedMapData {
6867
const data = inflateIfNeeded(buffer);
6968

7069
const reader = new NbtReader(data);

website/src/lib/mapPng.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function encodeMapDataToPng({ colors }: MapData): Blob {
8888
return new Blob([png], { type: "image/png" });
8989
}
9090

91-
export interface ParsedMap extends MapData {
91+
interface ParsedMap extends MapData {
9292
label?: string;
9393
}
9494

0 commit comments

Comments
 (0)