Skip to content

Commit

Permalink
fix links being broken for pages with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Feb 21, 2022
1 parent 9c04ca0 commit 714b4fc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{$trimmed := strings.TrimSuffix ".md" (.Destination | safeURL)}}
{{$trimmed = replace $trimmed "%20" "-" }}
{{$external := strings.HasPrefix $trimmed "http" }}
{{$dashedurl := replace $trimmed "%20" "-" }}
{{$external := strings.HasPrefix $dashedurl "http" }}
{{- if $external -}}
<a href="{{ $trimmed }}" rel="noopener">{{ .Text | safeHTML }}</a>
<a href="{{ $dashedurl }}" rel="noopener">{{ .Text | safeHTML }}</a>
{{- else -}}
{{$fixedUrl := (cond (hasPrefix $trimmed "/") $trimmed (print "/" $trimmed)) | urlize}}
{{$rooted := strings.TrimRight "/" (.Page.GetPage $fixedUrl).RelPermalink }}
{{$spacedurl := replace $trimmed "%20" " " }}
{{$fixedUrl := (cond (hasPrefix $spacedurl "/") $spacedurl (print "/" $spacedurl)) | urlize}}
{{$rooted := default $spacedurl (strings.TrimRight "/" (.Page.GetPage $spacedurl).RelPermalink) }}
<a href="{{$rooted}}" rel="noopener" class="internal-link" data-src="{{$rooted}}">{{ .Text | safeHTML }}</a>
{{- end -}}

0 comments on commit 714b4fc

Please sign in to comment.