Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
- run: npm run lint
- run: npm run typecheck
- run: npm run build
- run: npm run seo:check
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"pipeline:warm": "tsx pipeline/warm.ts",
"og": "tsx scripts/og.ts",
"pipeline:extras": "tsx pipeline/extras.ts",
"indexnow": "node scripts/indexnow.mjs"
"indexnow": "node scripts/indexnow.mjs",
"seo:check": "node scripts/seo-check.mjs"
},
"dependencies": {
"@fontsource-variable/inter": "^5.3.0",
Expand Down
41 changes: 41 additions & 0 deletions scripts/seo-check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Check the static export the way a crawler sees it: every sitemap URL has a page, that page is
// canonical to itself, is indexable, and has its own title. Run after `npm run build`.
import { existsSync, readFileSync } from "node:fs";

const ORIGIN = "https://vtaircrafts.in";
const xml = readFileSync("out/sitemap.xml", "utf8");
const urls = [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]);
const problems = [];
const titles = new Map();

for (const url of urls) {
if (!url.startsWith(ORIGIN)) {
problems.push(`${url}: not on ${ORIGIN}`);
continue;
}
const path = url.slice(ORIGIN.length) || "/";
const file = path === "/" ? "out/index.html" : [`out${path}.html`, `out${path}/index.html`].find(existsSync);
if (!file || !existsSync(file)) {
problems.push(`${path}: no page in out/`);
continue;
}
const html = readFileSync(file, "utf8");
const canonical = html.match(/<link rel="canonical" href="([^"]+)"/)?.[1];
if (canonical !== url && !(path === "/" && canonical === ORIGIN)) problems.push(`${path}: canonical is ${canonical ?? "missing"}`);
if (/<meta name="robots" content="[^"]*noindex/i.test(html)) problems.push(`${path}: noindex but listed in the sitemap`);
const title = html.match(/<title>([^<]*)<\/title>/)?.[1]?.trim();
if (!title) problems.push(`${path}: no title`);
else titles.set(title, [...(titles.get(title) ?? []), path]);
}

for (const [title, paths] of titles) if (paths.length > 1) problems.push(`title "${title}" on ${paths.join(", ")}`);

const robots = readFileSync("out/robots.txt", "utf8");
if (/^Disallow:\s*\/\s*$/im.test(robots)) problems.push("robots.txt disallows the whole site");

console.log(`checked ${urls.length} sitemap URLs`);
if (problems.length) {
console.error(problems.slice(0, 50).join("\n"));
console.error(`${problems.length} SEO problems`);
process.exit(1);
}
12 changes: 6 additions & 6 deletions src/app/aircraft/[reg]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from "next/link";
import { notFound } from "next/navigation";
import { getAircraft, getAircraftByReg, getArchive, getArchivedByReg, getEventsFor, getMeta, getOperator } from "@/lib/data";
import { ageOf } from "@/lib/registry";
import { answersFor, archivedAnswersFor, faqJsonLd } from "@/lib/answers";
import { answersFor, archivedAnswersFor, isThinArchive } from "@/lib/answers";
import { Container } from "@/components/ui/Container";
import { Photo, PhotoCredit } from "@/components/ui/Photo";
import { Placard } from "@/components/aircraft/Placard";
Expand Down Expand Up @@ -39,6 +39,7 @@ export async function generateMetadata({ params }: PageProps<"/aircraft/[reg]">)
description: ans.description,
alternates: { canonical },
openGraph: { title: ans.title, description: ans.description },
...(isThinArchive(h) ? { robots: { index: false, follow: true } } : {}),
};
}

