Skip to content

Commit

Permalink
fix: regex of external links and hosting
Browse files Browse the repository at this point in the history
Use `replace` instead of `replaceRE` to prevent some regular special
symbols in the string from causing replacement failures, e.g.
https://music.163.com/song?id=1409276662 (`?`)
  • Loading branch information
reuixiy committed Jan 14, 2020
1 parent 8918a4b commit ca47e40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions layouts/partials/components/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
{{- $url := replaceRE `<(img) src="/?([^":]+)` `$2` . -}}
{{- $prefix := replaceRE `(<(img) src=")/?([^":]+)` `$1` . -}}
{{- $replacement := (printf `%s%s%s` $prefix $hostURL $url) -}}
{{- $Content := ($.Scratch.Get "Content") | replaceRE . $replacement | safeHTML -}}
{{- $Content := replace ($.Scratch.Get "Content") . $replacement | safeHTML -}}
{{- $.Scratch.Set "Content" $Content -}}
{{- end -}}
{{- end -}}
Expand All @@ -166,7 +166,7 @@
{{- $url := replaceRE `<(video) src="/?([^":]+)` `$2` . -}}
{{- $prefix := replaceRE `(<(video) src=")/?([^":]+)` `$1` . -}}
{{- $replacement := (printf `%s%s%s` $prefix $hostURL $url) -}}
{{- $Content := ($.Scratch.Get "Content") | replaceRE . $replacement | safeHTML -}}
{{- $Content := replace ($.Scratch.Get "Content") . $replacement | safeHTML -}}
{{- $.Scratch.Set "Content" $Content -}}
{{- end -}}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/components/markdownify.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{{- if eq (substr . 9 4) "http" -}}
{{- $raw := replaceRE `(<a href="[^"]+")` `$1` . -}}
{{- $replacement := printf `%s target="_blank" rel="noopener"` $raw -}}
{{- $Content := ($Deliver.Scratch.Get "Content") | replaceRE . $replacement | safeHTML -}}
{{- $Content := replace ($Deliver.Scratch.Get "Content") . $replacement | safeHTML -}}
{{- $Deliver.Scratch.Set "Content" $Content -}}
{{- end -}}
{{- end -}}
Expand Down

0 comments on commit ca47e40

Please sign in to comment.