Specifically if you look at the “img_url” key, my goal is to grab every image listed on the page by it’s src value. A bonus would be to grab the images absolute url.
Currently my output is extracting the full html code for the img tag.
See github here for the project files and code I’m currently using:
I have a shortcode that resizes images in posts to fit to screen which I think may be effecting output, but I’m unsure.
Here is my current index.json:
[
{{ range $index, $page := (where .Site.Pages "Kind" "page") -}}
{{- if ne $page.Type "json" -}}
{{- if and $index (gt $index 0) -}},{{- end }}
{
"uri": "{{ $page.Permalink }}",
"title": "{{ htmlEscape $page.Title}}",
"categories": [{{ range $tindex, $tag := $page.Params.categories }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
"description": "{{ htmlEscape .Description}}",
"content": {{$page.Plain | jsonify}},
"image_url": [{{ range $pageimgs := (findRE `<img[^>]*src="([^"]+)"[^>]*>` .Content )}}{{ $myvar := replaceRE `/resize.+?/` `/` $pageimgs }}{{ $imageslice := slice $myvar }}{{ range $imageslice }}"{{ . }}",{{ end }}{{ end }}]
}
{{- end -}}
{{- end -}}
]