mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
658f03d1e5
* refactor(params)!: snake_case config + eliminate params.page + use .Param
BREAKING CHANGE: All params keys renamed from camelCase to snake_case,
[params.page] section eliminated (moved to [params] level), and users
must update their hugo.toml and front matter accordingly.
Key changes:
- All camelCase config keys → snake_case (e.g., defaultTheme → default_theme)
- [params.page] flat keys and sub-sections moved to [params] level
- Removed function/params.html (manual merge), replaced with Hugo .Param
- New function/param.html partial for page-level section params with
shorthand boolean support and site defaults merging
- New function/camel-case.html for string conversion
- snake2camel.html renamed to camel-case-keys.html
- New function/get-cover.html for cover image resolution
- Deprecation warnings in detection-deprecated.html for old config keys
- Front matter only params (subtitle, featured_image, password, repost,
weight, message) use .Params.xxx instead of .Param
- Page-level sections use param.html partial
- Simplified patch.html (siteTime only) and init/index.html
Refs: camel-case-keys.html#29 (planned v1.0 breaking change)
* refactor(params)!: move params.link to page-level, simplify link guard
- Move [params.link] and [params.link.guard] to page-level section
- link.html: .Page optional, use param.html when available for
page-level override, fall back to site config without .Page
- Remove $guardConfig variable, use $config.guard directly
- Remove unnecessary .Page from callers that don't need page override
- friends.html: use param.html for link guard instead of link_guard
* refactor(params)!: move image/codeblock/json_viewer/filetree to page-level
- Move [params.image], [params.codeblock], [params.json_viewer],
[params.filetree] to page-level sub-sections
- Templates use param.html for merged config (page override + site defaults)
- image.html: .Page optional, falls back to site config without .Page
- Add v1- prefix to all deprecation warnidf IDs
- Fix camelCase key access in image.html (blackList, cacheRemote)
- Fix Hugo-lowered camelCase keys in code-block-wrapper.html
- Add deprecation warnings for codeblock camelCase Markdown attributes
- Add deprecation warnings for file-tree camelCase Markdown attributes
- Update render-codeblock-toggle.html for snake_case attribute names
* style: standardize @param comment style across all HTML templates
- PascalCase types: {string} → {String}, {boolean} → {Boolean},
{int} → {Int}, {map} → {Map}, {array} → {Array}
- Add missing ` - ` separator between param name and description
- Remove extra alignment spaces between type and param name
* refactor(params)!: move params.mermaid to page-level, extract gen/ templates
- Move [params.mermaid] to page-level sub-sections
- Mermaid config injected into window.config (per-page override support)
- mermaid.ts reads config from window.config.mermaid instead of parameter
- Create _partials/gen/ directory for JS content generators
- Move mermaid-bootstrap.html from plugin/ to gen/
- Extract window.config JS generation into gen/config.html
- mermaid.html uses param.html for wrapper config
* refactor(params)!: consolidate link_to_* into params.post_link section
- Move link_to_markdown/source/edit/report/vscode into [params.post_link]
- Rename keys: markdown, source, edit, report (bool), editor (string)
- editor defaults to "vscode", supports "trae" etc. via protocol template
- footer.html uses .Param "post_link" for all link toggles
- Remove link_to_* from deprecated keys list
* fix: add fallback for deprecated camelCase attributes and expand deprecation warnings
- render-codeblock-file-tree.html: folderSlash attribute fallback
- render-codeblock-toggle.html: lineNosToggler/lineWrapToggler fallback + warnings
- code-block-wrapper.html: maxShownLines/wrapperClass fallback
- detection-deprecated.html: add nested key warnings for 13 sections
(header, breadcrumb, navigation, watermark, busuanzi, image, mermaid,
codeblock, filetree, math.katex, math.mathjax.options, post_summary, footer)
- detection-deprecated.html: add link_guard front matter deprecation warning
* fix(mermaid): fix rendering in hidden tab panels and neutral layer scheduling
- isRenderContextActive: check tab-panel visibility via getBoundingClientRect
instead of panel.hidden (tab-container uses slot-based hiding, not hidden attr)
- bindTabContainerChanged: render neutral layers when switching tabs so
print/fallback scenarios work correctly
169 lines
11 KiB
HTML
169 lines
11 KiB
HTML
{{- /*
|
|
Link rendering partial for regular and card-style links.
|
|
- Auto-detects external links and applies target/rel policies.
|
|
- Supports optional icon, download hint, and external icon display.
|
|
- Supports card mode with URL meta and favicon fallback.
|
|
@param {String} .Destination - Target URL
|
|
@param {String} [.Content] - Link label HTML
|
|
@param {String} [.Title] - Title attribute
|
|
@param {String} [.Class] - Custom CSS classes
|
|
@param {String} [.Rel] - Rel attribute value
|
|
@param {Boolean} [.Newtab] - Force external behavior
|
|
@param {Boolean} [.Noreferrer] - Whether to include noreferrer (default: true)
|
|
@param {Boolean} [.ExternalIcon] - Whether to show external-link icon
|
|
@param {Object} [.Icon] - Icon params for plugin/icon.html
|
|
@param {Boolean} [.Card] - Whether to render card link layout
|
|
@param {String} [.CardIcon] - Card icon URL or icon class
|
|
@param {String} [.Download] - Download attribute value
|
|
@param {Boolean} [.IsGuarded] - Explicitly enable or disable link guard
|
|
@param {Object} [.Page] - Page context for page-level link config override
|
|
*/ -}}
|
|
|
|
{{- /* Regular link rendering */ -}}
|
|
{{- define "render-link-regular" -}}
|
|
{{- $ctx := .ctx -}}
|
|
{{- $config := .config -}}
|
|
{{- $isExternal := .isExternal -}}
|
|
{{- $externalIcon := $ctx.ExternalIcon | default $config.externalIcon -}}
|
|
{{- with $ctx.Icon -}}
|
|
{{- partial "plugin/icon.html" . }}
|
|
{{ end -}}
|
|
{{- with $ctx.Content -}}
|
|
{{- . | safeHTML -}}
|
|
{{- end -}}
|
|
{{- if
|
|
$externalIcon
|
|
| and $isExternal
|
|
| and (not (hasPrefix $ctx.Content `<img`))
|
|
| and (not (hasPrefix $ctx.Content `<svg`))
|
|
| and (not (strings.HasSuffix $ctx.Content `</i>`))
|
|
| and (not (strings.HasSuffix $ctx.Content `):`))
|
|
-}}
|
|
{{- if $ctx.Download -}}
|
|
{{- dict "Class" "fa-solid fa-cloud-download-alt ms-1 text-secondary" | partial "plugin/icon.html" -}}
|
|
{{- else -}}
|
|
{{- dict "Class" "fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" | partial "plugin/icon.html" -}}
|
|
{{- end -}}
|
|
{{- else if $ctx.Download }}
|
|
{{- dict "Class" "fa-solid fa-download ms-1 text-secondary" | partial "plugin/icon.html" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Card link rendering */ -}}
|
|
{{- define "render-link-card" -}}
|
|
{{- $ctx := .ctx -}}
|
|
{{- $url := .url -}}
|
|
{{- $cardIcon := $ctx.CardIcon -}}
|
|
{{- with dict "Path" $cardIcon | partial "function/resource.html" -}}
|
|
{{- $cardIcon = .RelPermalink -}}
|
|
{{- end -}}
|
|
{{- if (not $cardIcon) | and $url.Host -}}
|
|
{{- with partial "function/get-remote-image.html" (dict "Src" (add "https://api.lruihao.cn/google/s2/favicons?sz=64&domain=" $url.Host)) -}}
|
|
{{- $cardIcon = .RelPermalink -}}
|
|
{{- else with partial "function/get-remote-image.html" (dict "Src" (add "https://favicon.im/" $url.Host)) -}}
|
|
{{- $cardIcon = .RelPermalink -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
<span class="cl-backdrop"></span>
|
|
<span class="cl-content">
|
|
<span class="cl-text">
|
|
<span class="cl-title">
|
|
{{- with $ctx.Icon -}}
|
|
{{- partial "plugin/icon.html" . }}
|
|
{{ end -}}
|
|
{{- with $ctx.Content -}}
|
|
{{- . | safeHTML -}}
|
|
{{- end -}}
|
|
</span>
|
|
<span class="cl-meta">
|
|
<svg class="cl-icon-link" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M574 665.4c-3.1-3.1-8.2-3.1-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8c-3.1-3.1-8.2-3.1-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zM832.6 191.4c-84.6-84.6-221.5-84.6-306 0L410.3 307.6c-3.1 3.1-3.1 8.2 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6c-3.1 3.1-3.1 8.2 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1z" fill="#a9a9b3"></path><path d="M610.1 372.3c-3.1-3.1-8.2-3.1-11.3 0L372.3 598.7c-3.1 3.1-3.1 8.2 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z" fill="#a9a9b3"></path></svg>
|
|
<span class="cl-url">
|
|
{{- $url.String | safeURL | strings.TrimPrefix (add $url.Scheme "://") -}}
|
|
</span>
|
|
</span>
|
|
</span>
|
|
{{- if $ctx.Download -}}
|
|
{{- /* @unocss-skip-start */ -}}
|
|
<svg class="cl-shortcut-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="64" height="64"><path d="M824.32 473.6c-15.36-2.56-25.6-15.36-25.6-30.72 0-112.64-71.68-217.6-179.2-250.88-148.48-46.08-289.28 38.4-332.8 166.4-2.56 10.24-12.8 17.92-23.04 20.48C143.36 401.92 51.2 509.44 51.2 637.44v2.56c0 115.2 97.28 204.8 209.92 204.8h524.8c102.4-2.56 184.32-84.48 184.32-186.88 2.56-89.6-61.44-163.84-145.92-184.32z m-273.92 225.28c-12.8 12.8-30.72 15.36-46.08 10.24H501.76c-5.12-2.56-10.24-5.12-15.36-10.24L366.08 578.56c-15.36-15.36-15.36-43.52 0-58.88 15.36-15.36 43.52-15.36 58.88 0l51.2 51.2V352.4608c0-23.04 17.92-40.96 40.96-40.96 23.04 0 40.96 17.92 40.96 40.96v218.4192l51.2-51.2c17.92-17.92 43.52-17.92 61.44 0 17.92 15.36 17.92 40.96 0 58.88l-120.32 120.32z" fill="#4FC089"></path></svg>
|
|
{{- /* @unocss-skip-end */ -}}
|
|
{{- else -}}
|
|
{{- with $cardIcon -}}
|
|
{{- if (strings.HasPrefix . "fa") -}}
|
|
<i class="{{ . }} cl-shortcut-icon"></i>
|
|
{{- else -}}
|
|
<img src="{{ . }}" alt="card image" class="cl-shortcut-image">
|
|
{{- end -}}
|
|
{{- else -}}
|
|
<svg class="cl-shortcut-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="64" height="64"><path d="M960 512c0 249.408-203.2 448-448 448-244.778667 0-448-198.592-448-448S262.592 64 512 64s448 198.592 448 448" fill="#2196F3"></path><path d="M507.52 718.08c0-8.96-4.48-13.44-13.44-17.92-26.88-8.96-53.76-8.96-76.16-31.381333-4.48-8.96-4.48-17.92-8.96-26.88-8.96-8.96-31.36-13.44-44.8-17.92h-89.6c-13.44-4.48-22.4-22.4-31.36-35.84 0-4.48 0-13.461333-8.96-13.461334-8.96-4.458667-17.92 4.501333-26.88 0-4.48-4.458667-4.48-8.96-4.48-13.418666 0-13.461333 8.96-26.901333 17.92-35.861334 13.44-8.96 26.88 4.48 40.32 4.48 4.48 0 4.48 0 8.96 4.48 13.44 4.48 17.92 22.4 17.92 35.861334v8.96c0 4.48 4.48 4.48 8.96 4.48 4.48-22.4 4.48-44.821333 8.96-67.2 0-26.88 26.88-53.781333 49.28-62.72 8.96-4.458667 13.44 4.501333 22.4 0 26.88-8.96 94.08-35.84 80.64-71.658667-8.96-31.381333-35.84-62.698667-71.68-58.24-8.96 4.501333-13.44 8.96-22.4 13.461333-13.44 8.96-40.32 35.84-53.76 35.84-22.4-4.48-22.4-35.84-17.92-49.301333 4.48-17.92 44.8-76.138667 71.68-67.178667l17.92 17.92c8.96 4.48 22.4 4.48 35.84 4.48 4.48 0 8.96 0 13.44-4.48 4.48-4.48 4.48-4.48 4.48-8.96 0-13.44-13.44-26.901333-22.4-35.861333s-22.4-17.92-35.84-22.378667c-44.8-13.461333-116.48 4.458667-152.32 35.84-35.84 31.36-62.72 85.12-80.64 129.92-8.96 26.88-17.92 62.698667-22.4 94.08-4.48 22.4-8.96 40.32 4.48 62.698667 13.44 26.88 40.32 53.781333 67.2 71.68 17.92 13.44 53.76 13.44 71.68 35.84 13.44 17.941333 8.96 40.32 8.96 62.72 0 26.88 17.92 49.28 26.88 71.658667 4.48 13.461333 8.96 31.381333 13.44 44.821333 0 4.48 4.48 31.36 4.48 35.84 26.88 13.44 49.28 26.901333 80.64 35.861333 4.48 0 22.4-26.901333 22.4-31.381333 13.44-13.44 22.4-31.36 35.84-40.32 8.96-4.48 17.92-8.96 26.88-17.941333 8.96-8.96 13.44-26.88 17.92-40.32 4.48-8.938667 8.96-26.858667 4.48-40.298667M516.48 305.92c4.48 0 8.96-4.48 17.92-8.96 13.44-8.96 26.901333-22.4 40.32-31.36 13.461333-8.96 26.901333-22.4 35.861333-31.36 13.44-8.96 22.4-26.88 26.88-40.341333 4.48-8.96 17.941333-26.88 13.44-40.32-4.48-8.96-26.88-13.44-35.84-17.92C579.2 126.698667 547.84 122.24 512 122.24c-13.44 0-31.36 4.458667-35.84 17.92-4.48 22.4 13.44 17.92 31.36 22.4 0 0 4.48 35.84 4.48 40.32 4.48 22.421333-8.96 35.84-8.96 58.24 0 13.44 0 35.84 8.96 44.8h4.48zM892.8 619.52c4.501333-8.96 4.501333-22.4 8.96-31.36 4.501333-22.421333 4.501333-44.8 4.501333-67.2 0-44.8-4.501333-89.578667-17.92-129.92-8.96-13.44-13.461333-26.88-17.941333-40.341333-8.96-22.378667-22.4-44.8-40.32-62.698667-17.92-22.4-40.341333-85.12-80.64-67.2-13.44 4.501333-22.4 22.421333-31.36 31.381333l-26.88 40.32c-4.501333 4.48-8.96 13.44-4.501333 17.92 0 4.48 4.501333 4.48 8.96 4.48 8.96 4.501333 13.461333 4.501333 22.421333 8.96 4.48 0 8.96 4.501333 4.48 8.96 0 0 0 4.501333-4.48 4.501334-22.421333 22.4-44.8 40.32-67.2 62.698666-4.48 4.48-8.96 13.44-8.96 17.92s4.48 4.48 4.48 8.96c0 4.501333-4.48 4.501333-8.96 8.96-8.96 4.501333-17.92 8.96-22.4 13.461334-4.48 8.96 0 22.4-4.48 31.36-4.48 22.4-17.941333 40.32-26.901333 62.72-8.96 13.418667-13.418667 26.88-22.378667 40.32 0 17.92-4.501333 31.36 4.458667 44.8 22.421333 31.36 62.72 13.44 94.08 26.901333 8.96 4.458667 17.92 4.458667 22.421333 13.418667 13.418667 13.461333 13.418667 35.861333 17.92 49.301333 4.458667 17.92 8.96 35.84 17.92 53.76 4.48 22.421333 13.44 44.821333 17.92 62.72 40.341333-31.36 76.16-67.178667 103.04-112 26.88-31.424 40.341333-67.242667 53.76-103.104" fill="#CDDC39"></path></svg>
|
|
{{- end -}}
|
|
{{- end -}}
|
|
</span>
|
|
{{- end -}}
|
|
|
|
{{- $blockSchemes := slice "javascript" "mailto" "tel" "file" "data" "vscode" "trae" -}}
|
|
{{- $config := partial "function/camel-case-keys.html" site.Params.link -}}
|
|
{{- with .Page -}}
|
|
{{- $config = dict "Page" . "Key" "link" "ToCamel" true | partial "function/param.html" -}}
|
|
{{- end -}}
|
|
{{- $rel := .Rel | default "" -}}
|
|
{{- $isExternal := false -}}
|
|
{{- $noreferrer := true -}}
|
|
{{- if eq .Noreferrer false -}}
|
|
{{- $noreferrer = false -}}
|
|
{{- end -}}
|
|
{{- $url := urls.Parse .Destination -}}
|
|
{{- if $url.IsAbs | and (not (in $blockSchemes $url.Scheme)) -}}
|
|
{{- $isExternal = not (strings.HasPrefix .Destination site.BaseURL) -}}
|
|
{{- end -}}
|
|
{{- if $isExternal -}}
|
|
{{- $rel = add $rel " external nofollow" -}}
|
|
{{- if $noreferrer -}}
|
|
{{- $rel = add $rel " noopener noreferrer" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- $class := .Class | default "" -}}
|
|
{{- if eq .Card true -}}
|
|
{{- $class = trim (printf "%v %v" "card-link" $class) " " -}}
|
|
{{- end -}}
|
|
|
|
{{- /* External link guard */ -}}
|
|
{{- $isGuarded := false -}}
|
|
{{- if
|
|
$config.guard.enable
|
|
| and $isExternal
|
|
| and (not (in $config.guard.allowDomains $url.Host))
|
|
-}}
|
|
{{- $isGuarded = .IsGuarded | default true -}}
|
|
{{- end -}}
|
|
|
|
{{- $destination := cond $isGuarded (add (relLangURL "link") "?target=" (urlquery .Destination)) .Destination -}}
|
|
{{- $attrs := printf `href="%s"` ($destination | safeURL) -}}
|
|
{{- with .Title -}}
|
|
{{- $attrs = printf ` title="%s"` . | add $attrs -}}
|
|
{{- end -}}
|
|
{{- if $isExternal | or .Newtab -}}
|
|
{{- $attrs = add $attrs ` target="_blank"` -}}
|
|
{{- end -}}
|
|
{{- with $rel -}}
|
|
{{- $attrs = printf ` rel="%s"` (trim . " ") | add $attrs -}}
|
|
{{- end -}}
|
|
{{- with $class -}}
|
|
{{- $attrs = printf ` class="%s"` . | add $attrs -}}
|
|
{{- end -}}
|
|
{{- with .Download -}}
|
|
{{- $attrs = printf ` download="%s"` . | add $attrs -}}
|
|
{{- end -}}
|
|
{{- if $isGuarded | and (eq $config.guard.mode "modal") -}}
|
|
{{- $attrs = add $attrs ` data-guard="modal"` -}}
|
|
{{- end -}}
|
|
|
|
<a {{ $attrs | safeHTMLAttr }}>
|
|
{{- if eq .Card true -}}
|
|
{{- template "render-link-card" (dict "ctx" . "url" $url) -}}
|
|
{{- else -}}
|
|
{{- template "render-link-regular" (dict "ctx" . "config" $config "isExternal" $isExternal) -}}
|
|
{{- end -}}
|
|
</a>
|
|
{{- /* EOF */ -}}
|