Skip to content

Commit e0e14d2

Browse files
brauliodiezCopilot
andcommitted
update friendly embalse and title
Co-authored-by: Copilot <copilot@github.com>
1 parent f7350c5 commit e0e14d2

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

front/src/app/embalse/[embalse]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
mapEmbalseToReservoirData,
1313
mapHistoricalReservoirToViewModel,
1414
} from "@/pods/embalse/embalse.mapper";
15+
import { formatEmbalseDisplayName } from "@/pods/embalse/embalse-name.helper";
1516

1617
export const revalidate = 300; // ISR: regenerar cada 5 minutos
1718

@@ -20,7 +21,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
2021
const embalseSlug = await getEmbalseBySlugCached(embalse);
2122

2223
return {
23-
title: embalseSlug.nombre,
24+
title: `Embalse de ${formatEmbalseDisplayName(embalseSlug.nombre)}`,
2425
alternates: { canonical: `/embalse/${embalse}` },
2526
};
2627
}

front/src/pods/embalse/components/reservoir-card-gauge.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { GaugeChart } from "./reservoir-gauge";
99
import { GaugeLegend } from "./reservoir-gauge/gauge-chart/components/gauge-legend.component";
1010
import { HistoryChart } from "./chart";
1111
import { useIsMobile } from "./useIsMobile";
12+
import { formatEmbalseDisplayName } from "../embalse-name.helper";
1213
interface Props {
1314
name: string;
1415
reservoirData: ReservoirData;
@@ -38,7 +39,7 @@ export const ReservoirCardGauge: React.FC<Props> = (props) => {
3839
aria-labelledby="gauge-title"
3940
>
4041
<h2 id="gauge-title" className="text-center">
41-
{name}
42+
{formatEmbalseDisplayName(name)}
4243
</h2>
4344
{isMobile && (
4445
<div className="join">
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, it, expect } from "vitest";
2+
import { formatEmbalseDisplayName } from "./embalse-name.helper";
3+
4+
describe("formatEmbalseDisplayName", () => {
5+
it("flips comma-inverted El", () => {
6+
expect(formatEmbalseDisplayName("Atazar, El")).toBe("El Atazar");
7+
expect(formatEmbalseDisplayName("Pardo, El")).toBe("El Pardo");
8+
expect(formatEmbalseDisplayName("Villar, El")).toBe("El Villar");
9+
});
10+
11+
it("flips comma-inverted La", () => {
12+
expect(formatEmbalseDisplayName("Jarosa, La")).toBe("La Jarosa");
13+
});
14+
15+
it("handles compound suffix with hyphen and parens", () => {
16+
expect(formatEmbalseDisplayName("Vellón,El-(Pedrezuela)")).toBe(
17+
"El Vellón (Pedrezuela)",
18+
);
19+
});
20+
21+
it("leaves untouched names without inverted article", () => {
22+
expect(formatEmbalseDisplayName("Navacerrada")).toBe("Navacerrada");
23+
expect(formatEmbalseDisplayName("Entrepeñas")).toBe("Entrepeñas");
24+
expect(formatEmbalseDisplayName("Cáceres - Guadiloba")).toBe(
25+
"Cáceres - Guadiloba",
26+
);
27+
expect(formatEmbalseDisplayName("Gabriel y Galán")).toBe("Gabriel y Galán");
28+
});
29+
30+
it("returns empty string for empty input", () => {
31+
expect(formatEmbalseDisplayName("")).toBe("");
32+
});
33+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const INVERTED_ARTICLE_PATTERN = /^(.+?),\s*(El|La|Los|Las)\b\s*(.*)$/;
2+
3+
export const formatEmbalseDisplayName = (rawName: string): string => {
4+
if (!rawName) return "";
5+
const match = rawName.match(INVERTED_ARTICLE_PATTERN);
6+
if (!match) return rawName.trim();
7+
8+
const [, baseName, article, rest] = match;
9+
const cleanedRest = rest.replace(/^[-\s]+/, "").trim();
10+
const tail = cleanedRest ? ` ${cleanedRest}` : "";
11+
return `${article} ${baseName.trim()}${tail}`.replace(/\s+/g, " ").trim();
12+
};

front/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)