mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
2c0b48370b
* feat(gen-docs): add documentation generation package with SassDoc and TypeDoc support Add new `@hugo-fixit/gen-docs` package that parses Hugo config (hugo.toml) and generates documentation. Includes SassDoc annotations for SCSS variables and mixins, TypeDoc config for TypeScript source docs, and a `.sassdocrc` configuration file. * docs(readme): add browsers support section * feat(gen-docs): add Hugo partials docs generation and fix config empty sections - Add partial-parser.ts: parses Hugo partial comment blocks (@param/@return/@example) - Add partials.ts renderer: generates grouped Markdown with param tables - Add `partials` subcommand with -t/-o options for template injection - Fix config-parser: empty TOML sections (library.js/library.css) now retain descriptions - Fix config-parser: correctly distinguish section-level vs key-level comments - Update README with partials subcommand documentation
76 lines
3.2 KiB
HTML
76 lines
3.2 KiB
HTML
{{- /*
|
|
Get the cover image for a page.
|
|
|
|
Resolves the cover image by checking front matter params first, then page resources.
|
|
Supports remote URLs, inline data URIs, and local page/global resources.
|
|
|
|
Resolution order:
|
|
1. Front matter: featured_image_preview (if Preview=true) or featured_image
|
|
2. Page resources: "featured-image-preview" (if Preview=true), then "featured-image"
|
|
3. Global resources: by the front matter value as a path
|
|
|
|
@param {Map} . - Configuration dict
|
|
- Page: {Page} the page context (required)
|
|
- Preview: {Boolean} if true, prefer featured_image_preview over featured_image (default: false)
|
|
- Build: {Boolean} if true, resolve resource objects and permalinks; if false, only check existence (default: false)
|
|
@return {Map} dict with:
|
|
- Source: {String} the raw front matter value (may be empty)
|
|
- Matches: {Slice} matched resource names (e.g., ["featured-image-preview"])
|
|
- Resource: {Object} the resolved Hugo resource object (empty dict if Build=false or not found)
|
|
- URL: {String} the resolved permalink, or raw front matter value if resource not found
|
|
|
|
@example
|
|
{{- $cover := dict "Page" . | partial "function/get-cover.html" -}}
|
|
{{- with $cover.URL -}}<img src="{{ . }}">{{- end -}}
|
|
|
|
@example
|
|
{{- $cover := dict "Page" . "Preview" true | partial "function/get-cover.html" -}}
|
|
{{- dict "Src" $cover.URL "Resources" .Resources "Matches" $cover.Matches | partial "plugin/image.html" -}}
|
|
*/ -}}
|
|
{{- $page := .Page -}}
|
|
{{- $preview := .Preview | default false -}}
|
|
{{- $build := .Build | default false -}}
|
|
|
|
{{- /* Resolve front matter value */ -}}
|
|
{{- $image := "" -}}
|
|
{{- if $preview -}}
|
|
{{- $image = $page.Params.featured_image_preview | default $page.Params.featured_image -}}
|
|
{{- else -}}
|
|
{{- $image = $page.Params.featured_image -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Skip resource resolution for remote URLs and inline data URIs */ -}}
|
|
{{- $isInline := strings.HasPrefix $image "data:image" -}}
|
|
{{- $isRemote := urls.Parse $image | partial "function/is-url-remote.html" -}}
|
|
{{- $matches := slice -}}
|
|
{{- $resource := dict -}}
|
|
{{- $url := $image -}}
|
|
|
|
{{- if not $isRemote | and (not $isInline) -}}
|
|
{{- /* Check which named resources exist in the page bundle */ -}}
|
|
{{- if $preview -}}
|
|
{{- if $page.Resources.GetMatch "featured-image-preview" -}}
|
|
{{- $matches = $matches | append "featured-image-preview" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if $page.Resources.GetMatch "featured-image" -}}
|
|
{{- $matches = $matches | append "featured-image" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* When Build=true, resolve the actual resource object and its permalink */ -}}
|
|
{{- if $build -}}
|
|
{{- /* Try matched resource names first (priority order) */ -}}
|
|
{{- range $matches -}}
|
|
{{- $resource = $page.Resources.GetMatch . -}}
|
|
{{- if $resource -}}
|
|
{{- break -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- /* Fallback: try page resources by path, then global assets */ -}}
|
|
{{- $resource = $resource | default ($page.Resources.Get $image) | default (resources.Get $image) -}}
|
|
{{- $url = $resource.RelPermalink | default $image -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- return (dict "Source" $image "Matches" $matches "Resource" $resource "URL" $url) -}}
|