From 861f65fd2f502a13f5d27bc837e12b8bcba2bad4 Mon Sep 17 00:00:00 2001 From: David Ascanio Date: Sat, 1 Aug 2026 18:04:12 -0300 Subject: [PATCH] contador volutanrios --- src/components/BaseHead.astro | 2 + src/layouts/MainLayout.astro | 3 +- src/pages/[locale]/contador-voluntarios.astro | 206 ++++++++++++++++++ src/pages/api/lib/googleSheets.ts | 11 + src/pages/api/voluntarios/count.ts | 21 ++ 5 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/pages/[locale]/contador-voluntarios.astro create mode 100644 src/pages/api/voluntarios/count.ts diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 541a678..a1ff7be 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -8,6 +8,7 @@ const { image = null, url = null, date = null, + noindex = false, } = Astro.props; const imageUrl = image ? new URL(image, Astro.site).toString() : null; @@ -20,6 +21,7 @@ const canonicalURL = new URL(url || Astro.url.pathname, Astro.site); + {noindex && } {title} diff --git a/src/layouts/MainLayout.astro b/src/layouts/MainLayout.astro index 1edcab3..432452b 100644 --- a/src/layouts/MainLayout.astro +++ b/src/layouts/MainLayout.astro @@ -8,7 +8,7 @@ import "@fontsource/poppins/700.css"; import "@fontsource-variable/kameron"; import ShareSticky from "../components/ShareSticky.vue"; import { routeTranslations } from "../i18n"; -const { title, description, image, url, date } = Astro.props; +const { title, description, image, url, date, noindex } = Astro.props; const currentLocale = Astro.currentLocale ?? "es"; const direction = currentLocale === "he" ? "rtl" : "ltr"; @@ -28,6 +28,7 @@ const isNewsPage = contentSegments.some((segment) => image={image} url={url} date={date} + noindex={noindex} /> + diff --git a/src/pages/api/lib/googleSheets.ts b/src/pages/api/lib/googleSheets.ts index 972826a..dcf8271 100644 --- a/src/pages/api/lib/googleSheets.ts +++ b/src/pages/api/lib/googleSheets.ts @@ -37,6 +37,17 @@ export async function emailExists(email: string): Promise { } +export async function getVolunteerCount(): Promise { + const result = await sheets.spreadsheets.values.get({ + spreadsheetId: SPREADSHEET_ID, + range: 'VOLUNTARIOS!B2:B', // columna nombre_completo, se llena en cada registro + valueRenderOption: 'UNFORMATTED_VALUE', + }); + + const rows = result.data.values || []; + return rows.filter((row) => row[0] !== undefined && row[0] !== '').length; +} + export async function appendToSheet(values: any[]) { try { await sheets.spreadsheets.values.append({ diff --git a/src/pages/api/voluntarios/count.ts b/src/pages/api/voluntarios/count.ts new file mode 100644 index 0000000..4cc10b3 --- /dev/null +++ b/src/pages/api/voluntarios/count.ts @@ -0,0 +1,21 @@ +import type { APIRoute } from "astro"; +import { getVolunteerCount } from "../lib/googleSheets"; + +export const prerender = false; + +export const GET: APIRoute = async () => { + try { + const count = await getVolunteerCount(); + + return Response.json( + { success: true, count }, + { headers: { "Cache-Control": "no-store" } } + ); + } catch (error) { + console.error("Error en /api/voluntarios/count:", error); + return Response.json( + { success: false, message: "Error al obtener el contador de voluntarios" }, + { status: 500 } + ); + } +};