Skip to content

Conversation

@wharris23
Copy link

@wharris23 wharris23 commented Sep 3, 2025

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

@netlify
Copy link

netlify bot commented Sep 3, 2025

Deploy Preview for hugo-hextra ready!

Name Link
🔨 Latest commit 39bf711
🔍 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.

Copy link
Author

@wharris23 wharris23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly a fixed version.

@ldez
Copy link
Contributor

ldez commented Sep 4, 2025

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 -}}
@imfing
Copy link
Owner

imfing commented Sep 10, 2025

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

@wharris23
Copy link
Author

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

@imfing
Copy link
Owner

imfing commented Sep 10, 2025

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

no worries take your time

Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
@wharris23 wharris23 changed the title add-full-url-support Sep 10, 2025
@wharris23
Copy link
Author

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

@ldez
Copy link
Contributor

ldez commented Sep 10, 2025

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 -}}
template comments instead of HTML comments

Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
{{- /* Default to just filename */ -}}
{{- $file_url := $filename -}}

{{- if .full_url -}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full_url is ignored when $base_url is empty, please pay attention to line 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants