@shop-on/create-theme 0.8.0 → 0.10.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/dist/LICENSE.md +2 -2
- package/package.json +1 -1
- package/template/.claude/skills/theme-dev/SKILL.md +3 -1
- package/template/.claude/skills/theme-dev/recipes/custom-sections.md +48 -0
- package/template/.claude/skills/theme-dev/recipes/input-settings.md +5 -3
- package/template/LICENSE.md +2 -2
- package/template/README.md +3 -3
- package/template/package.json +10 -10
- package/template/src/ai/guide.md +25 -0
- package/template/src/blocks/custom-block.json +4 -0
- package/template/src/blocks/custom-block.test.ts +16 -0
- package/template/src/blocks/custom-block.tsx +26 -0
- package/template/src/lib/i18n.ts +9 -0
- package/template/src/locales/en.default.json +4 -0
- package/template/src/locales/en.default.schema.json +16 -2
- package/template/src/locales/mn.default.json +4 -0
- package/template/src/locales/mn.default.schema.json +16 -2
- package/template/src/routeTree.gen.ts +22 -0
- package/template/src/routes/{-$locale}/orders/find.tsx +13 -0
- package/template/src/sections/custom-section.json +39 -0
- package/template/src/sections/custom-section.test.ts +14 -0
- package/template/src/sections/custom-section.tsx +73 -0
- package/template/src/sections/hero.json +6 -1
- package/template/src/sections/main-product.json +1 -0
- package/template/src/sections/main-product.tsx +15 -0
- package/template/src/server/settings.ts +26 -6
package/dist/LICENSE.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Shopon Theme Development License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026 Cody LLC. All rights reserved except as granted below.
|
|
4
4
|
|
|
5
5
|
"The Software" is this package, its source, and its documentation. "The
|
|
6
|
-
Platform" is
|
|
6
|
+
Platform" is Shopon, the commerce platform operated by Cody LLC.
|
|
7
7
|
|
|
8
8
|
## 1. Grant
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -98,6 +98,7 @@ Pick the matching recipe and follow it end-to-end:
|
|
|
98
98
|
- [Wire a picker (image/video/menu/collection/product_list/metaobject)](recipes/picker-data.md)
|
|
99
99
|
- [Dynamic sources (editor "dynamic values")](recipes/dynamic-sources.md) — the loader-side resolution pass; raw `product_attribute:title` on the storefront means it's missing
|
|
100
100
|
- [Design or optimize data fetching](recipes/data-fetching.md) — SSR, payload sizing, lazy interaction data, route loaders
|
|
101
|
+
- [AI-built sections and blocks](recipes/custom-sections.md) — the shipped `custom-section` / `custom-block`: how they work, the rules for changing them, what to do as the theme grows
|
|
101
102
|
- [Add buyer auth to a theme](recipes/customer-auth.md) — consume the `@shop-on/theme-server` auth surface: bouncers, handoff consume, customer-aware cart, logout, header account control
|
|
102
103
|
- [Add a translation key](recipes/locales.md)
|
|
103
104
|
- [Input setting types reference](recipes/input-settings.md) — every supported `type`, value shape, gotchas
|
|
@@ -267,13 +268,14 @@ Write the notes **for the merchant, not the diff**: what changes in their store,
|
|
|
267
268
|
|
|
268
269
|
## AI guide + recipes (`src/ai/`)
|
|
269
270
|
|
|
270
|
-
AI assistants connected to a store (Claude, ChatGPT)
|
|
271
|
+
AI assistants connected to a store (Claude, ChatGPT) and `shop-on theme mcp` edit a theme through one set of editor tools. What they know about _this_ theme comes from `src/ai/`: `get_theme_guide` serves `guide.md`, `list_recipes` / `apply_recipe` serve `recipes/<handle>.json`.
|
|
271
272
|
|
|
272
273
|
- **`guide.md`** — a designer's brief for the model, plain Markdown, ≤ 16 KB: what the theme is for, which section does which job, the settings that matter, what to avoid. Section, block and setting handles in backticks.
|
|
273
274
|
- **`recipes/<handle>.json`** — named page builds, ≤ 20, each ≤ 32 KB, handle `[a-z0-9-]`. Shape: `{ "name", "description", "params": { "<id>": { "type": "text" | "collection" | "image" | …, "label", "required" } }, "position": "append" | "prepend" | "replace", "sections": [{ "type", "settings", "blocks" }] }`; a param is used as `"{{id}}"` inside a setting value.
|
|
274
275
|
- **The rule is strict:** `ai/` holds exactly `guide.md` and `recipes/*.json`. No other file, subdir or dotfile — the build and the upload both refuse it.
|
|
275
276
|
- **Recipes are checked at build — but only shallowly.** Every section/block type and setting id must exist, or `pnpm build` fails. Setting values are checked only when a merchant applies the recipe: a select value outside its options, an out-of-range number or a `palette:` ref the shop no longer has makes `apply_recipe` refuse the whole recipe. Keep literal values to the schema's options; leave colours to the theme's defaults.
|
|
276
277
|
- **Optional params drop their line.** The editor tools store a rich-text value with nothing to show as `""` — `<p>{{tagline}}</p>` or `<a href="tel:{{phone}}">{{phone}}</a>` with the param omitted, or `<p> </p>` — so a theme that hides empty rich text drops it. A plain `text` setting, a button label or an FAQ row's question is not emptied for you: make that param required, or check the block renders nothing when it is blank.
|
|
278
|
+
- **Custom sections need a guide section too.** If the theme ships `custom-section` / `custom-block`, `guide.md` says how to style one for this theme, and changes with the theme's CSS variables: see [custom-sections.md](recipes/custom-sections.md#as-the-theme-grows).
|
|
277
279
|
- **Keep it in step with the sections.** Adding, renaming or removing a section or block, or changing a setting the guide names, means editing `guide.md` and any recipe that uses it in the same change.
|
|
278
280
|
|
|
279
281
|
## Building in the editor (Save to source)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# AI-built sections and blocks (custom sections)
|
|
2
|
+
|
|
3
|
+
When no section your theme ships fits what a merchant asks for ("a comparison table", "our three stores with opening hours"), an AI assistant connected to the store can write one. It writes Liquid, the platform validates it, and your theme renders the result. Two theme-shipped types make that possible:
|
|
4
|
+
|
|
5
|
+
- `sections/custom-section.{json,tsx}`: an AI-built section, a band of its own on the page.
|
|
6
|
+
- `blocks/custom-block.{json,tsx}`: an AI-built block inside a section that lists it (the product page's info column, say).
|
|
7
|
+
|
|
8
|
+
**The starter ships both, wired.** This recipe is what each piece does and the rules for changing it. Each file is also the **capability gate** for its feature: delete `custom-section` and the theme gets no custom sections; delete `custom-block` and it gets no custom blocks.
|
|
9
|
+
|
|
10
|
+
## How it works
|
|
11
|
+
|
|
12
|
+
An instance carries a `definition` field next to its `settings`: `{ settings: SchemaSetting[], liquid: string }`. The AI declares its own settings and writes the template. The values sit in the instance's ordinary `settings`, and its CSS goes in `custom_css`. The theme never reads `definition`: the render pass turns it into HTML and deletes it before the component renders.
|
|
13
|
+
|
|
14
|
+
| Piece | Where |
|
|
15
|
+
| ---------------------------------------------- | --------------------------------------------------------- |
|
|
16
|
+
| Section shell: width + padding settings | `src/sections/custom-section.json` |
|
|
17
|
+
| Draws the finished HTML, or the editor's error | `src/sections/custom-section.tsx` |
|
|
18
|
+
| Block (no settings, no shell) | `src/blocks/custom-block.{json,tsx}` |
|
|
19
|
+
| The render pass | `loadTemplate` in `src/server/settings.ts` |
|
|
20
|
+
| The section that takes custom blocks | `main-product` (`"blocks": [{ "type": "custom-block" }]`) |
|
|
21
|
+
| How the AI should style for this theme | `## Custom sections` in `src/ai/guide.md` |
|
|
22
|
+
|
|
23
|
+
## Rules when you change them
|
|
24
|
+
|
|
25
|
+
- **The section declares only reserved ids.** The contract reserves four, `color_scheme`, `container`, `padding_top` and `padding_bottom` (`BASE_SETTING_IDS`, `@shop-on/theme-contract/custom-section`), and the AI reads them as `settings.<id>`. Any other id on the type could clash with one the AI declares. `custom-section.test.ts` pins the set.
|
|
26
|
+
- **No `presets` on the section.** Without one the type never shows in the merchant's "Add section" picker. The AI adds instances with its own tool, `create_custom_section`. (`theme:check` knows this and doesn't ask for presets.)
|
|
27
|
+
- **Render through `CustomSectionHtml`, never anything else.** Not a bare `dangerouslySetInnerHTML`, and never a Custom HTML snippet that re-activates `<script>` tags: AI-written markup must never run one. `CustomSectionHtml` doesn't activate scripts, and it hands same-origin link clicks to the router, so internal links navigate client-side and keep the editor's preview.
|
|
28
|
+
- **Empty renders nothing.** `customHtml` is `""` when there is nothing to draw, and the section returns `null` so it takes no space. `customError` exists only in editor preview, since the pass writes it only when the request carries an editor `sid`.
|
|
29
|
+
- **The block declares no settings at all**: every setting it has comes from its definition. It has no shell either. The section around it owns width and spacing, and the base ids read as `nil` inside a block.
|
|
30
|
+
- **The pass runs after `runEnrichment`.** The enrichment's last phase re-scans string settings, so rendered HTML has to land after it. If you add a Custom Liquid pass, run this one after that too. Keep the `import()` dynamic, so liquidjs stays out of the client bundle. A page with no custom section loads neither liquidjs nor the validator.
|
|
31
|
+
- **`localizePath` only takes a locale the shop serves.** `req.locale` is server-fn input, and a crafted one would turn a site path into another host's (`//evil.example/…`). That's what the `isValidLocale` guard is for.
|
|
32
|
+
|
|
33
|
+
## As the theme grows
|
|
34
|
+
|
|
35
|
+
- **Adding color schemes:** the starter's section leaves out `color_scheme`, because with no schemes its picker would do nothing. When you add a `color_scheme_group` to the theme settings, add a `color_scheme` setting to `custom-section.json`, put its value on `data-color-scheme` on the section root, add the `settings.color_scheme` label to every schema catalog, and switch `custom-section.test.ts` to expect all four ids. Then tell the guide which CSS variables follow the scheme.
|
|
36
|
+
- **Loading the route product or collection in `settings.ts`:** pass `product` (the `ProductData`) and `getCollection` (a lazy provider) to `renderCustomSections`. Until you do, the template's `product` / `collection` drops are `nil` on those pages, but pickers the AI declared still resolve. See [dynamic-sources.md](dynamic-sources.md) for loading the route resource.
|
|
37
|
+
- **Letting another section take custom blocks:** add `{ "type": "custom-block" }` to its `blocks`. A container block can list it too. `create_custom_block` refuses any section that doesn't.
|
|
38
|
+
- **Drop empty blocks from your spacing.** An AI block that rendered nothing still sits in `blocks`. A section that wraps each block in a spaced row has to skip it, or it opens an empty gap. `main-product` shows how: `blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings))`, with `hasCustomOutput` from `@shop-on/theme-react/custom-section-html`.
|
|
39
|
+
- **Restyling the theme:** keep the guide's `## Custom sections` honest. The AI's HTML renders inside your page, so your stylesheet applies, and the AI is told to use the classes and CSS variables the guide names. Name your own heading, text and button classes there (`.button`, `.h2`: classes your stylesheet defines outright), and say whether plain `h1`–`h6` are styled (Tailwind's preflight resets them unless your base styles put them back). Don't name Tailwind utilities: Tailwind emits only the ones your own source uses, so the rest don't exist. Everything else the AI writes as plain CSS in `custom_css` against the variables the guide names. Rename a class or variable, and the guide changes in the same commit. Also tell it your root font size if `1rem` isn't 16px.
|
|
40
|
+
|
|
41
|
+
## What the AI can and can't do
|
|
42
|
+
|
|
43
|
+
You don't enforce any of this. It's here so you know what can land in your sections:
|
|
44
|
+
|
|
45
|
+
- **Validated, then escaped.** The platform refuses a template with `script`, `style`, `iframe`, `form`, `svg`, an `on*` or `style` attribute, or an unquoted attribute. It HTML-escapes every output except sanitized rich text. A URL attribute must be static (`/`, `#`, `https://`, `mailto:`, `tel:`) or one output through `link_url` / `image_url`.
|
|
46
|
+
- **Data:** `settings`, the route `product` and `collection`, `shop`, and the pickers the AI declared (product, product list, collection, image, menu, page, metaobject), resolved server-side. A setting can also take a dynamic source (a metafield of the page's product, for instance), and a rich-text metafield's `.html` renders as text.
|
|
47
|
+
- **Limits:** a template of up to 16 KB, CSS up to 8 KB, 12 declared settings, and **six custom sections and blocks together per template or section group**. Past six, the rest render empty and publish refuses.
|
|
48
|
+
- **Merchant view:** the theme editor badges them "AI-built", never offers the types in its pickers, and copies the definition on duplicate or paste.
|
|
@@ -521,10 +521,12 @@ Hide a setting based on a sibling's value:
|
|
|
521
521
|
}
|
|
522
522
|
```
|
|
523
523
|
|
|
524
|
-
- **Inside block schemas:** reference siblings as `settings.<id
|
|
524
|
+
- **Inside block schemas:** reference siblings as `settings.<id>`, and the owning section's settings as `section.settings.<id>` (e.g. hide a card field the section's card style never renders).
|
|
525
525
|
- **Inside section schemas:** use `section.settings.<id>`.
|
|
526
|
-
- Evaluated by the editor as a small Liquid
|
|
527
|
-
-
|
|
526
|
+
- Evaluated by the editor as a small subset of Liquid: `==` / `!=` against a quoted literal or `blank`, `<` `<=` `>` `>=` on numbers, a bare `settings.<id>` for truthiness, `and` / `or`, and parentheses.
|
|
527
|
+
- **`and` / `or` read right to left, like Liquid, with no precedence:** `a and b or c` is `a and (b or c)`. When you mean `(a and b) or c`, write the parentheses.
|
|
528
|
+
- **An unsaved setting reads as its schema `default`**, as it renders on the storefront. So a checkbox that defaults on gates its dependents with a bare `{{ settings.show_x }}` (or `== true`), and they still show on an instance that never saved it.
|
|
529
|
+
- **Gate a field only when it does nothing**: a hidden field that still worked is a setting the merchant can no longer reach. A `!= blank` gate on a picker also hides its dependents while the picker is bound to a dynamic source, because a binding is not stored in `settings`.
|
|
528
530
|
|
|
529
531
|
---
|
|
530
532
|
|
package/template/LICENSE.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Shopon Theme Development License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026 Cody LLC. All rights reserved except as granted below.
|
|
4
4
|
|
|
5
5
|
"The Software" is this package, its source, and its documentation. "The
|
|
6
|
-
Platform" is
|
|
6
|
+
Platform" is Shopon, the commerce platform operated by Cody LLC.
|
|
7
7
|
|
|
8
8
|
## 1. Grant
|
|
9
9
|
|
package/template/README.md
CHANGED
|
@@ -49,9 +49,9 @@ with a "missing" message naming the variable.
|
|
|
49
49
|
| `pnpm theme:check` | the quality bar's static rules; `--release` before handing off |
|
|
50
50
|
| `pnpm build` | the theme artifact in `.output/`, with `release-notes.md` alongside it |
|
|
51
51
|
|
|
52
|
-
To sell the theme on the
|
|
52
|
+
To sell the theme on the Shopon theme store, register at the developer portal
|
|
53
53
|
and submit its source: `npx @shop-on/theme-cli theme source` writes the
|
|
54
|
-
tarball to upload.
|
|
54
|
+
tarball to upload. Shopon builds it and reviews the result; see the developer
|
|
55
55
|
portal guide.
|
|
56
56
|
|
|
57
57
|
`npx @shop-on/theme-cli theme dev` runs the theme behind the gateway and a
|
|
@@ -84,4 +84,4 @@ src/
|
|
|
84
84
|
|
|
85
85
|
## License
|
|
86
86
|
|
|
87
|
-
For developing themes for
|
|
87
|
+
For developing themes for Shopon only. See [LICENSE.md](LICENSE.md). The third-party skills under `.claude/skills/` (everything but `theme-dev`) are MIT; each folder carries its own `LICENSE.md`.
|
package/template/package.json
CHANGED
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@bprogress/core": "1.3.4",
|
|
20
|
-
"@shop-on/i18n": "^0.
|
|
21
|
-
"@shop-on/theme-contract": "^0.
|
|
22
|
-
"@shop-on/theme-loader": "^0.
|
|
23
|
-
"@shop-on/theme-react": "^0.
|
|
24
|
-
"@shop-on/theme-routes": "^0.
|
|
25
|
-
"@shop-on/theme-runtime": "^0.
|
|
26
|
-
"@shop-on/theme-server": "^0.
|
|
27
|
-
"@shop-on/theme-system": "^0.
|
|
20
|
+
"@shop-on/i18n": "^0.10.0",
|
|
21
|
+
"@shop-on/theme-contract": "^0.10.0",
|
|
22
|
+
"@shop-on/theme-loader": "^0.10.0",
|
|
23
|
+
"@shop-on/theme-react": "^0.10.0",
|
|
24
|
+
"@shop-on/theme-routes": "^0.10.0",
|
|
25
|
+
"@shop-on/theme-runtime": "^0.10.0",
|
|
26
|
+
"@shop-on/theme-server": "^0.10.0",
|
|
27
|
+
"@shop-on/theme-system": "^0.10.0",
|
|
28
28
|
"@tailwindcss/vite": "4.3.3",
|
|
29
29
|
"@tanstack/react-router": "1.170.45",
|
|
30
30
|
"@tanstack/react-start": "1.169.3",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"tailwindcss": "4.3.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@shop-on/theme-config": "^0.
|
|
39
|
-
"@shop-on/theme-dev-host": "^0.
|
|
38
|
+
"@shop-on/theme-config": "^0.10.0",
|
|
39
|
+
"@shop-on/theme-dev-host": "^0.10.0",
|
|
40
40
|
"@spiriit/vite-plugin-svg-spritemap": "7.2.0",
|
|
41
41
|
"@types/node": "26.6.5",
|
|
42
42
|
"@types/react": "19.3.0",
|
package/template/src/ai/guide.md
CHANGED
|
@@ -22,6 +22,31 @@ one they won't reach for.
|
|
|
22
22
|
(`cta_label`, `cta_url`). Keep the headline short; leave the button out
|
|
23
23
|
rather than pointing it nowhere.
|
|
24
24
|
|
|
25
|
+
## Custom sections
|
|
26
|
+
|
|
27
|
+
Build a custom section only when no section above can do the job, after
|
|
28
|
+
checking their settings. Its width (`container`: small, medium, large, page or
|
|
29
|
+
full) and padding come from the theme, so its own markup needs no outer
|
|
30
|
+
background or page margins.
|
|
31
|
+
|
|
32
|
+
The theme's utility classes don't exist inside it: write plain CSS in the
|
|
33
|
+
section's CSS against these variables:
|
|
34
|
+
|
|
35
|
+
- Colors: `--color-background`, `--color-foreground` (text), `--color-muted`
|
|
36
|
+
(secondary text), `--color-border` (hairlines), `--color-accent` (buttons
|
|
37
|
+
and links) and `--color-accent-foreground` (text on the accent).
|
|
38
|
+
|
|
39
|
+
Use the variables rather than fixed colors, so the section follows the theme
|
|
40
|
+
when its palette changes.
|
|
41
|
+
|
|
42
|
+
## Custom blocks
|
|
43
|
+
|
|
44
|
+
For content that belongs in the product page's info column rather than as its
|
|
45
|
+
own band (a delivery note, a size hint, a trust badge), build a custom block
|
|
46
|
+
with `create_custom_block` in `main-product`, the one section that takes one.
|
|
47
|
+
It follows the CSS rules above, but the section around it owns the width and
|
|
48
|
+
spacing: keep it compact, with no outer padding or background of its own.
|
|
49
|
+
|
|
25
50
|
## What to avoid
|
|
26
51
|
|
|
27
52
|
- Don't stack two `hero` sections.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import mainProduct from "../sections/main-product.json";
|
|
3
|
+
import schema from "./custom-block.json";
|
|
4
|
+
|
|
5
|
+
// A custom block's settings are the ones its `definition` declares, and a
|
|
6
|
+
// declared id may not repeat one of the type's: any setting here could clash
|
|
7
|
+
// with a declared one.
|
|
8
|
+
it("declares no settings of its own", () => {
|
|
9
|
+
expect(schema.settings).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// The case for custom blocks: AI-written content in the product page's info
|
|
13
|
+
// column. `create_custom_block` refuses a section that doesn't list the type.
|
|
14
|
+
it("is one of the blocks the product information section takes", () => {
|
|
15
|
+
expect(mainProduct.blocks.map((b) => b.type)).toContain("custom-block");
|
|
16
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useTranslations } from "@shop-on/i18n";
|
|
2
|
+
import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
|
|
3
|
+
|
|
4
|
+
// A block an AI assistant wrote inside a section that lists `custom-block`
|
|
5
|
+
// (main-product's info column): rendered on the server by the same pass as a
|
|
6
|
+
// custom section, arriving as `customHtml`. No shell of its own: the section
|
|
7
|
+
// around it owns the width and spacing.
|
|
8
|
+
export default function CustomBlock({
|
|
9
|
+
customHtml = null,
|
|
10
|
+
customError = null,
|
|
11
|
+
}: {
|
|
12
|
+
customHtml?: string | null;
|
|
13
|
+
customError?: string | null;
|
|
14
|
+
}) {
|
|
15
|
+
const t = useTranslations("custom_section");
|
|
16
|
+
|
|
17
|
+
// Editor-only by construction: the pass writes `customError` only when the
|
|
18
|
+
// request carries an editor `sid`.
|
|
19
|
+
if (customError)
|
|
20
|
+
return (
|
|
21
|
+
<p className="rounded-lg border border-border p-4 text-sm text-muted">
|
|
22
|
+
{t("block_error")}: {customError}
|
|
23
|
+
</p>
|
|
24
|
+
);
|
|
25
|
+
return <CustomSectionHtml html={customHtml ?? ""} />;
|
|
26
|
+
}
|
package/template/src/lib/i18n.ts
CHANGED
|
@@ -37,3 +37,12 @@ export function publicPath(pathname: string): string {
|
|
|
37
37
|
if (!getCurrentLocale()) return pathname;
|
|
38
38
|
return localizeUrl(new URL(pathname, "http://internal")).pathname;
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/** The public path for a site path in an EXPLICIT content locale (undefined on
|
|
42
|
+
* the primary one), for server code that holds the request's locale rather
|
|
43
|
+
* than the ambient one: the custom-section pass's `localizePath`. The raw
|
|
44
|
+
* string is prefixed, so a query survives. */
|
|
45
|
+
export function localizedPath(path: string, locale: string | undefined): string {
|
|
46
|
+
if (!locale) return path;
|
|
47
|
+
return `/${locale}${path === "/" ? "" : path}`;
|
|
48
|
+
}
|
|
@@ -26,7 +26,11 @@
|
|
|
26
26
|
"main_article": "Article",
|
|
27
27
|
"main_search": "Search results",
|
|
28
28
|
"main_policy": "Policy",
|
|
29
|
-
"main_password": "Password"
|
|
29
|
+
"main_password": "Password",
|
|
30
|
+
"custom_section": "AI-built section"
|
|
31
|
+
},
|
|
32
|
+
"blocks": {
|
|
33
|
+
"custom_block": "AI-built block"
|
|
30
34
|
},
|
|
31
35
|
"names": {
|
|
32
36
|
"custom_css": "Custom CSS"
|
|
@@ -42,7 +46,17 @@
|
|
|
42
46
|
"cta_label": "Button label",
|
|
43
47
|
"cta_url": "Button link",
|
|
44
48
|
"heading": "Heading",
|
|
45
|
-
"message": "Message"
|
|
49
|
+
"message": "Message",
|
|
50
|
+
"content_width": "Content width",
|
|
51
|
+
"padding_top": "Top padding",
|
|
52
|
+
"padding_bottom": "Bottom padding"
|
|
53
|
+
},
|
|
54
|
+
"content_width_options": {
|
|
55
|
+
"small": "Narrow",
|
|
56
|
+
"medium": "Medium",
|
|
57
|
+
"large": "Wide",
|
|
58
|
+
"page": "Page width",
|
|
59
|
+
"full": "Full width"
|
|
46
60
|
},
|
|
47
61
|
"info": {
|
|
48
62
|
"custom_css": "Applies to every page. Target a section with its `.section-<type>` class, a block with `.block-<type>`."
|
|
@@ -26,7 +26,11 @@
|
|
|
26
26
|
"main_article": "Нийтлэл",
|
|
27
27
|
"main_search": "Хайлтын үр дүн",
|
|
28
28
|
"main_policy": "Бодлого",
|
|
29
|
-
"main_password": "Нууц үг"
|
|
29
|
+
"main_password": "Нууц үг",
|
|
30
|
+
"custom_section": "AI бүтээсэн хэсэг"
|
|
31
|
+
},
|
|
32
|
+
"blocks": {
|
|
33
|
+
"custom_block": "AI бүтээсэн блок"
|
|
30
34
|
},
|
|
31
35
|
"names": {
|
|
32
36
|
"custom_css": "Өөрийн CSS"
|
|
@@ -42,7 +46,17 @@
|
|
|
42
46
|
"cta_label": "Товчны бичиг",
|
|
43
47
|
"cta_url": "Товчны холбоос",
|
|
44
48
|
"heading": "Гарчиг",
|
|
45
|
-
"message": "Мессеж"
|
|
49
|
+
"message": "Мессеж",
|
|
50
|
+
"content_width": "Агуулгын өргөн",
|
|
51
|
+
"padding_top": "Дээд зай",
|
|
52
|
+
"padding_bottom": "Доод зай"
|
|
53
|
+
},
|
|
54
|
+
"content_width_options": {
|
|
55
|
+
"small": "Нарийн",
|
|
56
|
+
"medium": "Дунд",
|
|
57
|
+
"large": "Өргөн",
|
|
58
|
+
"page": "Хуудасны өргөн",
|
|
59
|
+
"full": "Бүтэн өргөн"
|
|
46
60
|
},
|
|
47
61
|
"info": {
|
|
48
62
|
"custom_css": "Бүх хуудсанд үйлчилнэ. Хэсгийг `.section-<type>`, блокийг `.block-<type>` классаар онилно."
|
|
@@ -29,6 +29,7 @@ import { Route as Char123LocaleChar125AccountVerifyRouteImport } from './routes/
|
|
|
29
29
|
import { Route as Char123LocaleChar125BlogsBlogHandleRouteImport } from './routes/{-$locale}/blogs/$blogHandle'
|
|
30
30
|
import { Route as Char123LocaleChar125CollectionsIndexRouteImport } from './routes/{-$locale}/collections/index'
|
|
31
31
|
import { Route as Char123LocaleChar125CollectionsCollectionHandleRouteImport } from './routes/{-$locale}/collections/$collectionHandle'
|
|
32
|
+
import { Route as Char123LocaleChar125OrdersFindRouteImport } from './routes/{-$locale}/orders/find'
|
|
32
33
|
import { Route as Char123LocaleChar125PagesHandleRouteImport } from './routes/{-$locale}/pages/$handle'
|
|
33
34
|
import { Route as Char123LocaleChar125PoliciesHandleRouteImport } from './routes/{-$locale}/policies/$handle'
|
|
34
35
|
import { Route as Char123LocaleChar125PreviewSectionRouteImport } from './routes/{-$locale}/preview/section'
|
|
@@ -148,6 +149,12 @@ const Char123LocaleChar125CollectionsCollectionHandleRoute =
|
|
|
148
149
|
path: '/collections/$collectionHandle',
|
|
149
150
|
getParentRoute: () => Char123LocaleChar125Route,
|
|
150
151
|
} as any)
|
|
152
|
+
const Char123LocaleChar125OrdersFindRoute =
|
|
153
|
+
Char123LocaleChar125OrdersFindRouteImport.update({
|
|
154
|
+
id: '/orders/find',
|
|
155
|
+
path: '/orders/find',
|
|
156
|
+
getParentRoute: () => Char123LocaleChar125Route,
|
|
157
|
+
} as any)
|
|
151
158
|
const Char123LocaleChar125PagesHandleRoute =
|
|
152
159
|
Char123LocaleChar125PagesHandleRouteImport.update({
|
|
153
160
|
id: '/pages/$handle',
|
|
@@ -206,6 +213,7 @@ export interface FileRoutesByFullPath {
|
|
|
206
213
|
'/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
|
|
207
214
|
'/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
|
|
208
215
|
'/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
|
|
216
|
+
'/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
|
|
209
217
|
'/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
|
|
210
218
|
'/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
|
|
211
219
|
'/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
|
|
@@ -233,6 +241,7 @@ export interface FileRoutesByTo {
|
|
|
233
241
|
'/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
|
|
234
242
|
'/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
|
|
235
243
|
'/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
|
|
244
|
+
'/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
|
|
236
245
|
'/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
|
|
237
246
|
'/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
|
|
238
247
|
'/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
|
|
@@ -262,6 +271,7 @@ export interface FileRoutesById {
|
|
|
262
271
|
'/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
|
|
263
272
|
'/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
|
|
264
273
|
'/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
|
|
274
|
+
'/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
|
|
265
275
|
'/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
|
|
266
276
|
'/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
|
|
267
277
|
'/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
|
|
@@ -292,6 +302,7 @@ export interface FileRouteTypes {
|
|
|
292
302
|
| '/{-$locale}/account/verify'
|
|
293
303
|
| '/{-$locale}/blogs/$blogHandle'
|
|
294
304
|
| '/{-$locale}/collections/$collectionHandle'
|
|
305
|
+
| '/{-$locale}/orders/find'
|
|
295
306
|
| '/{-$locale}/pages/$handle'
|
|
296
307
|
| '/{-$locale}/policies/$handle'
|
|
297
308
|
| '/{-$locale}/preview/section'
|
|
@@ -319,6 +330,7 @@ export interface FileRouteTypes {
|
|
|
319
330
|
| '/{-$locale}/account/verify'
|
|
320
331
|
| '/{-$locale}/blogs/$blogHandle'
|
|
321
332
|
| '/{-$locale}/collections/$collectionHandle'
|
|
333
|
+
| '/{-$locale}/orders/find'
|
|
322
334
|
| '/{-$locale}/pages/$handle'
|
|
323
335
|
| '/{-$locale}/policies/$handle'
|
|
324
336
|
| '/{-$locale}/preview/section'
|
|
@@ -347,6 +359,7 @@ export interface FileRouteTypes {
|
|
|
347
359
|
| '/{-$locale}/account/verify'
|
|
348
360
|
| '/{-$locale}/blogs/$blogHandle'
|
|
349
361
|
| '/{-$locale}/collections/$collectionHandle'
|
|
362
|
+
| '/{-$locale}/orders/find'
|
|
350
363
|
| '/{-$locale}/pages/$handle'
|
|
351
364
|
| '/{-$locale}/policies/$handle'
|
|
352
365
|
| '/{-$locale}/preview/section'
|
|
@@ -509,6 +522,13 @@ declare module '@tanstack/react-router' {
|
|
|
509
522
|
preLoaderRoute: typeof Char123LocaleChar125CollectionsCollectionHandleRouteImport
|
|
510
523
|
parentRoute: typeof Char123LocaleChar125Route
|
|
511
524
|
}
|
|
525
|
+
'/{-$locale}/orders/find': {
|
|
526
|
+
id: '/{-$locale}/orders/find'
|
|
527
|
+
path: '/orders/find'
|
|
528
|
+
fullPath: '/{-$locale}/orders/find'
|
|
529
|
+
preLoaderRoute: typeof Char123LocaleChar125OrdersFindRouteImport
|
|
530
|
+
parentRoute: typeof Char123LocaleChar125Route
|
|
531
|
+
}
|
|
512
532
|
'/{-$locale}/pages/$handle': {
|
|
513
533
|
id: '/{-$locale}/pages/$handle'
|
|
514
534
|
path: '/pages/$handle'
|
|
@@ -566,6 +586,7 @@ interface Char123LocaleChar125RouteChildren {
|
|
|
566
586
|
Char123LocaleChar125AccountVerifyRoute: typeof Char123LocaleChar125AccountVerifyRoute
|
|
567
587
|
Char123LocaleChar125BlogsBlogHandleRoute: typeof Char123LocaleChar125BlogsBlogHandleRoute
|
|
568
588
|
Char123LocaleChar125CollectionsCollectionHandleRoute: typeof Char123LocaleChar125CollectionsCollectionHandleRoute
|
|
589
|
+
Char123LocaleChar125OrdersFindRoute: typeof Char123LocaleChar125OrdersFindRoute
|
|
569
590
|
Char123LocaleChar125PagesHandleRoute: typeof Char123LocaleChar125PagesHandleRoute
|
|
570
591
|
Char123LocaleChar125PoliciesHandleRoute: typeof Char123LocaleChar125PoliciesHandleRoute
|
|
571
592
|
Char123LocaleChar125PreviewSectionRoute: typeof Char123LocaleChar125PreviewSectionRoute
|
|
@@ -592,6 +613,7 @@ const Char123LocaleChar125RouteChildren: Char123LocaleChar125RouteChildren = {
|
|
|
592
613
|
Char123LocaleChar125BlogsBlogHandleRoute,
|
|
593
614
|
Char123LocaleChar125CollectionsCollectionHandleRoute:
|
|
594
615
|
Char123LocaleChar125CollectionsCollectionHandleRoute,
|
|
616
|
+
Char123LocaleChar125OrdersFindRoute: Char123LocaleChar125OrdersFindRoute,
|
|
595
617
|
Char123LocaleChar125PagesHandleRoute: Char123LocaleChar125PagesHandleRoute,
|
|
596
618
|
Char123LocaleChar125PoliciesHandleRoute:
|
|
597
619
|
Char123LocaleChar125PoliciesHandleRoute,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
+
import { orderLookupRouteOptions } from "@shop-on/theme-routes";
|
|
3
|
+
import { routeAdapter } from "@/src/route-adapter";
|
|
4
|
+
|
|
5
|
+
// The address a merchant links for "Find an order": the account app holds the
|
|
6
|
+
// lookup, so this path on the storefront host only bounces there. Thrown from
|
|
7
|
+
// `beforeLoad`, like the account bounces, so the root loader never runs.
|
|
8
|
+
const { validateSearch, beforeLoad } = orderLookupRouteOptions(routeAdapter.account);
|
|
9
|
+
|
|
10
|
+
export const Route = createFileRoute("/{-$locale}/orders/find")({
|
|
11
|
+
validateSearch,
|
|
12
|
+
beforeLoad,
|
|
13
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "t:sections.custom_section",
|
|
3
|
+
"tag": "section",
|
|
4
|
+
"settings": [
|
|
5
|
+
{
|
|
6
|
+
"type": "select",
|
|
7
|
+
"id": "container",
|
|
8
|
+
"label": "t:settings.content_width",
|
|
9
|
+
"options": [
|
|
10
|
+
{ "value": "small", "label": "t:content_width_options.small" },
|
|
11
|
+
{ "value": "medium", "label": "t:content_width_options.medium" },
|
|
12
|
+
{ "value": "large", "label": "t:content_width_options.large" },
|
|
13
|
+
{ "value": "page", "label": "t:content_width_options.page" },
|
|
14
|
+
{ "value": "full", "label": "t:content_width_options.full" }
|
|
15
|
+
],
|
|
16
|
+
"default": "page"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"type": "range",
|
|
20
|
+
"id": "padding_top",
|
|
21
|
+
"label": "t:settings.padding_top",
|
|
22
|
+
"min": 0,
|
|
23
|
+
"max": 100,
|
|
24
|
+
"step": 4,
|
|
25
|
+
"unit": "px",
|
|
26
|
+
"default": 0
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"type": "range",
|
|
30
|
+
"id": "padding_bottom",
|
|
31
|
+
"label": "t:settings.padding_bottom",
|
|
32
|
+
"min": 0,
|
|
33
|
+
"max": 100,
|
|
34
|
+
"step": 4,
|
|
35
|
+
"unit": "px",
|
|
36
|
+
"default": 0
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BASE_SETTING_IDS } from "@shop-on/theme-contract/custom-section";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import schema from "./custom-section.json";
|
|
4
|
+
|
|
5
|
+
// A custom section's template reads the contract's base settings
|
|
6
|
+
// (`settings.container`, …) beside its own declared ones, whose ids may not
|
|
7
|
+
// reuse a base id. A setting here outside the contract would let a template
|
|
8
|
+
// read a value the contract doesn't know about. `color_scheme` is the one base
|
|
9
|
+
// id left out: the theme has no color schemes yet, so its picker would do
|
|
10
|
+
// nothing. Declare it when the schemes arrive.
|
|
11
|
+
it("declares the contract's base settings, but color_scheme", () => {
|
|
12
|
+
const ids = schema.settings.flatMap((s) => ("id" in s ? [s.id] : []));
|
|
13
|
+
expect(ids.toSorted()).toEqual(BASE_SETTING_IDS.filter((id) => id !== "color_scheme").toSorted());
|
|
14
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import { useTranslations } from "@shop-on/i18n";
|
|
3
|
+
import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
|
|
4
|
+
|
|
5
|
+
// `page` is the theme container and `full` is edge to edge; the rest cap the
|
|
6
|
+
// content's measure inside the container.
|
|
7
|
+
const WIDTHS: Record<string, string> = {
|
|
8
|
+
small: "44rem",
|
|
9
|
+
medium: "60rem",
|
|
10
|
+
large: "78rem",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// A section an AI assistant wrote: Liquid the custom-section pass
|
|
14
|
+
// (`renderCustomSections`, @shop-on/theme-loader/custom-sections, called from
|
|
15
|
+
// `loadTemplate` in src/server/settings.ts) validated and rendered on the
|
|
16
|
+
// server, arriving here as a finished HTML string on `customHtml`. The
|
|
17
|
+
// instance's `definition` (its template and declared settings) never reaches
|
|
18
|
+
// this component: the pass deletes it.
|
|
19
|
+
//
|
|
20
|
+
// Rendered through the shared `CustomSectionHtml`, never a raw
|
|
21
|
+
// `dangerouslySetInnerHTML` or a Custom HTML snippet that re-activates
|
|
22
|
+
// `<script>` tags: model-written markup must not run one. `CustomSectionHtml`
|
|
23
|
+
// also hands clicks on its internal links to the router.
|
|
24
|
+
export default function CustomSection({
|
|
25
|
+
sectionId,
|
|
26
|
+
customHtml = null,
|
|
27
|
+
customError = null,
|
|
28
|
+
container = "page",
|
|
29
|
+
padding_top = 0,
|
|
30
|
+
padding_bottom = 0,
|
|
31
|
+
}: {
|
|
32
|
+
sectionId?: string;
|
|
33
|
+
customHtml?: string | null;
|
|
34
|
+
customError?: string | null;
|
|
35
|
+
container?: string | null;
|
|
36
|
+
padding_top?: number | null;
|
|
37
|
+
padding_bottom?: number | null;
|
|
38
|
+
}) {
|
|
39
|
+
const t = useTranslations("custom_section");
|
|
40
|
+
|
|
41
|
+
// Nothing rendered, nothing shown. An error shows only in the editor: the
|
|
42
|
+
// pass writes `customError` only when the request carries an editor `sid`.
|
|
43
|
+
if (!customError && !customHtml?.trim()) return null;
|
|
44
|
+
|
|
45
|
+
const measure = WIDTHS[container ?? "page"];
|
|
46
|
+
const body = customError ? (
|
|
47
|
+
<p className="rounded-lg border border-border p-4 text-sm text-muted">
|
|
48
|
+
{t("error")}: {customError}
|
|
49
|
+
</p>
|
|
50
|
+
) : (
|
|
51
|
+
<CustomSectionHtml html={customHtml ?? ""} />
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<section
|
|
56
|
+
data-section-id={sectionId}
|
|
57
|
+
style={{ paddingTop: `${padding_top ?? 0}px`, paddingBottom: `${padding_bottom ?? 0}px` }}
|
|
58
|
+
>
|
|
59
|
+
<div className={container === "full" ? undefined : "mx-auto max-w-6xl px-6"}>
|
|
60
|
+
{measure ? (
|
|
61
|
+
<div
|
|
62
|
+
className="mx-auto w-full max-w-(--cs-w)"
|
|
63
|
+
style={{ "--cs-w": measure } as CSSProperties}
|
|
64
|
+
>
|
|
65
|
+
{body}
|
|
66
|
+
</div>
|
|
67
|
+
) : (
|
|
68
|
+
body
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
</section>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -21,7 +21,12 @@
|
|
|
21
21
|
"default": "t:text_defaults.hero_body"
|
|
22
22
|
},
|
|
23
23
|
{ "type": "text", "id": "cta_label", "label": "t:settings.cta_label" },
|
|
24
|
-
{
|
|
24
|
+
{
|
|
25
|
+
"type": "url",
|
|
26
|
+
"id": "cta_url",
|
|
27
|
+
"label": "t:settings.cta_url",
|
|
28
|
+
"visible_if": "{{ section.settings.cta_label != blank }}"
|
|
29
|
+
}
|
|
25
30
|
],
|
|
26
31
|
"presets": [{ "name": "t:sections.hero" }]
|
|
27
32
|
}
|
|
@@ -7,16 +7,24 @@
|
|
|
7
7
|
// settings as `productData`. Then add a variant picker + add-to-cart (cart
|
|
8
8
|
// mutations live in `@shop-on/theme-server/cart-mutations`).
|
|
9
9
|
import { formatMoney } from "@shop-on/theme-runtime/money";
|
|
10
|
+
import { hasCustomOutput } from "@shop-on/theme-react/custom-section-html";
|
|
10
11
|
import type { ProductData } from "@shop-on/theme-server/product";
|
|
12
|
+
import { BlockRenderer, type BlockInstance } from "@/src/components/template-renderer";
|
|
11
13
|
import { useProductViewed } from "@/src/lib/use-analytics";
|
|
12
14
|
|
|
13
15
|
export default function MainProduct({
|
|
14
16
|
sectionId,
|
|
15
17
|
productData,
|
|
18
|
+
blocks = [],
|
|
16
19
|
}: {
|
|
17
20
|
sectionId?: string;
|
|
18
21
|
productData?: ProductData | null;
|
|
22
|
+
blocks?: BlockInstance[];
|
|
19
23
|
}) {
|
|
24
|
+
// An AI-built block the custom-section pass rendered nothing for would still
|
|
25
|
+
// get a wrapper of its own, and the wrapper's margin would open a gap.
|
|
26
|
+
const shown = blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings));
|
|
27
|
+
|
|
20
28
|
// `product_viewed` — no-ops until the route patches in `productData`.
|
|
21
29
|
useProductViewed(productData?.id, productData?.handle);
|
|
22
30
|
|
|
@@ -47,6 +55,13 @@ export default function MainProduct({
|
|
|
47
55
|
<div className="h-4 w-5/6 rounded-sm bg-border" />
|
|
48
56
|
</div>
|
|
49
57
|
)}
|
|
58
|
+
{/* One wrapper per block, not one BlockRenderer over the list: its own
|
|
59
|
+
wrapper is `display: contents`, so it can't carry the spacing. */}
|
|
60
|
+
{shown.map((block, i) => (
|
|
61
|
+
<div key={block.id ?? i} className="mt-8">
|
|
62
|
+
<BlockRenderer blocks={[block]} />
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
50
65
|
</div>
|
|
51
66
|
</div>
|
|
52
67
|
</section>
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import { createServerFn } from "@tanstack/react-start";
|
|
23
23
|
import type { LoadedTemplate } from "@shop-on/theme-loader/types";
|
|
24
|
+
import { isValidLocale, localizedPath } from "@/src/lib/i18n";
|
|
24
25
|
|
|
25
26
|
/** Everything the loader needs about the request behind a template load. */
|
|
26
27
|
interface TemplateRequest {
|
|
@@ -37,16 +38,35 @@ async function loadTemplate(
|
|
|
37
38
|
templateId: string,
|
|
38
39
|
req: TemplateRequest = {},
|
|
39
40
|
): Promise<LoadedTemplate | null> {
|
|
40
|
-
const [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const [
|
|
42
|
+
{ loadTemplateForRequest, runEnrichment },
|
|
43
|
+
{ loaderConfig },
|
|
44
|
+
{ enrichAdapter },
|
|
45
|
+
{ renderCustomSections },
|
|
46
|
+
] = await Promise.all([
|
|
47
|
+
import("@shop-on/theme-loader"),
|
|
48
|
+
import("./template-loader"),
|
|
49
|
+
import("./enrich-adapter"),
|
|
50
|
+
import("@shop-on/theme-loader/custom-sections"),
|
|
51
|
+
]);
|
|
46
52
|
|
|
47
53
|
const template = await loadTemplateForRequest(loaderConfig, templateId, req.sid, req.locale);
|
|
48
54
|
if (!template) return null;
|
|
49
55
|
await runEnrichment(loaderConfig, template, enrichAdapter, req);
|
|
56
|
+
// AI-built sections and blocks (`custom-section`, `custom-block`). AFTER the
|
|
57
|
+
// enrichment, deliberately: its last phase re-scans every string setting, so
|
|
58
|
+
// rendered HTML must land after it. `link_url` hands `localizePath` a
|
|
59
|
+
// locale-free site path. Only a locale the shop serves may prefix it:
|
|
60
|
+
// `req.locale` is server-fn input, and a crafted one would otherwise turn a
|
|
61
|
+
// site path into another host's (`//evil.example/…`). Once a route loads its
|
|
62
|
+
// product or collection here, pass `product` / `getCollection` as well, and
|
|
63
|
+
// the template's `product` / `collection` drops fill in on that page.
|
|
64
|
+
const pathLocale = isValidLocale(req.locale) ? req.locale : undefined;
|
|
65
|
+
await renderCustomSections(loaderConfig, template, {
|
|
66
|
+
sid: req.sid,
|
|
67
|
+
locale: req.locale,
|
|
68
|
+
localizePath: (path) => localizedPath(path, pathLocale),
|
|
69
|
+
});
|
|
50
70
|
return template;
|
|
51
71
|
}
|
|
52
72
|
|