feat(codeblock): add full URL support
Summary
This PR adds support for using a full_url when linking files in code blocks.
Changes
- If
full_urlis provided, it is used directly. - Otherwise falls back to
base_url + filenameor justfilename.
This keeps the old behavior while allowing more flexibility for cases where file URLs donβt follow the standard format.
Closes #801
Deploy Preview for hugo-hextra ready!
| Name | Link |
|---|---|
| Latest commit | 39bf711034cc522c244d3ba78461a621a2ea46cb |
| Latest deploy log | https://app.netlify.com/projects/hugo-hextra/deploys/68e004b1556a78000862fbce |
| Deploy Preview | https://deploy-preview-820--hugo-hextra.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
I think your PR must reference the issue #801 instead of the discussion #799.
The comments inside a PR description cannot automatically close a discussion, they can only close an issue or another PR.
The title can also be improved: feat(codeblock): add full URL support.
For consistency, I recommend using a local variable:
diff --git i/layouts/_partials/components/codeblock.html w/layouts/_partials/components/codeblock.html
index 857b925..43afe2e 100644
--- i/layouts/_partials/components/codeblock.html
+++ w/layouts/_partials/components/codeblock.html
@@ -1,5 +1,6 @@
{{ $filename := .filename | default "" -}}
{{ $base_url := .base_url | default "" -}}
+{{ $full_url := .full_url | default "" -}}
{{ $lang := .lang | default "" }}
{{ $content := .content }}
{{ $options := .options | default (dict) }}
@@ -13,8 +14,8 @@
{{- $file_url := $filename -}} <!-- default to just filename -->
- {{- with .full_url -}}
- {{- $file_url = . -}}
+ {{- if $full_url -}}
+ {{- $file_url = $full_url -}}
{{- else if $base_url -}}
{{- $file_url = urls.JoinPath $base_url $filename -}}
{{- end -}}
@wharris23 could you update the PR based on the above feedback?
@imfing Yes, I apologize for the delay. I am working on the PR today and tomorrow.
@imfing Yes, I apologize for the delay. I am working on the PR today and tomorrow.
no worries take your time
@imfing I believe all the checks pass now. Please let me know if you think this is good or if I can improve it.
I think you missed this remark:
For consistency, I recommend using a local variable:
diff --git i/layouts/_partials/components/codeblock.html w/layouts/_partials/components/codeblock.html
index 857b925..43afe2e 100644
--- i/layouts/_partials/components/codeblock.html
+++ w/layouts/_partials/components/codeblock.html
@@ -1,5 +1,6 @@
{{ $filename := .filename | default "" -}}
{{ $base_url := .base_url | default "" -}}
+{{ $full_url := .full_url | default "" -}}
{{ $lang := .lang | default "" }}
{{ $content := .content }}
{{ $options := .options | default (dict) }}
@@ -13,8 +14,8 @@
{{- $file_url := $filename -}} <!-- default to just filename -->
- {{- if .full_url -}}
- {{- $file_url = . -}}
+ {{- if $full_url -}}
+ {{- $file_url = $full_url -}}
{{- else if $base_url -}}
{{- $file_url = urls.JoinPath $base_url $filename -}}
{{- end -}}