feat: podpora více odkazů na podnik při objednávání

This commit is contained in:
2026-08-25 11:28:57 +02:00
parent 93242b7c7e
commit ce051447e6
13 changed files with 338 additions and 81 deletions
+37
View File
@@ -0,0 +1,37 @@
import { Store } from '../../../types';
/** Známé dovozové služby — hostname (bez www) → čitelný název pro nabídku. */
const KNOWN_SERVICES: { match: string; label: string }[] = [
{ match: 'bolt.eu', label: 'Bolt Food' },
{ match: 'wolt.com', label: 'Wolt' },
{ match: 'foodora.cz', label: 'Foodora' },
{ match: 'damejidlo.cz', label: 'Dáme jídlo' },
];
/**
* Ověří, že jde o odkaz s protokolem http(s) — jiné protokoly (např. javascript:)
* by mohly být zneužity, proto je jako odkaz nezobrazujeme.
*/
export function isHttpUrl(url?: string): boolean {
return !!url && /^https?:\/\//i.test(url);
}
/** Vrátí platné URL na nabídku daného obchodu. */
export function getStoreUrls(store?: Store): string[] {
return (store?.urls ?? []).filter(isHttpUrl);
}
/**
* Popisek URL pro výběr nabídky — u známých dovozových služeb jejich název,
* jinak hostname odkazu (např. "restaurace-u-nas.cz").
*/
export function storeUrlLabel(url: string): string {
let hostname: string;
try {
hostname = new URL(url).hostname.toLowerCase().replace(/^www\./, '');
} catch {
return url;
}
const known = KNOWN_SERVICES.find(s => hostname === s.match || hostname.endsWith(`.${s.match}`));
return known ? known.label : hostname;
}