I’m trying to use replaceRE
to extract the iTunes podcast ID from a URL.
This code is from my header.html
partial.
{{ if .Site.Params.Podcast.enable }}
<meta name="apple-itunes-app" content="app-id={{- replaceRE "id(\d{10})" "$1" .Site.Params.Podcast.iTunes -}}" />
{{ end }}
I’m getting an invalid syntax
error, but I can’t see where I’ve gone wrong.
You need to escape it properly. See:
Thanks @alexandros .
I’d seen that thread come up in searching the forum, but thought it wasn’t going to be my problem since the regex in that thread seemed much more complex than what I was aiming for!
For the sake of those searching here later, here’s the solution I came up with to extract the iTunes ID from a URL:
<title>{{ .Site.Params.title }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{{ with .Site.Params.subtitle }}<meta name="description" content="{{ . }}">{{ end }}
{{ with .Site.Params.name }}<meta name="author" content="{{ . }}">{{ end }}
{{- with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s+%s" href="%s" title="%s" />` .Rel .MediaType.Type .MediaType.Suffix .Permalink $.Site.Title | safeHTML }}
{{- end -}}
{{ .Hugo.Generator }}
{{ with .Site.Params.Podcast.itunes }}
<meta name="apple-itunes-app" content="app-id={{ replaceRE "https\\:\\/\\/itunes\\.apple\\.com\\/[a-z]{2}\\/podcast\\/[a-z\\-]*\\/id(\\d{10}).*" "$1" . }}" />
{{ end }}
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{- $css := .Site.Data.libs.css -}}
{{ printf "<link rel=\"stylesheet\" href=\"//use.fontawesome.com/releases/v%s/css/all.css\" integrity=\"%s\" crossorigin=\"anonymous\">" $css.fontawesome.version $css.fontawesome.integrity | safeHTML }}
{{ printf "<link rel=\"stylesheet\" href=\"//cdn.plyr.io/%s/plyr.css\" integrity=\"%s\" crossorigin=\"anonymous\">" $css.plyr.version $css.plyr.integrity | safeHTML }}
<!-- OpenStreetMaps -->
{{ printf "<link rel=\"stylesheet\" href=\"//unpkg.com/leaflet@%s/dist/leaflet.css\" integrity=\"%s\" crossorigin=\"anonymous\"/>" $css.leaflet.version $css.leaflet.integrity | safeHTML }}
{{- $ieStyles := resources.Get "scss/main.scss" | toCSS | minify -}}
{{- $ieJs := resources.Get "js/ie/html5shiv.js" | minify -}}
(Though if anyone has a more elegant solution, I’d love to hear it!)