forge
Explore
Log in

Don't you dare go Hollow

hezarfen_landing

Clone
★ 0

0 watching0 forksTypeScript581.6 KiB94b1804Burak Boduroğlu2 months ago15 commits

schema.ts186 lines, 5.6 KiBHistoryRawDownload
1import { anchors, routes, site } from "~/config";
2import type { Dictionary } from "~/i18n";
3
4/**
5 * schema.org payloads, built from the same `config.ts` and dictionary the page
6 * renders from — so the markup search engines read cannot drift from the copy
7 * a visitor reads.
8 *
9 * The site is one page, so it emits one `@graph`: the organisation, the site,
10 * the page, and the list of products the page is about. Nodes are referenced
11 * by `@id` rather than repeated, which is what lets a crawler tie them into
12 * one entity.
13 */
14
15const ORGANIZATION = `${site.url}/#organization`;
16const WEBSITE = `${site.url}/#website`;
17
18/** The logo Google reads has to be a raster; `image` is the link preview card. */
19const LOGO = `${site.url}/brand/hezarfen-mark-512.png`;
20export const OG_IMAGE = `${site.url}/og.png`;
21
22/** The site publishes in one language, so this is a constant, not a lookup. */
23const inLanguage = "tr-TR";
24
25type PageInput = {
26 url: string;
27 title: string;
28 description: string;
29 t: Dictionary;
30 /** The page's short nav label, for the home → page trail. */
31 breadcrumb?: string;
32 /** Nodes describing what the page lists, from the builders below. */
33 extra?: object[];
34};
35
36export function pageGraph(input: PageInput) {
37 const page: Record<string, unknown> = {
38 "@type": "WebPage",
39 "@id": `${input.url}#webpage`,
40 url: input.url,
41 name: input.title,
42 description: input.description,
43 isPartOf: { "@id": WEBSITE },
44 about: { "@id": ORGANIZATION },
45 primaryImageOfPage: OG_IMAGE,
46 inLanguage,
47 };
48
49 const nodes: object[] = [
50 {
51 "@type": "Organization",
52 "@id": ORGANIZATION,
53 name: site.legalName,
54 alternateName: site.name,
55 url: site.url,
56 email: site.email,
57 foundingDate: String(site.founded),
58 description: input.t.meta.homeDescription,
59 logo: { "@type": "ImageObject", url: LOGO, width: 512, height: 512 },
60 image: OG_IMAGE,
61 address: {
62 "@type": "PostalAddress",
63 addressCountry: "TR",
64 },
65 // Who builds it, so the credit in the about band is part of the entity
66 // rather than only a link in the footer.
67 parentOrganization: {
68 "@type": "Organization",
69 name: site.builder.name,
70 url: site.builder.url,
71 },
72 // The four products are what the entity is known for, so they are part
73 // of the organisation rather than only body copy on the page.
74 knowsAbout: input.t.products.items.map(item => item.name),
75 // Accounts with no address yet are dropped rather than sent as an empty
76 // string, which would make the whole property unusable.
77 sameAs: Object.values(site.social).filter(Boolean),
78 },
79 {
80 "@type": "WebSite",
81 "@id": WEBSITE,
82 url: site.url,
83 name: site.legalName,
84 publisher: { "@id": ORGANIZATION },
85 inLanguage,
86 },
87 page,
88 ];
89
90 if (input.breadcrumb) {
91 page.breadcrumb = { "@id": `${input.url}#breadcrumb` };
92 nodes.push({
93 "@type": "BreadcrumbList",
94 "@id": `${input.url}#breadcrumb`,
95 itemListElement: [
96 { "@type": "ListItem", position: 1, name: input.t.nav.home, item: `${site.url}${routes.home}` },
97 { "@type": "ListItem", position: 2, name: input.breadcrumb, item: input.url },
98 ],
99 });
100 }
101
102 return { "@context": "https://schema.org", "@graph": [...nodes, ...(input.extra ?? [])] };
103}
104
105/** `/nasil-calisir`: the chain, as a crawler can read it. */
106export function howToNode(t: Dictionary, url: string) {
107 return {
108 "@type": "HowTo",
109 "@id": `${url}#howto`,
110 name: t.how.title,
111 description: t.how.lead,
112 step: t.how.stages.map((stage, index) => ({
113 "@type": "HowToStep",
114 position: index + 1,
115 name: stage.title,
116 text: stage.description,
117 url: `${url}#${stage.id}`,
118 })),
119 };
120}
121
122/** `/iletisim`: the page a demo request is made on. */
123export function contactPageNode(t: Dictionary, url: string) {
124 return {
125 "@type": "ContactPage",
126 "@id": `${url}#contact`,
127 name: t.contact.title,
128 description: t.contact.lead,
129 mainEntity: {
130 "@type": "Organization",
131 "@id": ORGANIZATION,
132 contactPoint: {
133 "@type": "ContactPoint",
134 contactType: "sales",
135 email: site.email,
136 areaServed: "TR",
137 availableLanguage: "Turkish",
138 },
139 },
140 };
141}
142
143/**
144 * The four products, as the page lists them. No `Offer`: the licence is
145 * quoted per kurum after a conversation, and publishing a number here that
146 * the page itself does not state is how a crawler ends up quoting a price we
147 * never gave.
148 */
149export function productList(t: Dictionary, url: string) {
150 return {
151 "@type": "ItemList",
152 "@id": `${url}#urunler`,
153 name: t.products.title,
154 itemListElement: t.products.items.map((item, index) => ({
155 "@type": "ListItem",
156 position: index + 1,
157 item: {
158 "@type": "SoftwareApplication",
159 name: item.name,
160 description: item.description,
161 applicationCategory: "EducationalApplication",
162 operatingSystem: "Web",
163 url: `${site.url}${anchors.products}`,
164 author: { "@id": ORGANIZATION },
165 featureList: item.pills,
166 },
167 })),
168 };
169}
170
171/**
172 * The FAQ band, as the rich result reads it. The answers are the page's own
173 * copy verbatim — Google drops a `FAQPage` whose answers are not visible on
174 * the page, and rewriting them for the markup is exactly that.
175 */
176export function faqPage(t: Dictionary, url: string) {
177 return {
178 "@type": "FAQPage",
179 "@id": `${url}#sss`,
180 mainEntity: t.faq.items.map(item => ({
181 "@type": "Question",
182 name: item.q,
183 acceptedAnswer: { "@type": "Answer", text: item.a },
184 })),
185 };
186}