- testi: «lo Studio» uniforme, «Centro autorizzato CAF», ripetizioni tolte nei servizi e in «Lo studio», valori senza superlativi, meta corrette, testo della mappa di §10.2, numeri e indirizzi con spazi non separabili - visuale: breadcrumb, anello della banda CTA, card dei professionisti, pager e sidebar dei servizi su mobile, pagine legali a colonna singola, pulsante e-mail su una riga, card sedi allineate - dati: fatti della sede di Asti da studio.ts/testi.ts, sede.telefono - 404 e conferma senza canonical; avviso mappa senza JavaScript - controlli: CSP per direttive (endpoint), anno da SOURCE_DATE_EPOCH, URL del sito controllati sulla build locale, import file:// e tar da stdin per Windows, .gitattributes, porta libera corretta - modulo: pattern del telefono valido, avviso visibile, Esc sul sottomenu aperto al passaggio del mouse; contact.php con -f, senza mbstring obbligatorio, fuso Europe/Rome - release: note --shell-safe, ripiego REST automatico, RELEASE_TOKEN; deploy di esempio senza esclusione di contact.php; nginx /privacy/ - DECISIONS D-040–D-044, TODO C4 e riferimenti di riga aggiornati Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
/**
|
||
* Funzioni di formattazione condivise (indirizzi, orari, link telefonici e mappe).
|
||
*/
|
||
import type { Phone, PostalAddress } from '../data/studio';
|
||
import { studio } from '../data/studio';
|
||
|
||
const NBSP = '\u00a0';
|
||
|
||
/** «14048 Montegrosso d’Asti (AT)», con spazi non separabili: CAP, località e provincia non
|
||
* vanno mai a capo separatamente. */
|
||
export function cityLine(a: PostalAddress): string {
|
||
return [a.postalCode, ...a.locality.split(' '), `(${a.province})`].join(NBSP);
|
||
}
|
||
|
||
/** «Via XX Settembre, 163 — 14048 Montegrosso d’Asti (AT)» */
|
||
export function addressLine(a: PostalAddress): string {
|
||
return `${a.streetAddress} — ${cityLine(a)}`;
|
||
}
|
||
|
||
/**
|
||
* Spazio non separabile dopo le abbreviazioni seguite da un numero o da un riferimento
|
||
* («n. 1535», «sez. 1», «L. 4/2013», «D.Lgs. 81/2008»), così non restano a fine riga.
|
||
*/
|
||
export function nbspAbbreviations(text: string): string {
|
||
return text.replace(/(^|[\s(])(n\.|sez\.|L\.|D\.Lgs\.|D\.L\.|art\.|co\.) (?=\S)/g, `$1$2${NBSP}`);
|
||
}
|
||
|
||
export function telHref(phone: Phone): string {
|
||
return `tel:${phone.e164}`;
|
||
}
|
||
|
||
/** Numero da mostrare con spazi non separabili, così non va mai a capo. */
|
||
export function telText(phone: Phone | string): string {
|
||
return (typeof phone === 'string' ? phone : phone.display).replace(/ /g, '\u00a0');
|
||
}
|
||
|
||
export function mailtoHref(email: string, subject?: string): string {
|
||
return subject ? `mailto:${email}?subject=${encodeURIComponent(subject)}` : `mailto:${email}`;
|
||
}
|
||
|
||
/** Fasce orarie leggibili: «9:00 – 12:30 | 15:00 – 18:30». */
|
||
export function hoursLine(): string {
|
||
const short = (t: string) => t.replace(/^0/, '');
|
||
return studio.orari.fasce.map((f) => `${short(f.apertura)} – ${short(f.chiusura)}`).join(' | ');
|
||
}
|
||
|
||
/** Ricerca per indirizzo (le coordinate non sono verificate, brief §4.6). */
|
||
export function googleMapsUrl(query: string): string {
|
||
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`;
|
||
}
|
||
|
||
export function googleDirectionsUrl(query: string): string {
|
||
return `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(query)}`;
|
||
}
|
||
|
||
export function openStreetMapUrl(query: string): string {
|
||
return `https://www.openstreetmap.org/search?query=${encodeURIComponent(query)}`;
|
||
}
|
||
|
||
/** Dominio leggibile di un URL esterno (es. «agenziaentrate.gov.it»). */
|
||
export function displayDomain(url: string): string {
|
||
return new URL(url).hostname.replace(/^www\./, '');
|
||
}
|
||
|
||
/** Data in italiano: «15 ottobre 2026». */
|
||
export function formatDateIt(date: Date): string {
|
||
return new Intl.DateTimeFormat('it-IT', {
|
||
day: 'numeric',
|
||
month: 'long',
|
||
year: 'numeric',
|
||
timeZone: 'Europe/Rome',
|
||
}).format(date);
|
||
}
|
||
|
||
/** Iniziali per l'avatar: «Dott.ssa Giulia Grasso» → «GG». */
|
||
export function initials(name: string): string {
|
||
return name
|
||
.replace(/^(Dott\.ssa|Dott\.|Avv\.|Rag\.)\s+/i, '')
|
||
.split(/\s+/)
|
||
.map((p) => p.charAt(0).toUpperCase())
|
||
.join('')
|
||
.slice(0, 2);
|
||
}
|