hextra icon indicating copy to clipboard operation
hextra copied to clipboard

feat(codeblock): add full URL support

Open wharris23 opened this issue 4 months ago β€’ 7 comments

Summary

This PR adds support for using a full_url when linking files in code blocks.

Changes

  • If full_url is provided, it is used directly.
  • Otherwise falls back to base_url + filename or just filename.

This keeps the old behavior while allowing more flexibility for cases where file URLs don’t follow the standard format.

Closes #801

wharris23 avatar Sep 03 '25 22:09 wharris23

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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Sep 03 '25 22:09 netlify[bot]

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 -}}

ldez avatar Sep 04 '25 08:09 ldez

@wharris23 could you update the PR based on the above feedback?

imfing avatar Sep 10 '25 21:09 imfing

@imfing Yes, I apologize for the delay. I am working on the PR today and tomorrow.

wharris23 avatar Sep 10 '25 21:09 wharris23

@imfing Yes, I apologize for the delay. I am working on the PR today and tomorrow.

no worries take your time

imfing avatar Sep 10 '25 21:09 imfing

@imfing I believe all the checks pass now. Please let me know if you think this is good or if I can improve it.

wharris23 avatar Sep 10 '25 22:09 wharris23

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 -}}

ldez avatar Sep 10 '25 22:09 ldez