Skip to content

Commit

Permalink
Fix broken iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
shiruken committed Apr 30, 2024
1 parent 479b360 commit 0c5d533
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion layouts/shortcodes/iframe.html
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<iframe src="{{ .Get "src" }}" width="100%" height="600" frameborder="0"></iframe>
<!-- Based on https://discourse.gohugo.io/t/shortcode-for-iframe-breaking-at-update-hugo-122-x-123-8/48904/16 -->
{{ with .Get "src" }}
{{ $u := urls.Parse . }}
{{ if $u.IsAbs }}
{{ errorf "The src argument passed to the %q shortcode may not be an absolute URL. See %s" $.Name $.Position }}
{{ else }}
{{ with $.Page.Resources.Get $u.Path }}
{{ $src := (.Content | resources.FromString .Path).RelPermalink }}
<iframe src="{{ $src }}" width="100%" height="600" frameborder="0">The <a href="{{ $src }}">embedded content</a> cannot be displayed.</iframe>
{{ else }}
{{ errorf "The %q shortcode was unable to find %s. See %s" $.Name $u.Path $.Position }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode requires a src argument. See %s" .Name .Position }}
{{ end }}

0 comments on commit 0c5d533

Please sign in to comment.