56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
type SearchActionConfig = {
|
|
/**
|
|
* URL template for site search, with {search_term_string} placeholder.
|
|
* e.g. 'https://example.com/szukaj?q={search_term_string}'. Only include if
|
|
* the site actually HAS a working search page — a SearchAction pointing at a
|
|
* non-existent search does more harm than good.
|
|
*/
|
|
target: string;
|
|
};
|
|
type WebSiteJsonLdArgs = {
|
|
/** Site name (from panel — siteName). */
|
|
name: string;
|
|
/**
|
|
* Optional site search. Enables the "sitelinks searchbox" — a search field
|
|
* Google may show under the brand result. Only pass when a real search page
|
|
* exists. Omit entirely otherwise.
|
|
*/
|
|
search?: SearchActionConfig;
|
|
/** Absolute site URL (https://…). */
|
|
url: string;
|
|
};
|
|
/**
|
|
* Builds WebSite JSON-LD (schema.org). Two jobs:
|
|
* - Declares the site + name (helps Google associate brand queries with the site).
|
|
* - Optionally declares a SearchAction, which is what can produce the "sitelinks
|
|
* searchbox" (a search field under the brand result in Google).
|
|
*
|
|
* IMPORTANT — sitelinks (the sub-links under a result) CANNOT be forced. No
|
|
* schema guarantees them; Google generates them algorithmically from site
|
|
* structure, internal links, clear titles, and ranking. This schema is a SIGNAL
|
|
* that improves the odds and can enable the searchbox — not a switch. Manage
|
|
* expectations accordingly (see docs/seo.md).
|
|
*
|
|
* Emit once in the ROOT layout (site-wide), from panel data:
|
|
*
|
|
* import { buildWebSiteJsonLd } from '@intecion/ipal-kit'
|
|
* const jsonLd = buildWebSiteJsonLd({ name: settings.siteName, url: baseUrl })
|
|
* <script type="application/ld+json"
|
|
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
|
|
*/
|
|
export declare function buildWebSiteJsonLd({ name, search, url }: WebSiteJsonLdArgs): {
|
|
potentialAction?: {
|
|
'@type': string;
|
|
'query-input': string;
|
|
target: {
|
|
'@type': string;
|
|
urlTemplate: string;
|
|
};
|
|
} | undefined;
|
|
name: string;
|
|
'@context': string;
|
|
'@type': string;
|
|
url: string;
|
|
};
|
|
export {};
|