Expand Down Expand Up @@ -71,16 +72,16 @@ export default async function AircraftPage({ params }: PageProps<"/aircraft/[reg
url: `https://vtaircrafts.in/aircraft/${a.reg}`,
description: ans.lede,
dateModified: getMeta().generatedAt,
// Not "Product": Google validates Product markup for offers, reviews or ratings and flags every page without them.
about: {
"@type": "Product",
"@type": "Thing",
additionalType: "https://www.wikidata.org/wiki/Q11436",
name: `${a.type.name} ${a.reg}`,
identifier: a.reg,
manufacturer: { "@type": "Organization", name: a.type.manufacturer },
...(a.history?.msn ? { serialNumber: a.history.msn } : {}),
description: `${a.type.name}${a.history?.msn ? `, MSN ${a.history.msn}` : ""}`,
...(a.image ? { image: a.image.src } : {}),
},
},
faqJsonLd(ans.answers),
]}
/>
<Container>
Expand Down Expand Up @@ -151,7 +152,6 @@ function ArchivedAircraftPage({ reg }: { reg: string }) {
description: ans.lede,
dateModified: getMeta().generatedAt,
},
faqJsonLd(ans.answers),
]}
/>
<Container>
Expand Down
3 changes: 2 additions & 1 deletion src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MetadataRoute } from "next";
import { getAircraft, getArchive, getMeta, getOperators, getPastOperators, getTraining } from "@/lib/data";
import { getOwnerPages, getRegister, getTypes } from "@/lib/registry";
import { isThinArchive } from "@/lib/answers";

export const dynamic = "force-static";

Expand All @@ -19,6 +20,6 @@ export default function sitemap(): MetadataRoute.Sitemap {
...(getTraining()?.ftos ?? []).map((f) => page(`/flying-schools/${f.id}`, 0.5)),
...getAircraft().map((a) => page(`/aircraft/${a.reg}`, 0.6)),
...getPastOperators().map((o) => page(`/operators/${o.id}`, 0.4)),
...getArchive().map((a) => page(`/aircraft/${a.reg}`, 0.3)),
...getArchive().filter((a) => !isThinArchive(a)).map((a) => page(`/aircraft/${a.reg}`, 0.3)),
];
}
28 changes: 15 additions & 13 deletions src/lib/answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function current(a: Aircraft) {
}

return {
title: `${a.reg}: ${named}, owner and operator`,
// The registration, type and operator, the format these pages ranked with through October.
// The 29 Oct "owner and operator" wording dropped the operator name from every title.
title: `${a.reg} · ${a.type.name} · ${a.operator} · VT Aircrafts`,
description: `${lede}${facts.length ? ` ${capitalise(facts.join(", "))}.` : ""}`,
lede,
answers,
Expand Down Expand Up @@ -136,11 +138,12 @@ function archived(h: ArchivedAircraft, sentence: string) {
: `${h.reg} is not on any scheduled or non-scheduled operator permit in DGCA's latest lists, as on ${asOn}.`,
});

const title = h.training
? `${h.reg}: ${h.type.name} trainer, ${h.training.fto.replace(/\.$/, "")}`
: operators.length
? `${h.reg}: ex-${operators.at(-1)} ${h.type.name}, owner and history`
: `${h.reg}: ${named}, ${owner ? "owner and history" : "history"}`;
const title = [
h.reg,
h.type.name,
h.training ? h.training.fto.replace(/\.$/, "") : operators.length ? `ex-${operators.at(-1)}` : h.status === "deregistered" ? "deregistered" : "Indian register",
"VT Aircrafts",
].join(" · ");
return {
title,
description: `${h.reg} ${sentence}${owner ? ` Last registered owner: ${owner}.` : ""}`,
Expand All @@ -164,11 +167,10 @@ export function archivedAnswersFor(h: ArchivedAircraft, summary: { sentence: str
return archived(h, summary.sentence);
}

/** schema.org FAQPage for a question list. */
export function faqJsonLd(answers: Answer[]): object {
return {
"@context": "https://schema.org",
"@type": "FAQPage",
mainEntity: answers.map((x) => ({ "@type": "Question", name: x.q, acceptedAnswer: { "@type": "Answer", text: x.a } })),
};
/**
* An archived registration with nothing beyond its DGCA register line: no owner, no operator history
* and no flying school. These pages stay reachable but are kept out of the index and the sitemap.
*/
export function isThinArchive(h: ArchivedAircraft): boolean {
return !h.training && h.stints.length === 0 && !ownerName(h.owner)?.name;
}
Loading