@domandigital/create-site 0.1.0 → 0.3.1
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 +34 -7
- package/LICENSE +202 -202
- package/README.md +104 -98
- package/dist/cli.js +61 -46
- package/package.json +3 -3
- package/templates/astro/components/DesignerCredit.astro +17 -17
- package/templates/astro/components/JsonLd.astro +14 -14
- package/templates/astro/pages/press.astro +86 -86
- package/templates/astro/pages/resources/index.astro +35 -35
- package/templates/astro/tests/seo/config.test.ts +18 -18
- package/templates/astro/tests/seo/routes-on-disk.ts +51 -51
- package/templates/next/app/press/page.tsx +96 -96
- package/templates/next/app/resources/page.tsx +32 -32
- package/templates/next/components/DesignerCredit.tsx +16 -16
- package/templates/next/components/JsonLd.tsx +11 -11
- package/templates/next/tests/seo/config.test.ts +15 -15
- package/templates/next/tests/seo/routes-on-disk.ts +55 -55
- package/templates/shared/lib/graph/page-graph.ts +37 -37
- package/templates/shared/lib/graph/site-adapter.ts +104 -104
- package/templates/shared/tests/house.test.ts +69 -69
- package/templates/shared/tests/seo/coverage.test.ts +20 -20
- package/templates/shared/tests/seo/graph.test.ts +16 -16
- package/templates/shared/tests/seo/redirects.test.ts +25 -25
|
@@ -1,16 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,11 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,15 +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
|
-
});
|
|
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
|
+
});
|
|
@@ -1,55 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,37 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,104 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
// House rules that run on every test run, plus a launch check.
|
|
2
|
-
// Written by @domandigital/create-site.
|
|
3
|
-
//
|
|
4
|
-
// pnpm seo:check always-on rules
|
|
5
|
-
// pnpm launch:check adds the "ready to launch" block below
|
|
6
|
-
|
|
7
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
8
|
-
import { join, relative } from "node:path";
|
|
9
|
-
import { describe, expect, test } from "vitest";
|
|
10
|
-
import { facts } from "~site/facts";
|
|
11
|
-
|
|
12
|
-
const ROOT = process.cwd();
|
|
13
|
-
const SOURCE_DIRS = ["app", "src", "components", "lib", "content"];
|
|
14
|
-
const SOURCE_FILE = /\.(tsx?|jsx?|astro|mdx?)$/;
|
|
15
|
-
|
|
16
|
-
function sourceFiles(): string[] {
|
|
17
|
-
const out: string[] = [];
|
|
18
|
-
const walk = (dir: string) => {
|
|
19
|
-
let entries;
|
|
20
|
-
try {
|
|
21
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
22
|
-
} catch {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
for (const entry of entries) {
|
|
26
|
-
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
27
|
-
const path = join(dir, entry.name);
|
|
28
|
-
if (entry.isDirectory()) walk(path);
|
|
29
|
-
else if (SOURCE_FILE.test(entry.name)) out.push(path);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
for (const dir of SOURCE_DIRS) walk(join(ROOT, dir));
|
|
33
|
-
return out;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// vitest sets MODE from --mode; typed loosely so this file needs no Vite types.
|
|
37
|
-
const mode = (import.meta as unknown as { env?: { MODE?: string } }).env?.MODE;
|
|
38
|
-
|
|
39
|
-
describe("the facts file is the single source of contact details", () => {
|
|
40
|
-
test("no page or component hard-codes the phone number, email or postcode from site.facts.ts", () => {
|
|
41
|
-
const values = [facts.phone, facts.email, facts.address?.postalCode].filter((v): v is string => Boolean(v));
|
|
42
|
-
const offenders = sourceFiles().flatMap((file) => {
|
|
43
|
-
const text = readFileSync(file, "utf8");
|
|
44
|
-
return values.filter((v) => text.includes(v)).map((v) => `${relative(ROOT, file)}: ${v}`);
|
|
45
|
-
});
|
|
46
|
-
expect(offenders).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe.runIf(mode === "launch")("ready to launch", () => {
|
|
51
|
-
test("the designer credit is placed on the site", () => {
|
|
52
|
-
const placed = sourceFiles().some((file) => !/DesignerCredit\.(tsx|astro)$/.test(file) && readFileSync(file, "utf8").includes("<DesignerCredit"));
|
|
53
|
-
expect(placed).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("phone and postcode are filled in", () => {
|
|
57
|
-
expect(facts.phone).not.toBeNull();
|
|
58
|
-
expect(facts.address?.postalCode ?? null).not.toBeNull();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("at least one profile is live", () => {
|
|
62
|
-
expect(facts.profiles.some((p) => p.status === "live")).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("every accreditation has a register link and a date someone checked it", () => {
|
|
66
|
-
const unchecked = facts.accreditations.filter((a) => !a.registerUrl || !a.verifiedOn).map((a) => a.name);
|
|
67
|
-
expect(unchecked).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
1
|
+
// House rules that run on every test run, plus a launch check.
|
|
2
|
+
// Written by @domandigital/create-site.
|
|
3
|
+
//
|
|
4
|
+
// pnpm seo:check always-on rules
|
|
5
|
+
// pnpm launch:check adds the "ready to launch" block below
|
|
6
|
+
|
|
7
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
8
|
+
import { join, relative } from "node:path";
|
|
9
|
+
import { describe, expect, test } from "vitest";
|
|
10
|
+
import { facts } from "~site/facts";
|
|
11
|
+
|
|
12
|
+
const ROOT = process.cwd();
|
|
13
|
+
const SOURCE_DIRS = ["app", "src", "components", "lib", "content"];
|
|
14
|
+
const SOURCE_FILE = /\.(tsx?|jsx?|astro|mdx?)$/;
|
|
15
|
+
|
|
16
|
+
function sourceFiles(): string[] {
|
|
17
|
+
const out: string[] = [];
|
|
18
|
+
const walk = (dir: string) => {
|
|
19
|
+
let entries;
|
|
20
|
+
try {
|
|
21
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
27
|
+
const path = join(dir, entry.name);
|
|
28
|
+
if (entry.isDirectory()) walk(path);
|
|
29
|
+
else if (SOURCE_FILE.test(entry.name)) out.push(path);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
for (const dir of SOURCE_DIRS) walk(join(ROOT, dir));
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// vitest sets MODE from --mode; typed loosely so this file needs no Vite types.
|
|
37
|
+
const mode = (import.meta as unknown as { env?: { MODE?: string } }).env?.MODE;
|
|
38
|
+
|
|
39
|
+
describe("the facts file is the single source of contact details", () => {
|
|
40
|
+
test("no page or component hard-codes the phone number, email or postcode from site.facts.ts", () => {
|
|
41
|
+
const values = [facts.phone, facts.email, facts.address?.postalCode].filter((v): v is string => Boolean(v));
|
|
42
|
+
const offenders = sourceFiles().flatMap((file) => {
|
|
43
|
+
const text = readFileSync(file, "utf8");
|
|
44
|
+
return values.filter((v) => text.includes(v)).map((v) => `${relative(ROOT, file)}: ${v}`);
|
|
45
|
+
});
|
|
46
|
+
expect(offenders).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe.runIf(mode === "launch")("ready to launch", () => {
|
|
51
|
+
test("the designer credit is placed on the site", () => {
|
|
52
|
+
const placed = sourceFiles().some((file) => !/DesignerCredit\.(tsx|astro)$/.test(file) && readFileSync(file, "utf8").includes("<DesignerCredit"));
|
|
53
|
+
expect(placed).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("phone and postcode are filled in", () => {
|
|
57
|
+
expect(facts.phone).not.toBeNull();
|
|
58
|
+
expect(facts.address?.postalCode ?? null).not.toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("at least one profile is live", () => {
|
|
62
|
+
expect(facts.profiles.some((p) => p.status === "live")).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("every accreditation has a register link and a date someone checked it", () => {
|
|
66
|
+
const unchecked = facts.accreditations.filter((a) => !a.registerUrl || !a.verifiedOn).map((a) => a.name);
|
|
67
|
+
expect(unchecked).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
});
|