@shopbite-de/storefront 1.29.0 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -0
- package/CLAUDE.md +5 -1
- package/app/components/Category/Listing.vue +1 -0
- package/app/components/Home/Faq.vue +58 -0
- package/app/components/Home/Highlights.vue +1 -0
- package/app/components/Product/Card.vue +46 -10
- package/app/components/Product/CardDietBadges.vue +7 -13
- package/app/components/Product/CrossSelling.vue +18 -2
- package/app/components/Product/DeselectIngredient.vue +10 -3
- package/app/components/Product/Detail.vue +33 -2
- package/app/components/Product/QuickView.vue +20 -1
- package/app/composables/useMenuSectionSchema.ts +21 -8
- package/app/composables/useProductCrossSelling.ts +1 -0
- package/app/composables/useProductQuickView.ts +151 -9
- package/app/composables/useRestaurantSchema.ts +40 -3
- package/app/composables/useSeoUrlRoute.ts +50 -5
- package/app/composables/useShareLink.ts +61 -0
- package/app/composables/useTopSellers.ts +4 -1
- package/app/composables/useTrackEvent.ts +19 -0
- package/app/pages/[...all].vue +38 -10
- package/app/pages/index.vue +7 -0
- package/app/types/Association.d.ts +2 -0
- package/app/utils/product.ts +28 -0
- package/app/utils/productUrl.ts +87 -0
- package/app/utils/schema.ts +82 -1
- package/app/utils/seo.ts +13 -0
- package/app/utils/seoPath.ts +13 -2
- package/content/index.yml +18 -0
- package/content.config.ts +13 -0
- package/docs/notes/2026-10-05-issue-289-product-deep-links.md +28 -0
- package/docs/notes/2026-10-05-issue-400-menu-item-ingredients-diet.md +18 -0
- package/docs/notes/2026-10-05-issue-401-restaurant-schema-ordering.md +21 -0
- package/docs/notes/2026-10-05-issue-402-llms-txt.md +17 -0
- package/docs/notes/2026-10-05-issue-403-ai-crawlers.md +15 -0
- package/docs/notes/2026-10-05-issue-404-faq.md +21 -0
- package/docs/notes/2026-10-05-issue-411-quick-view-share.md +22 -0
- package/docs/notes/2026-10-06-old-seo-url-redirect.md +30 -0
- package/nuxt.config.ts +20 -0
- package/package.json +3 -3
- package/server/api/listing/[categoryId].get.ts +3 -0
- package/server/api/product/[productId]/cross-selling.get.ts +2 -1
- package/server/plugins/ai-crawlers.ts +27 -0
- package/server/routes/llms.txt.ts +213 -0
- package/server/utils/aiCrawlers.ts +79 -0
- package/server/utils/llmsTxt.ts +207 -0
- package/test/nuxt/HomeFaq.test.ts +34 -0
- package/test/nuxt/ProductCrossSelling.test.ts +20 -0
- package/test/nuxt/ProductDeselectIngredient.test.ts +34 -0
- package/test/nuxt/useSeoUrlRoute.test.ts +88 -5
- package/test/nuxt/useShareLink.test.ts +103 -0
- package/test/nuxt/useTrackEvent.test.ts +16 -0
- package/test/unit/aiCrawlers.spec.ts +48 -0
- package/test/unit/llmsTxt.spec.ts +149 -0
- package/test/unit/product.spec.ts +20 -0
- package/test/unit/productUrl.spec.ts +90 -0
- package/test/unit/schema.spec.ts +123 -0
- package/test/unit/seo.spec.ts +13 -0
- package/test/unit/seoPath.spec.ts +45 -0
- package/app/pages/c/[...all].vue +0 -20
- package/app/pages/speisekarte/[...all].vue +0 -20
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { queryCollection } from "@nuxt/content/server";
|
|
2
|
+
import type { components } from "~~/api-types/storeApiTypes";
|
|
3
|
+
import { getDiets, getMainIngredients } from "../../app/utils/product";
|
|
4
|
+
import { productDeepLink } from "../../app/utils/productUrl";
|
|
5
|
+
import { splitList, toAbsoluteUrl } from "../../app/utils/seo";
|
|
6
|
+
import { buildLlmsTxt, type LlmsMenuSection } from "../utils/llmsTxt";
|
|
7
|
+
|
|
8
|
+
type Schemas = components["schemas"];
|
|
9
|
+
|
|
10
|
+
// Store API maximum per request.
|
|
11
|
+
const PRODUCT_PAGE_SIZE = 100;
|
|
12
|
+
// A menu has a few hundred products at most (La Fattoria: 390 incl. extras).
|
|
13
|
+
const MAX_PRODUCT_PAGES = 10;
|
|
14
|
+
|
|
15
|
+
const NAVIGATION_CRITERIA = {
|
|
16
|
+
depth: 10,
|
|
17
|
+
buildTree: true,
|
|
18
|
+
includes: {
|
|
19
|
+
category: ["id", "name", "translated", "seoUrl", "type", "children"],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const PRODUCT_CRITERIA = {
|
|
24
|
+
limit: PRODUCT_PAGE_SIZE,
|
|
25
|
+
// Main products only; variants are summed up as "ab <cheapest price>".
|
|
26
|
+
filter: [{ type: "equals", field: "parentId", value: null }],
|
|
27
|
+
associations: { properties: { associations: { group: {} } } },
|
|
28
|
+
includes: {
|
|
29
|
+
product: [
|
|
30
|
+
"id",
|
|
31
|
+
"name",
|
|
32
|
+
"translated",
|
|
33
|
+
"categoryIds",
|
|
34
|
+
"childCount",
|
|
35
|
+
"calculatedPrice",
|
|
36
|
+
"calculatedCheapestPrice",
|
|
37
|
+
"sortedProperties",
|
|
38
|
+
"productNumber",
|
|
39
|
+
"seoUrls",
|
|
40
|
+
],
|
|
41
|
+
seo_url: ["seoPathInfo", "isCanonical"],
|
|
42
|
+
calculated_price: ["unitPrice"],
|
|
43
|
+
calculated_cheapest_price: ["unitPrice"],
|
|
44
|
+
property_group: ["name", "translated", "options"],
|
|
45
|
+
property_group_option: ["name", "translated"],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `/llms.txt` (#402): the shop, its hours, ordering and the menu as Markdown
|
|
51
|
+
* for language models. Every source is optional; a failing request leaves
|
|
52
|
+
* its section out instead of failing the file.
|
|
53
|
+
*/
|
|
54
|
+
export default defineEventHandler(async (event) => {
|
|
55
|
+
const { shopware, shopBite, site } = useRuntimeConfig(event).public;
|
|
56
|
+
const siteUrl = getSiteConfig(event).url;
|
|
57
|
+
const headers = { "sw-access-key": shopware.accessToken };
|
|
58
|
+
const menuRootId = shopBite.menuCategoryId || "main-navigation";
|
|
59
|
+
|
|
60
|
+
const storeApi = <T>(path: string, body?: Record<string, unknown>) =>
|
|
61
|
+
$fetch<T>(`${shopware.endpoint}${path}`, {
|
|
62
|
+
method: body ? "POST" : "GET",
|
|
63
|
+
headers: { ...headers, "sw-include-seo-urls": "true" },
|
|
64
|
+
body,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const [navigation, products, hours, holidays, config, context, pages, home] =
|
|
68
|
+
await Promise.allSettled([
|
|
69
|
+
storeApi<Schemas["Category"][]>(
|
|
70
|
+
`/navigation/${menuRootId}/${menuRootId}`,
|
|
71
|
+
NAVIGATION_CRITERIA,
|
|
72
|
+
),
|
|
73
|
+
loadProducts((page) =>
|
|
74
|
+
storeApiPost<{ elements?: Schemas["Product"][] }>(
|
|
75
|
+
"/product",
|
|
76
|
+
{ ...PRODUCT_CRITERIA, page },
|
|
77
|
+
{ headers: { "sw-include-seo-urls": "true" } },
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
storeApi<{ businessHours?: Schemas["ShopbiteBusinessHour"][] }>(
|
|
81
|
+
"/shopbite/business-hour",
|
|
82
|
+
),
|
|
83
|
+
storeApi<{ holidays?: { start?: string; end?: string }[] }>(
|
|
84
|
+
"/shopbite/holiday",
|
|
85
|
+
),
|
|
86
|
+
storeApi<{ isCheckoutEnabled?: boolean; deliveryTime?: number }>(
|
|
87
|
+
"/shopbite/config",
|
|
88
|
+
),
|
|
89
|
+
storeApi<Schemas["SalesChannelContext"]>("/context"),
|
|
90
|
+
queryCollection(event, "landingpages")
|
|
91
|
+
.select("path", "title", "description")
|
|
92
|
+
.all(),
|
|
93
|
+
queryCollection(event, "home").select("faq").first(),
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
const value = <T>(result: PromiseSettledResult<T>) =>
|
|
97
|
+
result.status === "fulfilled" ? result.value : undefined;
|
|
98
|
+
|
|
99
|
+
const productsByCategory = groupByCategory(value(products) ?? []);
|
|
100
|
+
const toSection = (category: Schemas["Category"]): LlmsMenuSection => ({
|
|
101
|
+
name: category.translated?.name ?? category.name,
|
|
102
|
+
url: category.seoUrl ? toAbsoluteUrl(siteUrl, category.seoUrl) : undefined,
|
|
103
|
+
items: (productsByCategory.get(category.id) ?? []).map((product) => {
|
|
104
|
+
const deepLink = productDeepLink(product, category.seoUrl);
|
|
105
|
+
return {
|
|
106
|
+
...toMenuItem(product),
|
|
107
|
+
url: deepLink ? toAbsoluteUrl(siteUrl, deepLink) : undefined,
|
|
108
|
+
};
|
|
109
|
+
}),
|
|
110
|
+
sections: (category.children ?? [])
|
|
111
|
+
.filter((child) => child.type === "page")
|
|
112
|
+
.map(toSection),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const body = buildLlmsTxt({
|
|
116
|
+
name: site.name,
|
|
117
|
+
description: site.description,
|
|
118
|
+
url: siteUrl,
|
|
119
|
+
cuisine: site.cuisine,
|
|
120
|
+
address: {
|
|
121
|
+
street: site.address.street,
|
|
122
|
+
postalCode: site.address.postalCode
|
|
123
|
+
? String(site.address.postalCode)
|
|
124
|
+
: undefined,
|
|
125
|
+
city: site.address.city,
|
|
126
|
+
},
|
|
127
|
+
telephone: site.telephone,
|
|
128
|
+
googleBusinessProfileUrl: site.googleBusinessProfileUrl,
|
|
129
|
+
deliveryAreas: splitList(site.deliveryAreas),
|
|
130
|
+
businessHours: value(hours)?.businessHours,
|
|
131
|
+
holidays: value(holidays)?.holidays,
|
|
132
|
+
isCheckoutEnabled: value(config)?.isCheckoutEnabled,
|
|
133
|
+
deliveryTime: value(config)?.deliveryTime,
|
|
134
|
+
menuUrl: toAbsoluteUrl(siteUrl, "/speisekarte"),
|
|
135
|
+
menu: (value(navigation) ?? [])
|
|
136
|
+
.filter((category) => category.type === "page")
|
|
137
|
+
.map(toSection),
|
|
138
|
+
pages: (value(pages) ?? [])
|
|
139
|
+
// Pages the shop keeps out of robots.txt (legal pages) stay out here.
|
|
140
|
+
.filter(
|
|
141
|
+
(page) =>
|
|
142
|
+
getPathRobotConfig(event, {
|
|
143
|
+
path: page.path,
|
|
144
|
+
skipSiteIndexable: true,
|
|
145
|
+
}).indexable,
|
|
146
|
+
)
|
|
147
|
+
.map((page) => ({
|
|
148
|
+
title: page.title,
|
|
149
|
+
url: toAbsoluteUrl(siteUrl, page.path),
|
|
150
|
+
description: page.description,
|
|
151
|
+
})),
|
|
152
|
+
faq: value(home)?.faq?.items,
|
|
153
|
+
currency: value(context)?.currency?.isoCode,
|
|
154
|
+
now: new Date(),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
setResponseHeader(event, "Content-Type", "text/markdown; charset=utf-8");
|
|
158
|
+
return body;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
async function loadProducts(
|
|
162
|
+
loadPage: (page: number) => Promise<{ elements?: Schemas["Product"][] }>,
|
|
163
|
+
) {
|
|
164
|
+
const products: Schemas["Product"][] = [];
|
|
165
|
+
for (let page = 1; page <= MAX_PRODUCT_PAGES; page++) {
|
|
166
|
+
const elements = (await loadPage(page)).elements ?? [];
|
|
167
|
+
products.push(...elements);
|
|
168
|
+
if (elements.length < PRODUCT_PAGE_SIZE) break;
|
|
169
|
+
}
|
|
170
|
+
return products;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Products by the categories they are assigned to directly. */
|
|
174
|
+
function groupByCategory(products: Schemas["Product"][]) {
|
|
175
|
+
const byCategory = new Map<string, Schemas["Product"][]>();
|
|
176
|
+
for (const product of products) {
|
|
177
|
+
for (const categoryId of product.categoryIds ?? []) {
|
|
178
|
+
byCategory.set(categoryId, [
|
|
179
|
+
...(byCategory.get(categoryId) ?? []),
|
|
180
|
+
product,
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Alphabetical, numbers in natural order ("Pizza 9" before "Pizza 10").
|
|
185
|
+
for (const items of byCategory.values()) {
|
|
186
|
+
items.sort((a, b) =>
|
|
187
|
+
(a.translated?.name ?? a.name).localeCompare(
|
|
188
|
+
b.translated?.name ?? b.name,
|
|
189
|
+
"de",
|
|
190
|
+
{ numeric: true },
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return byCategory;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function toMenuItem(product: Schemas["Product"]) {
|
|
198
|
+
const properties = product.sortedProperties as
|
|
199
|
+
Schemas["PropertyGroup"][] | undefined;
|
|
200
|
+
const hasVariants = (product.childCount ?? 0) > 0;
|
|
201
|
+
return {
|
|
202
|
+
name: product.translated?.name ?? product.name,
|
|
203
|
+
price: hasVariants
|
|
204
|
+
? (product.calculatedCheapestPrice?.unitPrice ??
|
|
205
|
+
product.calculatedPrice?.unitPrice)
|
|
206
|
+
: product.calculatedPrice?.unitPrice,
|
|
207
|
+
fromPrice: hasVariants,
|
|
208
|
+
ingredients: getMainIngredients(properties).map(
|
|
209
|
+
(option) => option.translated?.name ?? option.name,
|
|
210
|
+
),
|
|
211
|
+
diets: getDiets(properties),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// robots.txt groups for AI crawlers (#403). Pure, so it is unit-testable;
|
|
2
|
+
// `server/plugins/ai-crawlers.ts` adds the groups at runtime.
|
|
3
|
+
//
|
|
4
|
+
// User agents as documented by the operators (checked 2026-10):
|
|
5
|
+
// OpenAI https://platform.openai.com/docs/bots, Anthropic
|
|
6
|
+
// https://support.claude.com/en/articles/8896518, Perplexity
|
|
7
|
+
// https://docs.perplexity.ai/guides/bots, Google
|
|
8
|
+
// https://developers.google.com/search/docs/crawling-indexing/google-common-crawlers,
|
|
9
|
+
// Apple https://support.apple.com/en-us/119829, Common Crawl
|
|
10
|
+
// https://commoncrawl.org/ccbot, Meta
|
|
11
|
+
// https://developers.facebook.com/docs/sharing/webmasters/web-crawlers,
|
|
12
|
+
// Mistral https://docs.mistral.ai/robots.
|
|
13
|
+
|
|
14
|
+
/** Fetch pages to answer a user's question and link to the source. */
|
|
15
|
+
export const AI_SEARCH_USER_AGENTS = [
|
|
16
|
+
"OAI-SearchBot",
|
|
17
|
+
"ChatGPT-User",
|
|
18
|
+
"Claude-SearchBot",
|
|
19
|
+
"Claude-User",
|
|
20
|
+
"PerplexityBot",
|
|
21
|
+
"Perplexity-User",
|
|
22
|
+
"MistralAI-User",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collect content to train models. Google-Extended and Applebot-Extended are
|
|
27
|
+
* tokens only: Googlebot/Applebot crawl, the token decides about AI use.
|
|
28
|
+
*/
|
|
29
|
+
export const AI_TRAINING_USER_AGENTS = [
|
|
30
|
+
"GPTBot",
|
|
31
|
+
"ClaudeBot",
|
|
32
|
+
"Google-Extended",
|
|
33
|
+
"Applebot-Extended",
|
|
34
|
+
"CCBot",
|
|
35
|
+
"meta-externalagent",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export type AiCrawlerPolicy = {
|
|
39
|
+
/** Allow AI search and assistant fetches (default true). */
|
|
40
|
+
search: boolean;
|
|
41
|
+
/** Allow crawling for model training (default true). */
|
|
42
|
+
training: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type RobotsGroup = {
|
|
46
|
+
userAgent: string[];
|
|
47
|
+
allow: string[];
|
|
48
|
+
disallow: string[];
|
|
49
|
+
comment: string[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* One group per kind. A crawler that matches a named group ignores the `*`
|
|
54
|
+
* group, so an allowed group repeats its disallow rules.
|
|
55
|
+
*/
|
|
56
|
+
export function buildAiCrawlerGroups(
|
|
57
|
+
policy: AiCrawlerPolicy,
|
|
58
|
+
disallow: string[],
|
|
59
|
+
): RobotsGroup[] {
|
|
60
|
+
const group = (
|
|
61
|
+
comment: string,
|
|
62
|
+
userAgent: string[],
|
|
63
|
+
allowed: boolean,
|
|
64
|
+
): RobotsGroup => ({
|
|
65
|
+
comment: [comment],
|
|
66
|
+
userAgent,
|
|
67
|
+
allow: allowed ? ["/"] : [],
|
|
68
|
+
disallow: allowed ? disallow.filter((path) => path && path !== "/") : ["/"],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
group(
|
|
73
|
+
"AI search and assistants: answer questions with a link to this shop",
|
|
74
|
+
AI_SEARCH_USER_AGENTS,
|
|
75
|
+
policy.search,
|
|
76
|
+
),
|
|
77
|
+
group("AI model training", AI_TRAINING_USER_AGENTS, policy.training),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { groupOpeningHours } from "../../app/utils/openingHours";
|
|
2
|
+
|
|
3
|
+
// Builder for /llms.txt (#402, https://llmstxt.org): a Markdown summary of
|
|
4
|
+
// the shop for language models. Pure, so it is unit-testable; the route
|
|
5
|
+
// gathers the data and hands it in. The text is German like the shop.
|
|
6
|
+
|
|
7
|
+
export type LlmsMenuItem = {
|
|
8
|
+
name: string;
|
|
9
|
+
/** Quick view deep link (#289). */
|
|
10
|
+
url?: string;
|
|
11
|
+
price?: number;
|
|
12
|
+
/** The product has variants; `price` is the cheapest one. */
|
|
13
|
+
fromPrice?: boolean;
|
|
14
|
+
ingredients?: string[];
|
|
15
|
+
diets?: ("vegetarian" | "vegan")[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type LlmsMenuSection = {
|
|
19
|
+
name: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
items: LlmsMenuItem[];
|
|
22
|
+
sections?: LlmsMenuSection[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type LlmsTxtInput = {
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
url: string;
|
|
29
|
+
cuisine?: string;
|
|
30
|
+
address?: { street?: string; postalCode?: string; city?: string };
|
|
31
|
+
telephone?: string;
|
|
32
|
+
googleBusinessProfileUrl?: string;
|
|
33
|
+
deliveryAreas?: string[];
|
|
34
|
+
businessHours?: {
|
|
35
|
+
dayOfWeek?: number;
|
|
36
|
+
openingTime?: string;
|
|
37
|
+
closingTime?: string;
|
|
38
|
+
}[];
|
|
39
|
+
holidays?: { start?: string; end?: string }[];
|
|
40
|
+
isCheckoutEnabled?: boolean;
|
|
41
|
+
/** Minutes until delivery. */
|
|
42
|
+
deliveryTime?: number;
|
|
43
|
+
menuUrl?: string;
|
|
44
|
+
menu?: LlmsMenuSection[];
|
|
45
|
+
pages?: { title: string; url: string; description?: string }[];
|
|
46
|
+
/** FAQ of the home page (#404). */
|
|
47
|
+
faq?: { question: string; answer: string }[];
|
|
48
|
+
currency?: string;
|
|
49
|
+
/** Closing days that ended before this date are left out. */
|
|
50
|
+
now: Date;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const DIET_LABELS = { vegetarian: "vegetarisch", vegan: "vegan" } as const;
|
|
54
|
+
|
|
55
|
+
function formatPrice(price: number, currency: string) {
|
|
56
|
+
return new Intl.NumberFormat("de-DE", { style: "currency", currency })
|
|
57
|
+
.format(price)
|
|
58
|
+
.replace(/\u00a0/g, " ");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** `2026-07-12T21:00:00Z` → `12.07.2026` (date part as in the Restaurant schema). */
|
|
62
|
+
function formatDay(isoDate: string) {
|
|
63
|
+
const [year, month, day] = isoDate.slice(0, 10).split("-");
|
|
64
|
+
return `${day}.${month}.${year}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function menuItemLine(item: LlmsMenuItem, currency: string) {
|
|
68
|
+
const price =
|
|
69
|
+
item.price !== undefined
|
|
70
|
+
? `${item.fromPrice ? "ab " : ""}${formatPrice(item.price, currency)}`
|
|
71
|
+
: undefined;
|
|
72
|
+
// Vegan dishes are vegetarian too; naming "vegan" is enough.
|
|
73
|
+
const diet = item.diets?.includes("vegan")
|
|
74
|
+
? DIET_LABELS.vegan
|
|
75
|
+
: item.diets?.includes("vegetarian")
|
|
76
|
+
? DIET_LABELS.vegetarian
|
|
77
|
+
: undefined;
|
|
78
|
+
const details = [
|
|
79
|
+
item.ingredients?.length ? item.ingredients.join(", ") : undefined,
|
|
80
|
+
diet,
|
|
81
|
+
].filter((line): line is string => Boolean(line));
|
|
82
|
+
|
|
83
|
+
const name = item.url ? `[${item.name}](${item.url})` : item.name;
|
|
84
|
+
return `- ${name}${price ? `: ${price}` : ""}${
|
|
85
|
+
details.length ? ` (${details.join("; ")})` : ""
|
|
86
|
+
}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function menuSectionLines(
|
|
90
|
+
section: LlmsMenuSection,
|
|
91
|
+
currency: string,
|
|
92
|
+
level: number,
|
|
93
|
+
): string[] {
|
|
94
|
+
const heading = "#".repeat(Math.min(level, 6));
|
|
95
|
+
const title = section.url
|
|
96
|
+
? `[${section.name}](${section.url})`
|
|
97
|
+
: section.name;
|
|
98
|
+
const subsections = (section.sections ?? []).flatMap((child) =>
|
|
99
|
+
menuSectionLines(child, currency, level + 1),
|
|
100
|
+
);
|
|
101
|
+
if (section.items.length === 0 && subsections.length === 0) return [];
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
"",
|
|
105
|
+
`${heading} ${title}`,
|
|
106
|
+
...(section.items.length ? [""] : []),
|
|
107
|
+
...section.items.map((item) => menuItemLine(item, currency)),
|
|
108
|
+
...subsections,
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function buildLlmsTxt(input: LlmsTxtInput): string {
|
|
113
|
+
const currency = input.currency || "EUR";
|
|
114
|
+
const city = input.address?.city;
|
|
115
|
+
|
|
116
|
+
const summary = [
|
|
117
|
+
input.cuisine && city
|
|
118
|
+
? `${input.name}: ${input.cuisine} in ${city}.`
|
|
119
|
+
: `${input.name}${city ? ` in ${city}` : ""}.`,
|
|
120
|
+
input.isCheckoutEnabled
|
|
121
|
+
? `Online bestellen zur Lieferung oder Abholung unter ${input.url}.`
|
|
122
|
+
: undefined,
|
|
123
|
+
]
|
|
124
|
+
.filter(Boolean)
|
|
125
|
+
.join(" ");
|
|
126
|
+
|
|
127
|
+
const contact = [
|
|
128
|
+
input.address?.street || input.address?.postalCode || city
|
|
129
|
+
? `- Adresse: ${[
|
|
130
|
+
input.address?.street,
|
|
131
|
+
[input.address?.postalCode, city].filter(Boolean).join(" "),
|
|
132
|
+
]
|
|
133
|
+
.filter(Boolean)
|
|
134
|
+
.join(", ")}`
|
|
135
|
+
: undefined,
|
|
136
|
+
input.telephone ? `- Telefon: ${input.telephone}` : undefined,
|
|
137
|
+
`- Website: ${input.url}`,
|
|
138
|
+
input.googleBusinessProfileUrl
|
|
139
|
+
? `- Google: ${input.googleBusinessProfileUrl}`
|
|
140
|
+
: undefined,
|
|
141
|
+
].filter((line): line is string => Boolean(line));
|
|
142
|
+
|
|
143
|
+
const hours = groupOpeningHours(input.businessHours ?? []).map(
|
|
144
|
+
(row) =>
|
|
145
|
+
`- ${row.days}: ${row.intervals.length ? row.intervals.join(", ") : "Ruhetag"}`,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const today = input.now.toISOString().slice(0, 10);
|
|
149
|
+
const closingDays = (input.holidays ?? [])
|
|
150
|
+
.filter((holiday) => holiday.start && holiday.end)
|
|
151
|
+
.filter((holiday) => holiday.end!.slice(0, 10) >= today)
|
|
152
|
+
.map((holiday) => {
|
|
153
|
+
const start = formatDay(holiday.start!);
|
|
154
|
+
const end = formatDay(holiday.end!);
|
|
155
|
+
return `- Geschlossen: ${start === end ? start : `${start} – ${end}`}`;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const ordering = input.isCheckoutEnabled
|
|
159
|
+
? [
|
|
160
|
+
`- Online bestellen: ${input.menuUrl ?? input.url}`,
|
|
161
|
+
input.deliveryAreas?.length
|
|
162
|
+
? `- Liefergebiet: ${input.deliveryAreas.join(", ")}`
|
|
163
|
+
: undefined,
|
|
164
|
+
input.deliveryTime
|
|
165
|
+
? `- Lieferzeit: ca. ${input.deliveryTime} Minuten`
|
|
166
|
+
: undefined,
|
|
167
|
+
input.address?.street ? "- Abholung im Restaurant möglich" : undefined,
|
|
168
|
+
].filter((line): line is string => Boolean(line))
|
|
169
|
+
: [];
|
|
170
|
+
|
|
171
|
+
const menu = (input.menu ?? []).flatMap((section) =>
|
|
172
|
+
menuSectionLines(section, currency, 3),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const pages = (input.pages ?? []).map(
|
|
176
|
+
(page) =>
|
|
177
|
+
`- [${page.title}](${page.url})${page.description && page.description !== page.title ? `: ${page.description}` : ""}`,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const sections: string[][] = [
|
|
181
|
+
[`# ${input.name}`, "", `> ${summary}`],
|
|
182
|
+
input.description ? [input.description] : [],
|
|
183
|
+
["## Kontakt", "", ...contact],
|
|
184
|
+
hours.length || closingDays.length
|
|
185
|
+
? ["## Öffnungszeiten", "", ...hours, ...closingDays]
|
|
186
|
+
: [],
|
|
187
|
+
ordering.length ? ["## Bestellen", "", ...ordering] : [],
|
|
188
|
+
input.faq?.length
|
|
189
|
+
? [
|
|
190
|
+
"## Häufige Fragen",
|
|
191
|
+
...input.faq.flatMap((item) => [
|
|
192
|
+
"",
|
|
193
|
+
`### ${item.question}`,
|
|
194
|
+
"",
|
|
195
|
+
item.answer,
|
|
196
|
+
]),
|
|
197
|
+
]
|
|
198
|
+
: [],
|
|
199
|
+
menu.length ? ["## Speisekarte", ...menu] : [],
|
|
200
|
+
pages.length ? ["## Weitere Informationen", "", ...pages] : [],
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
return `${sections
|
|
204
|
+
.filter((lines) => lines.length)
|
|
205
|
+
.map((lines) => lines.join("\n"))
|
|
206
|
+
.join("\n\n")}\n`;
|
|
207
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mountSuspended } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import HomeFaq from "~/components/Home/Faq.vue";
|
|
4
|
+
|
|
5
|
+
const items = [
|
|
6
|
+
{ question: "Wohin liefern Sie?", answer: "Nach Obertshausen." },
|
|
7
|
+
{ question: "Wie kann ich bezahlen?", answer: "Bar oder mit EC-Karte." },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
describe("HomeFaq", () => {
|
|
11
|
+
it("renders every answer in the markup, collapsed", async () => {
|
|
12
|
+
const wrapper = await mountSuspended(HomeFaq, { props: { items } });
|
|
13
|
+
|
|
14
|
+
const details = wrapper.findAll("details");
|
|
15
|
+
expect(details).toHaveLength(2);
|
|
16
|
+
expect(details.every((d) => d.attributes("open") === undefined)).toBe(true);
|
|
17
|
+
expect(wrapper.find("summary").text()).toBe("Wohin liefern Sie?");
|
|
18
|
+
expect(wrapper.text()).toContain("Bar oder mit EC-Karte.");
|
|
19
|
+
expect(wrapper.text()).toContain("Häufige Fragen");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("adds FAQPage JSON-LD to the head", async () => {
|
|
23
|
+
await mountSuspended(HomeFaq, { props: { items } });
|
|
24
|
+
// unhead renders the DOM debounced
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
26
|
+
|
|
27
|
+
const schemas = [
|
|
28
|
+
...document.head.querySelectorAll('script[type="application/ld+json"]'),
|
|
29
|
+
].map((script) => JSON.parse(script.textContent ?? "{}"));
|
|
30
|
+
const schema = schemas.find((entry) => entry["@type"] === "FAQPage");
|
|
31
|
+
expect(schema).toBeDefined();
|
|
32
|
+
expect(schema!.mainEntity).toHaveLength(2);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -12,6 +12,7 @@ const group = (label: string, count: number): AssociationItem => ({
|
|
|
12
12
|
products: Array.from({ length: count }, (_, index) => ({
|
|
13
13
|
label: `${label} ${index + 1}`,
|
|
14
14
|
value: `${label}-${index + 1}`,
|
|
15
|
+
productNumber: `${label}-NR-${index + 1}`,
|
|
15
16
|
price: "1.00 €",
|
|
16
17
|
unitPrice: 1,
|
|
17
18
|
})),
|
|
@@ -96,4 +97,23 @@ describe("ProductCrossSelling", () => {
|
|
|
96
97
|
{ value: "Extras-3" },
|
|
97
98
|
]);
|
|
98
99
|
});
|
|
100
|
+
|
|
101
|
+
it("preselects extras from the URL and emits them (#411)", async () => {
|
|
102
|
+
const wrapper = await mountSuspended(ProductCrossSelling, {
|
|
103
|
+
props: {
|
|
104
|
+
associations: [group("Extras", 3)],
|
|
105
|
+
initialExtras: ["Extras-NR-2", "unknown"],
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const emitted = wrapper.emitted("extras-selected");
|
|
110
|
+
expect(emitted?.[0]?.[0]).toEqual([
|
|
111
|
+
expect.objectContaining({ productNumber: "Extras-NR-2" }),
|
|
112
|
+
]);
|
|
113
|
+
const checked = rows(wrapper).map(
|
|
114
|
+
(row: { attributes: (name: string) => string | undefined }) =>
|
|
115
|
+
row.attributes("aria-checked"),
|
|
116
|
+
);
|
|
117
|
+
expect(checked).toEqual(["false", "true", "false"]);
|
|
118
|
+
});
|
|
99
119
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mountSuspended } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import type { Schemas } from "#shopware";
|
|
4
|
+
import ProductDeselectIngredient from "~/components/Product/DeselectIngredient.vue";
|
|
5
|
+
|
|
6
|
+
const product = {
|
|
7
|
+
properties: ["Tomatensoße", "Zwiebeln", "Oliven"].map((name) => ({
|
|
8
|
+
group: { name: "Hauptzutaten" },
|
|
9
|
+
translated: { name },
|
|
10
|
+
})),
|
|
11
|
+
} as unknown as Schemas["Product"];
|
|
12
|
+
|
|
13
|
+
describe("ProductDeselectIngredient", () => {
|
|
14
|
+
it("starts without deselected ingredients", async () => {
|
|
15
|
+
const wrapper = await mountSuspended(ProductDeselectIngredient, {
|
|
16
|
+
props: { product },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(wrapper.emitted("ingredients-deselected")).toBeUndefined();
|
|
20
|
+
expect(wrapper.findAll('[aria-pressed="true"]')).toHaveLength(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("deselects ingredients from the URL and ignores unknown names (#411)", async () => {
|
|
24
|
+
const wrapper = await mountSuspended(ProductDeselectIngredient, {
|
|
25
|
+
props: { product, initialDeselected: ["Zwiebeln", "Salami"] },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(wrapper.emitted("ingredients-deselected")?.[0]).toEqual([
|
|
29
|
+
["Zwiebeln"],
|
|
30
|
+
]);
|
|
31
|
+
const pressed = wrapper.findAll('[aria-pressed="true"]');
|
|
32
|
+
expect(pressed.map((button) => button.text())).toEqual(["Zwiebeln"]);
|
|
33
|
+
});
|
|
34
|
+
});
|