feat: read opening hours from Google Business Profile

Places API script normalizes regular and special hours; build uses a
snapshot, an orari sidecar refreshes /dati/orari.json every 6 hours for
the open-now sign. Adds the company legal name. Key stays in .env.server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 16:13:35 +01:00
co-authored by Claude Opus 5.5
parent 29d8700081
commit a651519dbe
15 changed files with 378 additions and 46 deletions
+19
View File
@@ -0,0 +1,19 @@
# ADR 0005: Opening hours from the Google Business Profile via Places API
## Status
Accepted (2026-11-04)
## Context
Opening hours were hard-coded in the site. The client keeps them up to date on the Google Business Profile listing "Officine Zuliani E. di Peresani A. Tosoni B. & C. S.A.S.", including special closures (holidays, vacations). Having one source avoids mismatches between site and Google (also a local-SEO signal).
## Decision
- Read hours with **Places API (New)** Place Details (`regularOpeningHours`, `currentOpeningHours`, `businessStatus`) using an API key restricted to Places API. The Business Profile API was rejected: owner OAuth and Google approval are overkill for reading hours.
- `scripts/orari-google.mjs` normalizes the response to the site format: `settimana` (days grouped by identical time ranges) and `prossimiGiorni` (actual ranges for the next 7 days, special closures included). On any error it leaves the existing file untouched.
- **Build time:** `deploy.sh` runs the script and writes `src/data/orari-google.json` (committed snapshot). The build uses it for the hours text, the table on /dove-siamo and the `openingHoursSpecification` JSON-LD. If it is missing, `src/data/orari.ts` falls back to hard-coded hours.
- **Runtime:** a second container `officinezuliani-orari` (`node:22-alpine`, no custom image) runs the same script every 6 hours and writes `orari.json` to a shared volume served by nginx at `/dati/orari.json`. The "open now" sign fetches it in the browser and redraws bars and status; if the fetch fails, the build-time hours stay.
- The key is never in the repository or in the browser: local `.env.server` (git-ignored) → copied by `deploy.sh` to the server as `.env` (mode 600).
## Consequences
- The client edits hours only on Google; the sign follows within 6 hours, without a deploy. The /dove-siamo table and JSON-LD update at the next deploy.
- About 120 Place Details requests per month: expected to stay within Google Maps Platform free monthly usage, but a billing account is required — check the current price list.
- If Google returns no regular hours, nothing is overwritten (no blank sign).
+4 -2
View File
@@ -4,7 +4,9 @@
- `src/pages/` → site pages: `index`, `officina`, `servizi`, `dove-siamo`, `contatti`, plus `sitemap.xml`
- `src/layouts/Base.astro` → HTML shell, meta/OG, canonical, AutoRepair JSON-LD, header/footer, reveal script
- `src/components/` → `Insegna` (open-now sign + weekly hours), `ServiziLista`, `Marchi`, `Faq` (+ FAQPage JSON-LD), `BloccoContatti`, `StripFoto` (3-photo strip)
- `src/data/officina.ts` → single source of business data (NAP, hours, services, FAQ)
- `src/data/officina.ts` → single source of business data (NAP, legal name, services, FAQ)
- `src/data/orari.ts` → opening hours: Google snapshot `orari-google.json` or fallback (ADR 0005)
- `scripts/orari-google.mjs` → reads hours from Places API (deploy + `orari` container on the server)
- `src/styles/global.css` → design tokens and shared styles (ADR 0002)
- `public/` → favicon, robots.txt, partner logos
- `src/assets/home/`, `src/assets/officina/` → page photos (demonstrative, AI-generated; optimized by astro:assets via `StripFoto`)
@@ -16,4 +18,4 @@
- `.claude/launch.json` → preview configs: `sito` (Astro dev, 4321), `proposte` (4173)
## Important flows
- Opening hours: defined once in `src/data/officina.ts` → rendered as bars (Insegna), table (dove-siamo), JSON-LD (Base)
- Opening hours: Google Business Profile → Places API → `orari-google.json` (build: text, table, JSON-LD) and `/dati/orari.json` (runtime: Insegna "open now", special closures)
+29
View File
@@ -0,0 +1,29 @@
# Handoff
## Issue
None (explicit user instruction: read opening hours from the Google Business Profile via Places API)
## Goal
Make Google Business Profile the single source of opening hours.
## Status
in-progress — code done; waiting for the API key in `.env.server` to look up the Place ID, take the first snapshot and deploy
## What changed
- `scripts/orari-google.mjs` (Places API → site format; `--cerca` to find the Place ID)
- `src/data/orari.ts` (snapshot or fallback, `orariTesto` generated), `officina.ts` uses it; legal name added (footer + `legalName`)
- Insegna reads `/dati/orari.json` at runtime, handles special closures, redraws bars
- `docker-compose.yml`: `orari` service + shared volume; nginx `/dati/` no-cache; `deploy.sh` snapshot + `.env.server` transfer
- ADR 0005, runbook, module map, CLAUDE.md
## Tests
- Run: script with a stubbed Places response (regular hours + holiday + half day) → correct `settimana` / `prossimiGiorni`
- Run: Insegna with a test `/dati/orari.json` (today closed) → "Chiuso ora · Riapriamo venerdì alle 8:00"; without file → build hours
- Not run: real Places API call (no key yet), server container
## Risks / open questions
- Billing account required on Google Cloud; check free usage on the current price list
- Restrict the key to Places API (New) only
## Suggested next step
- Fill `.env.server`, run `--cerca`, set `GOOGLE_PLACE_ID`, `./deploy.sh`, commit the snapshot
+8 -2
View File
@@ -8,7 +8,12 @@ Hosting: Docker on the a75 server, same flow as cam85 (`docs/adr/0004-hosting-do
```
It builds locally, builds the amd64 image, loads it on `217.76.62.220`, runs `docker compose up -d` in `/home/ubuntu/officinezuliani` and checks `http://officinezuliani-site:3000/` from the Nginx Proxy Manager container.
Requirements: SSH key access as `root@217.76.62.220`, Docker with buildx, Node/npm.
Requirements: SSH key access as `root@217.76.62.220`, Docker with buildx, Node/npm, and a local `.env.server` (copy `.env.server.example`) with `GOOGLE_PLACES_API_KEY` and `GOOGLE_PLACE_ID`.
## Opening hours from Google (ADR 0005)
- Find the Place ID once: `set -a; source .env.server; set +a; node scripts/orari-google.mjs --cerca "Officine Zuliani Udine"`
- Each deploy refreshes `src/data/orari-google.json` (commit it with the deploy)
- On the server, container `officinezuliani-orari` refreshes `/dati/orari.json` every 6 hours: `docker compose logs orari` shows the last updates
## Publish a hostname (one-time, Nginx Proxy Manager UI)
1. DNS: A record of the hostname → `217.76.62.220`
@@ -25,7 +30,8 @@ docker run --rm -p 8089:3000 officinezuliani-web:latest # http://localhost:808
Check out the previous good commit and run `./deploy.sh` again.
## Server layout
- `/home/ubuntu/officinezuliani/docker-compose.yml` (copied by deploy.sh)
- `/home/ubuntu/officinezuliani/docker-compose.yml`, `scripts/`, `.env` (from `.env.server`, mode 600) — all copied by deploy.sh
- Volume `orari-dati` shared by `orari` (writes) and `web` (`/dati/`, read-only)
- Container `officinezuliani-site` on network `a75`, port 3000, no host ports
## Hostnames