Skip to content

Commit 36d37b3

Browse files
Amey-Thakurmsatmod
andcommitted
Amey's Arc
Co-authored-by: Mega Satish <mega.modha@gmail.com>
1 parent 0371293 commit 36d37b3

2 files changed

Lines changed: 70 additions & 25 deletions

File tree

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
1-
{{- $u := urls.Parse .Destination -}}
1+
<!-- ==============================================================================
2+
- File: render-image.html (Markdown Image Render Hook)
3+
- Author: Amey Thakur
4+
- Profile: https://github.com/Amey-Thakur
5+
- Repository: https://github.com/Amey-Thakur/Amey-Thakur.github.io
6+
- Release Date: December 16, 2025
7+
- License: MIT License
8+
- ==============================================================================
9+
-
10+
- DESCRIPTION:
11+
- This render hook intercepts the standard Markdown image syntax to provide
12+
- enhanced architectural control over visual assets. It facilitates
13+
- resource-aware path resolution and lazy-loading performance.
14+
-
15+
- HOW IT WORKS:
16+
- The script parses the image destination URL to distinguish between absolute
17+
- and relative paths. It utilizes Hugo's resource management to resolve local
18+
- assets from page bundles or the global assets directory, preserving query
19+
- parameters and fragments. It eventually renders a semantic <img> tag with
20+
- optimized attributes.
21+
-
22+
- TECH STACK:
23+
- - Hugo Goldmark Render Hooks
24+
- - URL Parsing & Resource Resolution
25+
- - HTML5 Optimization (Lazy-loading)
26+
-
27+
- ============================================================================== -->
28+
29+
{{- /* Path Orchestration: Resolving the image source across local and global scopes. */ -}}
30+
{{- $dest := .Destination -}}
31+
{{- $u := urls.Parse $dest -}}
232
{{- $src := $u.String -}}
33+
34+
{{- /* Relational Resolution: Handling non-absolute paths via Hugo resource pipeline. */ -}}
335
{{- if not $u.IsAbs -}}
4-
{{- $path := strings.TrimPrefix "./" $u.Path }}
5-
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
6-
{{- $src = .RelPermalink -}}
7-
{{- with $u.RawQuery -}}
8-
{{- $src = printf "%s?%s" $src . -}}
9-
{{- end -}}
10-
{{- with $u.Fragment -}}
11-
{{- $src = printf "%s#%s" $src . -}}
12-
{{- end -}}
13-
{{- end -}}
36+
{{- $path := strings.TrimPrefix "./" $u.Path }}
37+
{{- /*
38+
Resolution Logic: We prioritize page-specific resources before checking
39+
the global asset directory. Note: Using .Page instead of .PageInner.
40+
*/ -}}
41+
{{- with or (.Page.Resources.Get $path) (resources.Get $path) -}}
42+
{{- $src = .RelPermalink -}}
43+
{{- with $u.RawQuery -}}
44+
{{- $src = printf "%s?%s" $src . -}}
1445
{{- end -}}
15-
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape) "loading" "lazy") -}}
16-
<img
17-
{{- range $k, $v := $attributes -}}
18-
{{- if $v -}}
19-
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
20-
{{- end -}}
21-
{{- end -}}>
22-
{{- /**/ -}}
23-
46+
{{- with $u.Fragment -}}
47+
{{- $src = printf "%s#%s" $src . -}}
48+
{{- end -}}
49+
{{- end -}}
50+
{{- end -}}
51+
52+
{{- /* Attribute Synthesis: Merging markdown parameters with architectural defaults. */ -}}
53+
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape) "loading"
54+
"lazy") -}}
55+
<img {{- range $k, $v :=$attributes -}} {{- if $v -}} {{- printf " %s=%q" $k $v | safeHTMLAttr -}} {{- end -}} {{- end
56+
-}}>
57+
{{- /**/ -}}

Source Code/layouts/shortcodes/Academic_Figure.html

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
- The component parses input parameters (src, caption, attr) to architect
1717
- a responsive media block. It utilizes conditional logic for spatial
1818
- alignment, lazy-loading for performance, and markdown processing for
19-
- rich-text captions.
19+
- rich-text captions. It attempts to resolve local resources via the
20+
- Hugo Resource API for correct URL generation.
2021
-
2122
- TECH STACK:
2223
- - Hugo Shortcode API
@@ -25,6 +26,16 @@
2526
-
2627
- ============================================================================== -->
2728

29+
{{- /* Resource Resolution: Identifying and resolving the source artifact. */ -}}
30+
{{- $src := .Get "src" -}}
31+
{{- $u := urls.Parse $src -}}
32+
{{- if not $u.IsAbs -}}
33+
{{- $path := strings.TrimPrefix "./" $u.Path -}}
34+
{{- with or (.Page.Resources.Get $path) (resources.Get $path) -}}
35+
{{- $src = .RelPermalink -}}
36+
{{- end -}}
37+
{{- end -}}
38+
2839
{{- /* Spatial Architecture: Defining the container grid and alignment modality. */ -}}
2940
<figure{{ if or (.Get "class" ) (eq (.Get "align" ) "center" ) }} class="
3041
{{- if eq (.Get " align") "center" }}align-center {{ end }} {{- with .Get "class" }}{{ . }}{{- end }}" {{-
@@ -35,10 +46,10 @@
3546
{{ end }}>
3647
{{- end }}
3748
{{- /* Media Processor: Delivering the visual artifact with lazy-loading performance. */ -}}
38-
<img loading="lazy" src="{{ .Get " src" }}{{- if eq (.Get "align" ) "center" }}#center{{- end }}" {{- if or
39-
(.Get "alt" ) (.Get "caption" ) }} alt="{{ with .Get " alt" }}{{ . }}{{ else }}{{ .Get "caption" |
40-
markdownify | plainify }}{{ end }}" {{- end -}} {{- with .Get "width" }} width="{{ . }}" {{ end -}} {{- with
41-
.Get "height" }} height="{{ . }}" {{ end -}} />
49+
<img loading="lazy" src="{{ $src }}{{- if eq (.Get " align") "center" }}#center{{- end }}" {{- if or (.Get "alt"
50+
) (.Get "caption" ) }} alt="{{ with .Get " alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify |
51+
plainify }}{{ end }}" {{- end -}} {{- with .Get "width" }} width="{{ . }}" {{ end -}} {{- with .Get "height"
52+
}} height="{{ . }}" {{ end -}} />
4253
{{- if .Get "link" }}</a>{{ end -}}
4354

4455
{{- /* Scholarly Metadata: Injecting semantic figcaptions and attribution trails. */ -}}

0 commit comments

Comments
 (0)