Skip to content

Commit 2f1cab6

Browse files
authored
Use title with jurisdiction for guide page titles (#706)
1 parent 65927ba commit 2f1cab6

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

web/src/constants/jurisdictions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const JURISDICTIONS = {
7373
>;
7474

7575
export type JurisdictionId = keyof typeof JURISDICTIONS;
76+
export type JurisdictionName = (typeof JURISDICTIONS)[JurisdictionId]["name"];
7677

7778
export const JURISDICTION_OPTIONS = Object.entries(JURISDICTIONS).map(
7879
([id, jurisdiction]) => ({

web/src/content.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { ANNOTATION_TYPES } from "./constants/annotations";
55
import { CATEGORIES } from "./constants/categories";
66
import { COLOR_KEYS } from "./constants/colors";
77
import type { FormConfig } from "./constants/forms";
8-
import { JURISDICTIONS } from "./constants/jurisdictions";
8+
import {
9+
JURISDICTIONS,
10+
type JurisdictionName,
11+
} from "./constants/jurisdictions";
912
import type { PDFDefinition } from "./constants/pdf";
1013
import { SERVICES } from "./constants/services";
1114

@@ -120,7 +123,7 @@ const jurisdictions = defineCollection({
120123
namesakeSupport: jurisdiction.namesakeSupport,
121124
})),
122125
schema: z.object({
123-
name: z.string(),
126+
name: z.string<JurisdictionName>(),
124127
territory: z.boolean(),
125128
namesakeSupport: z.enum(["full", "prioritized", "none"]),
126129
}),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from "vitest";
2+
import { formatTitleWithJurisdiction } from "../formatTitleWithJurisdiction";
3+
4+
describe("formatTitleWithJurisdiction", () => {
5+
it("renders the title correctly with the jurisdiction", () => {
6+
expect(formatTitleWithJurisdiction("Court Order", "Massachusetts")).toEqual(
7+
"Massachusetts Court Order",
8+
);
9+
});
10+
11+
it("renders the title correctly without the jurisdiction", () => {
12+
expect(formatTitleWithJurisdiction("Passport")).toEqual("Passport");
13+
});
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { JurisdictionName } from "#constants/jurisdictions.ts";
2+
3+
/**
4+
* Given a title and jurisdiction
5+
* return the full string to display in the page title.
6+
*
7+
* @example
8+
* formatPageTitle("Court Order", "Massachusetts")
9+
* // "Massachusetts Court Order"
10+
*/
11+
export function formatTitleWithJurisdiction(
12+
title: string,
13+
jurisdiction?: JurisdictionName,
14+
) {
15+
return `${jurisdiction ? `${jurisdiction} ` : ""}${title}`;
16+
}

web/src/pages/guides/[...slug].astro

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import GuideFooter from "#components/GuideFooter.astro";
55
import StubBanner from "#components/StubBanner.astro";
66
import TableOfContents from "#components/TableOfContents.astro";
77
import ProseLayout from "#layouts/ProseLayout.astro";
8+
import { formatTitleWithJurisdiction } from "#lib/utils/formatTitleWithJurisdiction.ts";
89
910
export async function getStaticPaths() {
1011
const guides = await getCollection("guides", ({ data }) => !data.unlisted);
@@ -20,14 +21,14 @@ const jurisdiction = guide.data.jurisdiction
2021
? await getEntry(guide.data.jurisdiction)
2122
: null;
2223
23-
const searchTitle = jurisdiction
24-
? `${jurisdiction.data.name}: ${guide.data.title}`
25-
: guide.data.title;
24+
const title = formatTitleWithJurisdiction(
25+
guide.data.title,
26+
jurisdiction?.data.name,
27+
);
2628
---
2729

2830
<ProseLayout
29-
title={guide.data.title}
30-
searchTitle={searchTitle}
31+
title={title}
3132
description={guide.data.description}
3233
annotation="box"
3334
breadcrumbs={[

0 commit comments

Comments
 (0)