Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ All components follow the same structure:
- `blueprint`: Component schema with default values

2. **Hugo Template** (`.hugo.html`):
- Cannot use InitArgs partial (Bookshop live editing requirement)
- Cannot use the Args partial (Bookshop live editing requirement)
- Access arguments directly from dot notation (`.breadcrumb`, `.heading`, etc.)
- Call mod-blocks partials like `assets/hero.html` (now owned by mod-blocks)
- Call Hinode shared partials like `assets/card-group.html`, `assets/video.html` (still in Hinode)
Expand All @@ -95,14 +95,14 @@ All components follow the same structure:
- Page template: page/contact.html

**Hinode provides (accessed via module inheritance):**
- mod-utils utilities: GetPadding, GetBreakpoint, LogWarn, InitArgs, etc.
- mod-utils utilities: GetPadding, GetBreakpoint, LogWarn, Args, etc.
- Shared asset partials: card-group.html, video.html, table.html, timeline.html, live-image.html, section-title.html, etc.
- Bootstrap styling and theming system

**Dependency Flow:**
```
Hinode v2 (core theme)
├── mod-utils (GetPadding, LogWarn, InitArgs, etc.)
├── mod-utils (GetPadding, LogWarn, Args, etc.)
├── Shared partials (card-group, video, table, timeline, section-title)
└── Bootstrap theming

Expand Down Expand Up @@ -143,7 +143,7 @@ blueprint:

### 2. Hugo Partial Structures (`data/structures/*.yml`) — kebab-case

Structure files define the argument interface for **Hugo partials** (e.g., `assets/menu.html`, `assets/hero.html`). These are processed by `InitArgs` (mod-utils), which stores keys as-is and then camelizes any key containing `-`. **Always use kebab-case here** so that `$args.menuStyle`, `$args.linkType` etc. work correctly.
Structure files define the argument interface for **Hugo partials** (e.g., `assets/menu.html`, `assets/hero.html`). These are processed by `Args` (mod-utils v6), which returns a separated envelope with camelCase keys under `args`. **Always use kebab-case here** so that `$args.menuStyle`, `$args.linkType` etc. work correctly.

```yaml
# data/structures/menu.yml
Expand All @@ -153,7 +153,7 @@ arguments:
icon-style: # → $args.iconStyle
```

**Critical**: `InitArgs` does exact key matching against the structure. If the structure uses snake_case (`menu_style`) but the caller passes kebab-case (`"menu-style"`), `InitArgs` reports an unknown argument, sets `$error = true`, and breaks out of the range loop — potentially leaving required args (like `menu`) as nil, causing a runtime panic.
**Critical**: `Args` does exact key matching against the structure. If the structure uses snake_case (`menu_style`) but the caller passes kebab-case (`"menu-style"`), `Args` reports an unknown argument as an error — potentially leaving required args (like `menu`) as nil.

### 3. Hugo Template Dict Keys (`.hugo.html` → partials) — kebab-case

Expand All @@ -171,7 +171,7 @@ When `.hugo.html` components call Hugo partials, they pass a dict with kebab-cas
| Context | Key format | Example | Reason |
|---|---|---|---|
| `.bookshop.yml` blueprint | snake_case | `link_type` | CloudCannon CMS requirement |
| `data/structures/*.yml` | kebab-case | `link-type` | `InitArgs` camelizes `-` keys; `_` keys are NOT camelized |
| `data/structures/*.yml` | kebab-case | `link-type` | `Args` camelizes both `-` and `_` keys to camelCase |
| Dict key passed to Hugo partial | kebab-case | `"link-type"` | Must match structure definition exactly |
| Value read from bookshop context | `(or .snake (index . "kebab"))` | `(or .link_type (index . "link-type"))` | Backwards compatibility |

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Add mod-blocks to your Hinode site's `hugo.toml`:

```toml
[[module.imports]]
path = "github.com/gethinode/mod-blocks"
path = "github.com/gethinode/mod-blocks/v2"
```

Then run:
Expand All @@ -67,7 +67,7 @@ hugo mod get -u

- **Hugo Extended** v0.147.6 or higher
- **Hinode v2** for:
- mod-utils utilities (GetPadding, GetBreakpoint, LogWarn, InitArgs, etc.)
- mod-utils utilities (GetPadding, GetBreakpoint, LogWarn, Args, etc.)
- Shared asset partials (card-group, video, table, timeline, etc.)

## Architecture
Expand Down Expand Up @@ -96,7 +96,7 @@ Located in `component-library/components/`:
### Dependencies on Hinode

mod-blocks depends on Hinode v2 for:
- **mod-utils utilities**: GetPadding, GetBreakpoint, LogWarn, InitArgs, etc.
- **mod-utils utilities**: GetPadding, GetBreakpoint, LogWarn, Args, etc.
- **Shared asset partials**: card-group, video, table, timeline, live-image, section-title, etc.
- **Bootstrap styling** and theming system

Expand Down
12 changes: 6 additions & 6 deletions component-library/components/about/about.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "about" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "about" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/about/about.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
12 changes: 6 additions & 6 deletions component-library/components/approach/approach.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}
Expand All @@ -17,16 +17,16 @@
{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "approach" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "approach" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/approach/approach.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
12 changes: 6 additions & 6 deletions component-library/components/articles/articles.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "articles" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "articles" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/articles/articles.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
12 changes: 6 additions & 6 deletions component-library/components/cards/cards.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "cards" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "cards" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/cards/cards.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
18 changes: 9 additions & 9 deletions component-library/components/contact-form/contact-form.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}
Expand All @@ -13,24 +13,24 @@
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $bookshop := "contact-form" }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" $bookshop "args" .)}}
{{ $err := $args.err }}
{{ $msg := ($args.errmsg | append $args.warnmsg) }}
{{ $result := partial "utilities/Args.html" (dict "bookshop" $bookshop "args" . "strict" false) }}
{{ $err := $result.err }}
{{ $msg := ($result.errmsg | append $result.warnmsg) }}

{{ if not $err }}
{{ if not $args.hook }}
{{ if not $result.args.hook }}
{{ $msg = $msg | append (printf "[%s] requires argument 'hook'" $bookshop) }}
{{ $err = true }}
{{ else if (not (templates.Exists (printf "_partials/%s" $args.hook))) }}
{{ $hook := cond (path.Ext $args.hook) $args.hook (printf "%s.html" $args.hook) }}
{{ else if (not (templates.Exists (printf "_partials/%s" $result.args.hook))) }}
{{ $hook := cond (path.Ext $result.args.hook) $result.args.hook (printf "%s.html" $result.args.hook) }}
{{ if (not (templates.Exists (printf "_partials/%s" $hook))) }}
{{ $msg = $msg | append (printf "[%s] cannot find render hook '%s'" $bookshop $args.hook) }}
{{ $msg = $msg | append (printf "[%s] cannot find render hook '%s'" $bookshop $result.args.hook) }}
{{ $err = true }}
{{ end }}
{{ end }}
{{ end }}

{{ if or $err $args.warnmsg }}
{{ if or $err $result.warnmsg }}
{{ partial (cond $err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/contact-form/contact-form.hugo.html"
"warnid" "warn-invalid-arguments"
Expand Down
12 changes: 6 additions & 6 deletions component-library/components/cta/cta.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "cta" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "cta" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/cta/cta.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
14 changes: 7 additions & 7 deletions component-library/components/faq/faq.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "faq" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "faq" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/faq/faq.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down Expand Up @@ -52,7 +52,7 @@
{{ if $raw }}
{{ partial "utilities/section.html" (dict
"_ordinal" ._ordinal
"component-name" "faw"
"component-name" "faq"
"id" .id
"raw" $raw
"background" .background
Expand Down
12 changes: 6 additions & 6 deletions component-library/components/featured/featured.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "featured" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "featured" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/featured/featured.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
12 changes: 6 additions & 6 deletions component-library/components/heading/heading.hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
Visit gethinode.com/license for more details.

Note: To support live editing, bookshop components should use a clear path to the provided arguments.
Therefore, we cannot use the InitArgs partial at this point, and we need to access each argument
Therefore, we cannot use the validated arguments (Args partial) at this point, and we need to access each argument
directly. See the docs for more background:
https://github.com/CloudCannon/bookshop/blob/main/guides/hugo.adoc#passing-data-to-bookshop-components
*/}}

{{/* Validate arguments */}}
{{ $error := false }}
{{ if not site.Params.env_bookshop_live }}
{{ $args := partial "utilities/InitArgs.html" (dict "bookshop" "heading" "args" .) }}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
{{ $result := partial "utilities/Args.html" (dict "bookshop" "heading" "args" . "strict" false) }}
{{ if or $result.err $result.warnmsg }}
{{ partial (cond $result.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "component-library/components/heading/heading.hugo.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"details" ($result.errmsg | append $result.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ $error = $result.err }}
{{- end -}}
{{- end -}}

Expand Down
Loading
Loading