@domandigital/create-site 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +202 -0
- package/README.md +98 -0
- package/dist/cli.js +1094 -0
- package/package.json +57 -0
- package/templates/astro/components/DesignerCredit.astro +17 -0
- package/templates/astro/components/JsonLd.astro +14 -0
- package/templates/astro/pages/press.astro +86 -0
- package/templates/astro/pages/resources/index.astro +35 -0
- package/templates/astro/tests/seo/config.test.ts +18 -0
- package/templates/astro/tests/seo/routes-on-disk.ts +51 -0
- package/templates/next/app/press/page.tsx +96 -0
- package/templates/next/app/resources/page.tsx +32 -0
- package/templates/next/components/DesignerCredit.tsx +16 -0
- package/templates/next/components/JsonLd.tsx +11 -0
- package/templates/next/tests/seo/config.test.ts +15 -0
- package/templates/next/tests/seo/routes-on-disk.ts +55 -0
- package/templates/shared/lib/graph/page-graph.ts +37 -0
- package/templates/shared/lib/graph/site-adapter.ts +104 -0
- package/templates/shared/tests/house.test.ts +69 -0
- package/templates/shared/tests/seo/coverage.test.ts +20 -0
- package/templates/shared/tests/seo/graph.test.ts +16 -0
- package/templates/shared/tests/seo/redirects.test.ts +25 -0
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@domandigital/create-site",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "The first thing that runs on a new Doman Digital client site: installs the house packages and writes the per-site files they read (the facts file, route policy, backlink register, redirects, JSON-LD, the designer credit, house docs and the SEO checks), so every build starts on the same foundation and stays upgradeable by bumping packages.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Doman Digital",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"bin": {
|
|
10
|
+
"create-site": "dist/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist",
|
|
20
|
+
"templates"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22.12"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Doman-Digital/dd-packages.git",
|
|
28
|
+
"directory": "packages/create-site"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"create",
|
|
32
|
+
"scaffold",
|
|
33
|
+
"nextjs",
|
|
34
|
+
"astro",
|
|
35
|
+
"seo",
|
|
36
|
+
"json-ld",
|
|
37
|
+
"local-business"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^20.17.0",
|
|
41
|
+
"tsup": "^8.3.5",
|
|
42
|
+
"typescript": "^5.6.3",
|
|
43
|
+
"vitest": "^2.1.9",
|
|
44
|
+
"@domandigital/craft": "^0.11.0",
|
|
45
|
+
"@domandigital/graph": "^0.7.0",
|
|
46
|
+
"@domandigital/seo": "^0.3.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"test": "vitest run"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The designer credit. Written by @domandigital/create-site.
|
|
3
|
+
//
|
|
4
|
+
// Brand name as the link text, the homepage as the target, rel="nofollow".
|
|
5
|
+
// Google's link spam policy lists "widely distributed links in the footers
|
|
6
|
+
// or templates of various sites", and a studio credit on every client site
|
|
7
|
+
// is that pattern. The credit is never a contract term and never tied to a
|
|
8
|
+
// discount. Doman Digital decision, 24 September 2026: do not change the
|
|
9
|
+
// text, the href or the rel.
|
|
10
|
+
interface Props {
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { class: className } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<a class={className} href="https://domandigital.co.uk/" rel="nofollow">Website by Doman Digital</a>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One JSON-LD script per page. Pass buildPageGraph({ path, name, description }).
|
|
3
|
+
// Written by @domandigital/create-site.
|
|
4
|
+
import { escapeJsonLdForScript } from "@domandigital/graph";
|
|
5
|
+
import type { JsonLdGraph } from "@domandigital/graph";
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
graph: JsonLdGraph;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { graph } = Astro.props;
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<script type="application/ld+json" is:inline set:html={escapeJsonLdForScript(JSON.stringify(graph))} />
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The press page: company facts, checked accreditations, press contact and
|
|
3
|
+
// earned coverage, all read from the site's data files. A section with no
|
|
4
|
+
// data is not rendered, so nothing is invented. A whole document, because a
|
|
5
|
+
// fresh Astro site may have no layout yet: move it into yours.
|
|
6
|
+
// Written by @domandigital/create-site.
|
|
7
|
+
import { isRouteIndexable } from "@domandigital/seo";
|
|
8
|
+
import type { BacklinkRegister } from "@domandigital/seo";
|
|
9
|
+
import JsonLd from "~site/components/JsonLd.astro";
|
|
10
|
+
import { facts } from "~site/facts";
|
|
11
|
+
import links from "~site/links.json";
|
|
12
|
+
import { buildPageGraph } from "~site/page-graph";
|
|
13
|
+
import { policy } from "~site/routes";
|
|
14
|
+
|
|
15
|
+
const title = `Press: ${facts.tradingName}`;
|
|
16
|
+
const indexable = isRouteIndexable(policy, "/press");
|
|
17
|
+
const accreditations = facts.accreditations.filter((a) => a.registerUrl && a.verifiedOn);
|
|
18
|
+
const coverage = (links as BacklinkRegister).links.filter((l) => l.kind === "press" && l.status === "live");
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
<html lang="en-GB">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="utf-8" />
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
25
|
+
<title>{title}</title>
|
|
26
|
+
<meta name="description" content={facts.description} />
|
|
27
|
+
{!indexable && <meta name="robots" content="noindex" />}
|
|
28
|
+
<JsonLd graph={buildPageGraph({ path: "/press", name: title, description: facts.description })} />
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<main>
|
|
32
|
+
<h1>Press</h1>
|
|
33
|
+
|
|
34
|
+
<section>
|
|
35
|
+
<h2>About {facts.tradingName}</h2>
|
|
36
|
+
<p>{facts.description}</p>
|
|
37
|
+
</section>
|
|
38
|
+
|
|
39
|
+
<section>
|
|
40
|
+
<h2>Company facts</h2>
|
|
41
|
+
<dl>
|
|
42
|
+
<dt>Registered name</dt>
|
|
43
|
+
<dd>{facts.legalName}</dd>
|
|
44
|
+
{facts.serviceAreas.length > 0 && (
|
|
45
|
+
<>
|
|
46
|
+
<dt>Areas served</dt>
|
|
47
|
+
<dd>{facts.serviceAreas.join(", ")}</dd>
|
|
48
|
+
</>
|
|
49
|
+
)}
|
|
50
|
+
<dt>Website</dt>
|
|
51
|
+
<dd>{facts.url}</dd>
|
|
52
|
+
</dl>
|
|
53
|
+
</section>
|
|
54
|
+
|
|
55
|
+
{accreditations.length > 0 && (
|
|
56
|
+
<section>
|
|
57
|
+
<h2>Accreditations</h2>
|
|
58
|
+
<ul>
|
|
59
|
+
{accreditations.map((a) => (
|
|
60
|
+
<li><a href={a.registerUrl}>{a.name}</a></li>
|
|
61
|
+
))}
|
|
62
|
+
</ul>
|
|
63
|
+
</section>
|
|
64
|
+
)}
|
|
65
|
+
|
|
66
|
+
{(facts.email || facts.phone) && (
|
|
67
|
+
<section>
|
|
68
|
+
<h2>Press contact</h2>
|
|
69
|
+
{facts.email && <p><a href={`mailto:${facts.email}`}>{facts.email}</a></p>}
|
|
70
|
+
{facts.phone && <p><a href={`tel:${facts.phone.replace(/\s+/g, "")}`}>{facts.phone}</a></p>}
|
|
71
|
+
</section>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
{coverage.length > 0 && (
|
|
75
|
+
<section>
|
|
76
|
+
<h2>Coverage</h2>
|
|
77
|
+
<ul>
|
|
78
|
+
{coverage.map((c) => (
|
|
79
|
+
<li><a href={c.url}>{c.source}</a></li>
|
|
80
|
+
))}
|
|
81
|
+
</ul>
|
|
82
|
+
</section>
|
|
83
|
+
)}
|
|
84
|
+
</main>
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The home for the site's linkable assets: a cost guide from the client's own
|
|
3
|
+
// job data, a calculator, or a practical guide. Kept out of the index until
|
|
4
|
+
// the first one ships: flip /resources to indexable in site.routes.ts then.
|
|
5
|
+
// Written by @domandigital/create-site.
|
|
6
|
+
import { isRouteIndexable } from "@domandigital/seo";
|
|
7
|
+
import { facts } from "~site/facts";
|
|
8
|
+
import { linkableAssets, policy } from "~site/routes";
|
|
9
|
+
|
|
10
|
+
const indexable = isRouteIndexable(policy, "/resources");
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<html lang="en-GB">
|
|
14
|
+
<head>
|
|
15
|
+
<meta charset="utf-8" />
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
17
|
+
<title>Resources: {facts.tradingName}</title>
|
|
18
|
+
{!indexable && <meta name="robots" content="noindex" />}
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<main>
|
|
22
|
+
<h1>Resources</h1>
|
|
23
|
+
{linkableAssets.length > 0 && (
|
|
24
|
+
<ul>
|
|
25
|
+
{linkableAssets.map((asset) => (
|
|
26
|
+
<li>
|
|
27
|
+
<a href={asset.path}>{asset.title}</a>
|
|
28
|
+
<p>{asset.summary}</p>
|
|
29
|
+
</li>
|
|
30
|
+
))}
|
|
31
|
+
</ul>
|
|
32
|
+
)}
|
|
33
|
+
</main>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// astro.config serves exactly the redirects in redirects.json. Written by
|
|
2
|
+
// @domandigital/create-site; fails until the config reads redirects.json.
|
|
3
|
+
//
|
|
4
|
+
// Static output turns these into meta-refresh pages, not real 301s. For a
|
|
5
|
+
// migration, deploy with a host adapter or add host-level redirects.
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import type { RedirectsFile } from "@domandigital/seo";
|
|
9
|
+
import config from "~site/framework-config";
|
|
10
|
+
import redirectsFile from "~site/redirects.json";
|
|
11
|
+
|
|
12
|
+
describe("astro.config redirects", () => {
|
|
13
|
+
test("serves every redirect in redirects.json, and nothing else", () => {
|
|
14
|
+
const served = Object.entries(config.redirects ?? {}).map(([from, r]) => [from, typeof r === "string" ? r : r.destination]);
|
|
15
|
+
const listed = (redirectsFile as RedirectsFile).redirects;
|
|
16
|
+
expect(served).toEqual(listed.map((r) => [r.from, r.to]));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The pages under src/pages, as the two lists validateCoverage takes. Written
|
|
2
|
+
// by @domandigital/create-site; the generator seeds site.routes.ts from the
|
|
3
|
+
// same file, so the two cannot disagree.
|
|
4
|
+
//
|
|
5
|
+
// routesOnDisk() concrete URL paths: "/", "/press"
|
|
6
|
+
// dynamicRoutesOnDisk() bracket paths: "/blog/[slug]", "/docs/[...slug]"
|
|
7
|
+
//
|
|
8
|
+
// Skipped: "_x" files and folders (Astro ignores them), endpoints (.ts/.js),
|
|
9
|
+
// and the 404 and 500 pages, which are never indexed.
|
|
10
|
+
|
|
11
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
|
|
14
|
+
const PAGE_FILE = /^(.+)\.(astro|md|mdx|html)$/;
|
|
15
|
+
const NOT_PAGES = new Set(["404", "500"]);
|
|
16
|
+
|
|
17
|
+
function walk(root: string): { routes: string[]; dynamicRoutes: string[] } {
|
|
18
|
+
const pagesDir = join(root, "src", "pages");
|
|
19
|
+
const routes = new Set<string>();
|
|
20
|
+
const dynamicRoutes = new Set<string>();
|
|
21
|
+
if (!existsSync(pagesDir)) return { routes: [], dynamicRoutes: [] };
|
|
22
|
+
|
|
23
|
+
const visit = (dir: string, segments: string[]) => {
|
|
24
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
25
|
+
const name = entry.name;
|
|
26
|
+
if (name.startsWith("_")) continue;
|
|
27
|
+
if (entry.isDirectory()) {
|
|
28
|
+
visit(join(dir, name), [...segments, name]);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const match = PAGE_FILE.exec(name);
|
|
32
|
+
if (!match) continue;
|
|
33
|
+
const base = match[1]!;
|
|
34
|
+
if (segments.length === 0 && NOT_PAGES.has(base)) continue;
|
|
35
|
+
const parts = base === "index" ? segments : [...segments, base];
|
|
36
|
+
const path = `/${parts.join("/")}`;
|
|
37
|
+
(parts.some((p) => p.startsWith("[")) ? dynamicRoutes : routes).add(path);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
visit(pagesDir, []);
|
|
42
|
+
return { routes: [...routes].sort(), dynamicRoutes: [...dynamicRoutes].sort() };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function routesOnDisk(root: string = process.cwd()): string[] {
|
|
46
|
+
return walk(root).routes;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function dynamicRoutesOnDisk(root: string = process.cwd()): string[] {
|
|
50
|
+
return walk(root).dynamicRoutes;
|
|
51
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The press page: company facts, checked accreditations, press contact and
|
|
2
|
+
// earned coverage, all read from the site's data files. A section with no
|
|
3
|
+
// data is not rendered, so nothing is invented. Written by
|
|
4
|
+
// @domandigital/create-site.
|
|
5
|
+
|
|
6
|
+
import type { Metadata } from "next";
|
|
7
|
+
import { isRouteIndexable } from "@domandigital/seo";
|
|
8
|
+
import type { BacklinkRegister } from "@domandigital/seo";
|
|
9
|
+
import { JsonLd } from "~site/components/JsonLd";
|
|
10
|
+
import { facts } from "~site/facts";
|
|
11
|
+
import links from "~site/links.json";
|
|
12
|
+
import { buildPageGraph } from "~site/page-graph";
|
|
13
|
+
import { policy } from "~site/routes";
|
|
14
|
+
|
|
15
|
+
const TITLE = `Press: ${facts.tradingName}`;
|
|
16
|
+
|
|
17
|
+
export const metadata: Metadata = {
|
|
18
|
+
title: TITLE,
|
|
19
|
+
description: facts.description,
|
|
20
|
+
robots: { index: isRouteIndexable(policy, "/press") },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const accreditations = facts.accreditations.filter((a) => a.registerUrl && a.verifiedOn);
|
|
24
|
+
const coverage = (links as BacklinkRegister).links.filter((l) => l.kind === "press" && l.status === "live");
|
|
25
|
+
|
|
26
|
+
export default function PressPage() {
|
|
27
|
+
return (
|
|
28
|
+
<main>
|
|
29
|
+
<JsonLd graph={buildPageGraph({ path: "/press", name: TITLE, description: facts.description })} />
|
|
30
|
+
<h1>Press</h1>
|
|
31
|
+
|
|
32
|
+
<section>
|
|
33
|
+
<h2>About {facts.tradingName}</h2>
|
|
34
|
+
<p>{facts.description}</p>
|
|
35
|
+
</section>
|
|
36
|
+
|
|
37
|
+
<section>
|
|
38
|
+
<h2>Company facts</h2>
|
|
39
|
+
<dl>
|
|
40
|
+
<dt>Registered name</dt>
|
|
41
|
+
<dd>{facts.legalName}</dd>
|
|
42
|
+
{facts.serviceAreas.length > 0 && (
|
|
43
|
+
<>
|
|
44
|
+
<dt>Areas served</dt>
|
|
45
|
+
<dd>{facts.serviceAreas.join(", ")}</dd>
|
|
46
|
+
</>
|
|
47
|
+
)}
|
|
48
|
+
<dt>Website</dt>
|
|
49
|
+
<dd>{facts.url}</dd>
|
|
50
|
+
</dl>
|
|
51
|
+
</section>
|
|
52
|
+
|
|
53
|
+
{accreditations.length > 0 && (
|
|
54
|
+
<section>
|
|
55
|
+
<h2>Accreditations</h2>
|
|
56
|
+
<ul>
|
|
57
|
+
{accreditations.map((a) => (
|
|
58
|
+
<li key={a.name}>
|
|
59
|
+
<a href={a.registerUrl ?? undefined}>{a.name}</a>
|
|
60
|
+
</li>
|
|
61
|
+
))}
|
|
62
|
+
</ul>
|
|
63
|
+
</section>
|
|
64
|
+
)}
|
|
65
|
+
|
|
66
|
+
{(facts.email || facts.phone) && (
|
|
67
|
+
<section>
|
|
68
|
+
<h2>Press contact</h2>
|
|
69
|
+
{facts.email && (
|
|
70
|
+
<p>
|
|
71
|
+
<a href={`mailto:${facts.email}`}>{facts.email}</a>
|
|
72
|
+
</p>
|
|
73
|
+
)}
|
|
74
|
+
{facts.phone && (
|
|
75
|
+
<p>
|
|
76
|
+
<a href={`tel:${facts.phone.replace(/\s+/g, "")}`}>{facts.phone}</a>
|
|
77
|
+
</p>
|
|
78
|
+
)}
|
|
79
|
+
</section>
|
|
80
|
+
)}
|
|
81
|
+
|
|
82
|
+
{coverage.length > 0 && (
|
|
83
|
+
<section>
|
|
84
|
+
<h2>Coverage</h2>
|
|
85
|
+
<ul>
|
|
86
|
+
{coverage.map((c) => (
|
|
87
|
+
<li key={c.url}>
|
|
88
|
+
<a href={c.url}>{c.source}</a>
|
|
89
|
+
</li>
|
|
90
|
+
))}
|
|
91
|
+
</ul>
|
|
92
|
+
</section>
|
|
93
|
+
)}
|
|
94
|
+
</main>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The home for the site's linkable assets: a cost guide from the client's own
|
|
2
|
+
// job data, a calculator, or a practical guide. Kept out of the index until
|
|
3
|
+
// the first one ships: flip /resources to indexable in site.routes.ts then.
|
|
4
|
+
// Written by @domandigital/create-site.
|
|
5
|
+
|
|
6
|
+
import type { Metadata } from "next";
|
|
7
|
+
import { isRouteIndexable } from "@domandigital/seo";
|
|
8
|
+
import { facts } from "~site/facts";
|
|
9
|
+
import { linkableAssets, policy } from "~site/routes";
|
|
10
|
+
|
|
11
|
+
export const metadata: Metadata = {
|
|
12
|
+
title: `Resources: ${facts.tradingName}`,
|
|
13
|
+
robots: { index: isRouteIndexable(policy, "/resources") },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default function ResourcesPage() {
|
|
17
|
+
return (
|
|
18
|
+
<main>
|
|
19
|
+
<h1>Resources</h1>
|
|
20
|
+
{linkableAssets.length > 0 && (
|
|
21
|
+
<ul>
|
|
22
|
+
{linkableAssets.map((asset) => (
|
|
23
|
+
<li key={asset.path}>
|
|
24
|
+
<a href={asset.path}>{asset.title}</a>
|
|
25
|
+
<p>{asset.summary}</p>
|
|
26
|
+
</li>
|
|
27
|
+
))}
|
|
28
|
+
</ul>
|
|
29
|
+
)}
|
|
30
|
+
</main>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The designer credit. Written by @domandigital/create-site.
|
|
2
|
+
//
|
|
3
|
+
// Brand name as the link text, the homepage as the target, rel="nofollow".
|
|
4
|
+
// Google's link spam policy lists "widely distributed links in the footers
|
|
5
|
+
// or templates of various sites", and a studio credit on every client site
|
|
6
|
+
// is that pattern. The credit is never a contract term and never tied to a
|
|
7
|
+
// discount. Doman Digital decision, 24 September 2026: do not change the
|
|
8
|
+
// text, the href or the rel.
|
|
9
|
+
|
|
10
|
+
export function DesignerCredit({ className }: { className?: string }) {
|
|
11
|
+
return (
|
|
12
|
+
<a className={className} href="https://domandigital.co.uk/" rel="nofollow">
|
|
13
|
+
Website by Doman Digital
|
|
14
|
+
</a>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// One JSON-LD script per page. Pass buildPageGraph({ path, name, description }).
|
|
2
|
+
// Written by @domandigital/create-site.
|
|
3
|
+
|
|
4
|
+
import { escapeJsonLdForScript } from "@domandigital/graph";
|
|
5
|
+
import type { JsonLdGraph } from "@domandigital/graph";
|
|
6
|
+
|
|
7
|
+
export function JsonLd({ graph }: { graph: JsonLdGraph }) {
|
|
8
|
+
return (
|
|
9
|
+
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: escapeJsonLdForScript(JSON.stringify(graph)) }} />
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// next.config serves exactly the redirects in redirects.json. Written by
|
|
2
|
+
// @domandigital/create-site; fails until the config reads redirects.json.
|
|
3
|
+
|
|
4
|
+
import { describe, expect, test } from "vitest";
|
|
5
|
+
import type { RedirectsFile } from "@domandigital/seo";
|
|
6
|
+
import nextConfig from "~site/framework-config";
|
|
7
|
+
import redirectsFile from "~site/redirects.json";
|
|
8
|
+
|
|
9
|
+
describe("next.config redirects", () => {
|
|
10
|
+
test("serves every redirect in redirects.json, and nothing else", async () => {
|
|
11
|
+
const served = (await nextConfig.redirects?.()) ?? [];
|
|
12
|
+
const listed = (redirectsFile as RedirectsFile).redirects;
|
|
13
|
+
expect(served.map((r) => [r.source, r.destination])).toEqual(listed.map((r) => [r.from, r.to]));
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The App Router's pages, as the two lists validateCoverage takes. Written by
|
|
2
|
+
// @domandigital/create-site; the generator seeds site.routes.ts from the same
|
|
3
|
+
// file, so the two cannot disagree.
|
|
4
|
+
//
|
|
5
|
+
// routesOnDisk() concrete URL paths: "/", "/press"
|
|
6
|
+
// dynamicRoutesOnDisk() bracket paths: "/blog/[slug]", "/docs/[[...slug]]"
|
|
7
|
+
//
|
|
8
|
+
// Route groups "(x)" add no URL segment and are dropped. Private folders
|
|
9
|
+
// "_x", parallel slots "@x" and intercepting routes "(.)x" have no URL of
|
|
10
|
+
// their own and are skipped. An optional catch-all also serves its parent,
|
|
11
|
+
// so "/docs/[[...slug]]" puts "/docs" in routesOnDisk too.
|
|
12
|
+
|
|
13
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
|
|
16
|
+
const PAGE_FILE = /^page\.(tsx|ts|jsx|js|mdx|md)$/;
|
|
17
|
+
const OPTIONAL_CATCH_ALL = /^\[\[\.\.\..+\]\]$/;
|
|
18
|
+
|
|
19
|
+
function walk(root: string): { routes: string[]; dynamicRoutes: string[] } {
|
|
20
|
+
const appDir = [join(root, "app"), join(root, "src", "app")].find((dir) => existsSync(dir));
|
|
21
|
+
const routes = new Set<string>();
|
|
22
|
+
const dynamicRoutes = new Set<string>();
|
|
23
|
+
if (!appDir) return { routes: [], dynamicRoutes: [] };
|
|
24
|
+
|
|
25
|
+
const visit = (dir: string, segments: string[]) => {
|
|
26
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
const name = entry.name;
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
if (name.startsWith("_") || name.startsWith("@") || name.startsWith("(.")) continue;
|
|
30
|
+
const isGroup = name.startsWith("(") && name.endsWith(")");
|
|
31
|
+
visit(join(dir, name), isGroup ? segments : [...segments, name]);
|
|
32
|
+
} else if (PAGE_FILE.test(name)) {
|
|
33
|
+
const path = `/${segments.join("/")}`;
|
|
34
|
+
const firstDynamic = segments.findIndex((s) => s.startsWith("["));
|
|
35
|
+
if (firstDynamic === -1) {
|
|
36
|
+
routes.add(path);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
dynamicRoutes.add(path);
|
|
40
|
+
if (OPTIONAL_CATCH_ALL.test(segments[firstDynamic]!)) routes.add(`/${segments.slice(0, firstDynamic).join("/")}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
visit(appDir, []);
|
|
46
|
+
return { routes: [...routes].sort(), dynamicRoutes: [...dynamicRoutes].sort() };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function routesOnDisk(root: string = process.cwd()): string[] {
|
|
50
|
+
return walk(root).routes;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function dynamicRoutesOnDisk(root: string = process.cwd()): string[] {
|
|
54
|
+
return walk(root).dynamicRoutes;
|
|
55
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// One JSON-LD graph per page: the organisation and website spine, the page
|
|
2
|
+
// itself, and its breadcrumb trail, all joined by @id references so search
|
|
3
|
+
// engines read one connected entity. Written by @domandigital/create-site.
|
|
4
|
+
//
|
|
5
|
+
// Use it through the JsonLd component, once per page:
|
|
6
|
+
// <JsonLd graph={buildPageGraph({ path: "/services/rewiring", name: "Rewiring" })} />
|
|
7
|
+
|
|
8
|
+
import { buildBreadcrumbs, buildGraph, buildSpine, buildWebPage, createGraphIds } from "@domandigital/graph";
|
|
9
|
+
import type { JsonLdGraph } from "@domandigital/graph";
|
|
10
|
+
import { getBreadcrumbTrail } from "@domandigital/seo";
|
|
11
|
+
import { facts } from "~site/facts";
|
|
12
|
+
import { trailLabels } from "~site/routes";
|
|
13
|
+
import { toOrganizationInput } from "~site/site-adapter";
|
|
14
|
+
|
|
15
|
+
export type PageGraphInput = { path: string; name: string; description?: string | null };
|
|
16
|
+
|
|
17
|
+
export function buildPageGraph(page: PageGraphInput): JsonLdGraph {
|
|
18
|
+
const origin = facts.url.replace(/\/$/, "");
|
|
19
|
+
const ids = createGraphIds(origin);
|
|
20
|
+
const [organization, website] = buildSpine(
|
|
21
|
+
toOrganizationInput(facts),
|
|
22
|
+
{ name: facts.tradingName, url: origin, inLanguage: "en-GB" },
|
|
23
|
+
ids,
|
|
24
|
+
facts.businessTypes,
|
|
25
|
+
);
|
|
26
|
+
const trail = getBreadcrumbTrail(trailLabels, page.path).map((t) => ({ name: t.label, url: `${origin}${t.path}` }));
|
|
27
|
+
|
|
28
|
+
return buildGraph([
|
|
29
|
+
organization,
|
|
30
|
+
website,
|
|
31
|
+
buildWebPage(
|
|
32
|
+
{ path: page.path, url: `${origin}${page.path}`, name: page.name, description: page.description, inLanguage: "en-GB" },
|
|
33
|
+
ids,
|
|
34
|
+
),
|
|
35
|
+
trail.length > 1 ? buildBreadcrumbs(trail, ids.breadcrumb(page.path)) : null,
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// The site's facts, shaped for @domandigital/graph. Written by
|
|
2
|
+
// @domandigital/create-site. graph owns JSON-LD emission; this adapter only
|
|
3
|
+
// maps site.facts.ts onto OrganizationInput, which is why it lives here and
|
|
4
|
+
// not in a package (graph PRINCIPLES.md, principle 6).
|
|
5
|
+
//
|
|
6
|
+
// Two rules are enforced in code rather than remembered:
|
|
7
|
+
// - sameAs lists only profiles marked "live". A profile still to claim is
|
|
8
|
+
// not evidence of anything.
|
|
9
|
+
// - An accreditation appears only once it has a register link and a date
|
|
10
|
+
// someone checked it. Unchecked claims do not reach search engines.
|
|
11
|
+
|
|
12
|
+
import type { OrganizationInput } from "@domandigital/graph";
|
|
13
|
+
|
|
14
|
+
export type Day = "Mo" | "Tu" | "We" | "Th" | "Fr" | "Sa" | "Su";
|
|
15
|
+
|
|
16
|
+
export type OpeningHours = { days: Day[]; opens: string; closes: string };
|
|
17
|
+
|
|
18
|
+
export type Accreditation = {
|
|
19
|
+
/** As the scheme names it, e.g. "NICEIC Approved Contractor". */
|
|
20
|
+
name: string;
|
|
21
|
+
/** The body, e.g. "NICEIC". */
|
|
22
|
+
scheme: string;
|
|
23
|
+
number: string | null;
|
|
24
|
+
/** The client's own entry on the public register. */
|
|
25
|
+
registerUrl: string | null;
|
|
26
|
+
/** ISO date a person last checked the entry. */
|
|
27
|
+
verifiedOn: string | null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ProfileKind =
|
|
31
|
+
| "google-business-profile"
|
|
32
|
+
| "bing-places"
|
|
33
|
+
| "apple-business-connect"
|
|
34
|
+
| "directory"
|
|
35
|
+
| "trade-register"
|
|
36
|
+
| "companies-house"
|
|
37
|
+
| "social";
|
|
38
|
+
|
|
39
|
+
export type Profile = {
|
|
40
|
+
kind: ProfileKind;
|
|
41
|
+
name: string;
|
|
42
|
+
url: string | null;
|
|
43
|
+
status: "to-claim" | "claimed" | "live";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type SiteFacts = {
|
|
47
|
+
/** The canonical origin, https, no trailing slash. */
|
|
48
|
+
url: string;
|
|
49
|
+
legalName: string;
|
|
50
|
+
tradingName: string;
|
|
51
|
+
/** One or two plain sentences: who, where, what. */
|
|
52
|
+
description: string;
|
|
53
|
+
/** schema.org types, most specific last, e.g. ["LocalBusiness", "Electrician"]. */
|
|
54
|
+
businessTypes: string[];
|
|
55
|
+
phone: string | null;
|
|
56
|
+
email: string | null;
|
|
57
|
+
address: {
|
|
58
|
+
streetAddress: string | null;
|
|
59
|
+
locality: string | null;
|
|
60
|
+
region: string | null;
|
|
61
|
+
postalCode: string | null;
|
|
62
|
+
country: "GB";
|
|
63
|
+
} | null;
|
|
64
|
+
geo: { latitude: number; longitude: number } | null;
|
|
65
|
+
openingHours: OpeningHours[];
|
|
66
|
+
serviceAreas: string[];
|
|
67
|
+
accreditations: Accreditation[];
|
|
68
|
+
profiles: Profile[];
|
|
69
|
+
/** Hostnames of previous sites that now redirect here, for the redirect check. */
|
|
70
|
+
previousHosts: string[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const DAY_NAMES: Record<Day, string> = {
|
|
74
|
+
Mo: "Monday",
|
|
75
|
+
Tu: "Tuesday",
|
|
76
|
+
We: "Wednesday",
|
|
77
|
+
Th: "Thursday",
|
|
78
|
+
Fr: "Friday",
|
|
79
|
+
Sa: "Saturday",
|
|
80
|
+
Su: "Sunday",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export function toOrganizationInput(facts: SiteFacts): OrganizationInput {
|
|
84
|
+
return {
|
|
85
|
+
name: facts.tradingName,
|
|
86
|
+
legalName: facts.legalName !== facts.tradingName ? facts.legalName : null,
|
|
87
|
+
description: facts.description,
|
|
88
|
+
url: facts.url,
|
|
89
|
+
phone: facts.phone,
|
|
90
|
+
email: facts.email,
|
|
91
|
+
address: facts.address,
|
|
92
|
+
geo: facts.geo ? { latitude: String(facts.geo.latitude), longitude: String(facts.geo.longitude) } : null,
|
|
93
|
+
openingHoursSpecification: facts.openingHours.map((h) => ({
|
|
94
|
+
dayOfWeek: h.days.map((d) => DAY_NAMES[d]),
|
|
95
|
+
opens: h.opens,
|
|
96
|
+
closes: h.closes,
|
|
97
|
+
})),
|
|
98
|
+
areaServed: facts.serviceAreas.length > 0 ? facts.serviceAreas : null,
|
|
99
|
+
sameAs: facts.profiles.filter((p) => p.status === "live" && p.url).map((p) => p.url as string),
|
|
100
|
+
identifiers: facts.accreditations
|
|
101
|
+
.filter((a) => a.registerUrl && a.verifiedOn)
|
|
102
|
+
.map((a) => ({ propertyID: a.scheme, name: a.name, value: a.number ?? a.name, url: a.registerUrl })),
|
|
103
|
+
};
|
|
104
|
+
}
|