Skip to content

Commit e3b4877

Browse files
authored
Merge pull request #208 from Lemoncode/feature/play-ground-seo
Feature/play ground seo
2 parents 1479b1e + e0e14d2 commit e3b4877

7 files changed

Lines changed: 59 additions & 7 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/app/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import type { Metadata } from "next";
12
import { EmbalseSearch } from "@/pods/embalse-search";
23
import { getEmbalsesCollection } from "@/pods/embalse-search/api";
34

4-
export const dynamic = "force-dynamic";
5+
export const revalidate = 300;
6+
7+
export const metadata: Metadata = {
8+
title: { absolute: "Estado de los embalses de España — InfoEmbalse" },
9+
};
510

611
const RootPage = async () => {
712
const embalses = await getEmbalsesCollection();

front/src/pods/embalse-search/embalse-search.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export const EmbalseSearch: React.FC<Props> = (props) => {
6565
aria-labelledby="search-title"
6666
>
6767
<div className="text-center">
68-
<h2 id="search-title" className="font-bold">
69-
Embalses
70-
</h2>
68+
<h1 id="search-title" className="font-bold">
69+
Estado de los embalses de España
70+
</h1>
7171
</div>
7272
<div>
7373
<p className="text-sm">

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)