Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Site: each page's card names its own page, and robots.txt and a sitemap are served

Lucas Marques8b1a0d742757
diff --git a/apps/site/app/docs/page.tsx b/apps/site/app/docs/page.tsx
index d7e1f98..048430a 100644
--- a/apps/site/app/docs/page.tsx
+++ b/apps/site/app/docs/page.tsx
@@ -5,6 +5,7 @@ import { Rail, type RailGroup } from "@/components/rail";
import { SECTIONS, type Group } from "@/lib/docs";
import { LINKS } from "@/lib/figures";
import { highlight } from "@/lib/highlight";
+import { share } from "@/lib/share";
import { tiny } from "@/lib/size";
import { CDN, CSS, QUICKSTART, REACT, REACT_SIGNATURE, VANILLA, VANILLA_SIGNATURE, install } from "@/lib/snippets";
import { Api, GettingStarted, Reference } from "./sections";
@@ -14,7 +15,7 @@ const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
/** A block's place in the header's entrance. */
const at = (i: number) => ({ "--i": i }) as CSSProperties;
-export const metadata: Metadata = { title: "Docs · hairline", alternates: { canonical: "/docs" } };
+export const metadata: Metadata = share("/docs", "Docs");
/** Each group of the rail under its own mark and colour. */
const MARK: Record<Group, Pick<RailGroup, "icon" | "color">> = {
diff --git a/apps/site/app/inspo/page.tsx b/apps/site/app/inspo/page.tsx
index d9323e8..f416341 100644
--- a/apps/site/app/inspo/page.tsx
+++ b/apps/site/app/inspo/page.tsx
@@ -3,6 +3,7 @@ import Image, { type StaticImageData } from "next/image";
import type { CSSProperties, ReactNode } from "react";
import { Footer, Topbar } from "@/components/chrome";
import { Rail } from "@/components/rail";
+import { share } from "@/lib/share";
import craft from "@/public/inspo/craft.webp";
import dissection from "@/public/inspo/dissection.webp";
import figures from "@/public/inspo/figures.webp";
@@ -12,12 +13,7 @@ import tune from "@/public/inspo/tune.webp";
const TITLE = "How Hairline was made";
const DESCRIPTION = "A long brief, a lot of arguing, and every correction written down as a rule: how Hairline was designed with Claude Opus and a live Artifact.";
-export const metadata: Metadata = {
- title: `${TITLE} · hairline`,
- description: DESCRIPTION,
- alternates: { canonical: "/inspo" },
- openGraph: { title: TITLE, description: DESCRIPTION, url: "/inspo", siteName: "hairline", type: "article", images: [{ url: "/og.png", width: 1200, height: 630, alt: "Line drawings that answer the pointer: the Terrain figure, its pillars rising." }] },
-};
+export const metadata: Metadata = share("/inspo", TITLE, DESCRIPTION, "article");
/** The story's parts, in order: the rail lists them and each step takes its title from here. */
const STEPS = ["A feeling, not a look", "The brief", "What came back", "Pushback", "The design pass", "Into a package", "What I’d keep"];
diff --git a/apps/site/app/layout.tsx b/apps/site/app/layout.tsx
index 27645d6..a453fa7 100644
--- a/apps/site/app/layout.tsx
+++ b/apps/site/app/layout.tsx
@@ -4,23 +4,15 @@ import { GeistMono } from "geist/font/mono";
import { GeistSans } from "geist/font/sans";
import { Instrument_Serif } from "next/font/google";
import { Analytics } from "@vercel/analytics/next";
+import { share } from "@/lib/share";
import "./globals.css";
/** The headline's one serif word. */
const serif = Instrument_Serif({ weight: "400", style: ["normal", "italic"], subsets: ["latin"], variable: "--font-instrument-serif" });
const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
-const DESCRIPTION = "Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.";
-export const metadata: Metadata = {
- metadataBase: new URL(SITE),
- title: "hairline",
- description: DESCRIPTION,
- alternates: { canonical: "/" },
- openGraph: { title: "hairline", description: DESCRIPTION, url: "/", siteName: "hairline", type: "website", images: [{ url: "/og.png", width: 1200, height: 630, alt: "Line drawings that answer the pointer: the Exploded figure, its layers lifted apart, with the install commands." }] },
- twitter: { card: "summary_large_image", title: "hairline", description: DESCRIPTION, images: ["/og.png"], creator: "@lucasmarkes" },
- icons: { icon: "/icon.svg" },
-};
+export const metadata: Metadata = { metadataBase: new URL(SITE), ...share("/"), icons: { icon: "/icon.svg" } };
export default function RootLayout({ children }: { children: ReactNode }) {
return (
diff --git a/apps/site/app/robots.ts b/apps/site/app/robots.ts
new file mode 100644
index 0000000..fec569b
--- /dev/null
+++ b/apps/site/app/robots.ts
@@ -0,0 +1,8 @@
+import type { MetadataRoute } from "next";
+
+const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
+
+/** Every crawler may read every page. /og stays open too: its own tag keeps it out of an index, and a crawler has to read the page to see it. */
+export default function robots(): MetadataRoute.Robots {
+ return { rules: { userAgent: "*", allow: "/" }, sitemap: `${SITE}/sitemap.xml` };
+}
diff --git a/apps/site/app/sitemap.ts b/apps/site/app/sitemap.ts
new file mode 100644
index 0000000..64d2a64
--- /dev/null
+++ b/apps/site/app/sitemap.ts
@@ -0,0 +1,9 @@
+import type { MetadataRoute } from "next";
+import { PAGES } from "@/lib/share";
+
+const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
+
+/** The pages a reader can land on, each at its canonical address. No dates: a build is not a change to a page. */
+export default function sitemap(): MetadataRoute.Sitemap {
+ return PAGES.map((path) => ({ url: path === "/" ? SITE : SITE + path }));
+}
diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsx
index ecf02c4..67d5fdd 100644
--- a/apps/site/app/skill/page.tsx
+++ b/apps/site/app/skill/page.tsx
@@ -6,6 +6,7 @@ import { Command } from "@/components/command";
import { ExampleFrame } from "@/components/example-frame";
import { Rail } from "@/components/rail";
import { LINKS } from "@/lib/figures";
+import { share } from "@/lib/share";
import { COMMAND, FOLDER, INSTALL, STEPS, SUMMARY, USE, examples } from "@/lib/skill";
/** The file the skill writes, set as code where a line names it. USE stays plain text for llms.txt. */
@@ -19,7 +20,7 @@ const named = (line: string) => {
/** A block's place in the header's entrance. */
const at = (i: number) => ({ "--i": i }) as CSSProperties;
-export const metadata: Metadata = { title: "Make your own figure · hairline", description: SUMMARY, alternates: { canonical: "/skill" } };
+export const metadata: Metadata = share("/skill", "Make your own figure", SUMMARY);
const RAIL = [
{
diff --git a/apps/site/lib/share.ts b/apps/site/lib/share.ts
new file mode 100644
index 0000000..966a2a2
--- /dev/null
+++ b/apps/site/lib/share.ts
@@ -0,0 +1,29 @@
+import type { Metadata } from "next";
+import { LINKS } from "./figures";
+
+/** What a page says of itself where it has nothing closer to say. */
+export const DESCRIPTION = "Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.";
+
+/** The pages a reader can land on, in the top bar's order: the sitemap lists these. /og is left out, a picture to photograph. */
+export const PAGES = ["/", "/docs", "/skill", "/inspo"] as const;
+
+const NAME = "hairline";
+
+/** The one picture every card shows: scripts/og.mjs photographs /og into public/og.png. */
+const PICTURE = { url: "/og.png", width: 1200, height: 630, alt: "Line drawings that answer the pointer: the Exploded figure, its layers lifted apart, with the install commands." };
+
+/**
+ * A page's metadata, with the card a pasted link shows: Open Graph's tags and
+ * X's. Next replaces `openGraph` and `twitter` whole instead of merging them,
+ * so a page that sets neither shows the home's title and address under its own
+ * link. Every page asks here, and each card names its own page.
+ */
+export function share(path: (typeof PAGES)[number], title = NAME, description = DESCRIPTION, type: "website" | "article" = "website"): Metadata {
+ return {
+ title: title === NAME ? NAME : `${title} · ${NAME}`,
+ description,
+ alternates: { canonical: path },
+ openGraph: { title, description, url: path, siteName: NAME, type, images: [PICTURE] },
+ twitter: { card: "summary_large_image", title, description, images: [PICTURE.url], creator: `@${LINKS.x.split("/").pop()}` },
+ };
+}
diff --git a/apps/site/test/share.test.ts b/apps/site/test/share.test.ts
new file mode 100644
index 0000000..64571d3
--- /dev/null
+++ b/apps/site/test/share.test.ts
@@ -0,0 +1,14 @@
+import { existsSync, readdirSync } from "node:fs";
+import { describe, expect, it } from "vitest";
+import { PAGES } from "@/lib/share";
+
+const APP = new URL("../app/", import.meta.url);
+
+describe("the sitemap's pages", () => {
+ it("are every page in app/ but the card's own, which is a picture to photograph and not a page to read", () => {
+ const routes = readdirSync(APP, { withFileTypes: true })
+ .filter((entry) => entry.isDirectory() && existsSync(new URL(`${entry.name}/page.tsx`, APP)))
+ .map((entry) => `/${entry.name}`);
+ expect([...PAGES].sort()).toEqual(["/", ...routes.filter((route) => route !== "/og")].sort());
+ });
+});
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index 8f86697..e59df8a 100644
--- a/apps/site/test/site.spec.ts
+++ b/apps/site/test/site.spec.ts
@@ -279,6 +279,39 @@ test("llms.txt and the registry item are served", async ({ request }) => {
expect(item.files[0].content).toContain('"use client"');
});
+// the build's base URL, which is localhost:3000 off Vercel
+const BASE = "http://localhost:3000";
+
+test("a pasted link shows the page it leads to: each page's card has its own title, text and address", async ({ request }) => {
+ const CARDS = [
+ ["/", "hairline", /^Six isometric line figures/],
+ ["/docs", "Docs", /^Six isometric line figures/],
+ ["/skill", "Make your own figure", /^hairline-create is a skill/],
+ ["/inspo", "How Hairline was made", /^A long brief/],
+ ] as const;
+ for (const [path, title, text] of CARDS) {
+ const html = await (await request.get(path)).text();
+ const tag = (key: string) => html.match(new RegExp(`<meta (?:property|name)="${key}" content="([^"]*)"`))?.[1];
+ // Open Graph's tags and X's say the same thing
+ for (const key of ["og:title", "twitter:title"]) expect(tag(key), `${path} ${key}`).toBe(title);
+ for (const key of ["og:description", "twitter:description"]) expect(tag(key), `${path} ${key}`).toMatch(text);
+ for (const key of ["og:image", "twitter:image"]) expect(tag(key), `${path} ${key}`).toBe(`${BASE}/og.png`);
+ expect(tag("og:url"), path).toBe(path === "/" ? BASE : BASE + path);
+ expect(tag("twitter:card"), path).toBe("summary_large_image");
+ // the account the footer links
+ expect(tag("twitter:creator"), path).toBe("@lucasmarkes__");
+ }
+});
+
+test("robots.txt lets every crawler in and names the sitemap, which lists the four pages", async ({ request }) => {
+ const robots = await (await request.get("/robots.txt")).text();
+ expect(robots).toMatch(/^User-Agent: \*\nAllow: \/\n/);
+ expect(robots).toContain(`Sitemap: ${BASE}/sitemap.xml`);
+
+ const sitemap = await (await request.get("/sitemap.xml")).text();
+ expect([...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])).toEqual([BASE, `${BASE}/docs`, `${BASE}/skill`, `${BASE}/inspo`]);
+});
+
test("the page fits a phone, with the longest install command, its buttons and the reel's ticks", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 800 });
await page.goto("/");