Documents posted on GitHub looks different from rendered by Hugo

We had similar issues for some time, but I believe we found a solution today.

Problem: Images embedded with ![Test][Destination] into regular pages are either shown in GitHub preview or in the rendered site, but not both.

Our analysis: With pretty URLs, a regular page like content/section/page.md is rendered by Hugo as section/page/index.html. So the image Destination needs to be relative to section for GitHub but relative to section/page for the rendered site. (The content is not a problem if the Destination is also below content)

Our solution: We use the markdown render hook feature to override how the image Destination is treated. The logic is a bit complicated, but the basic idea is to add ../ for relative Destination in images appearing in regular pages:

{{- if strings.HasPrefix .Destination "http:" -}}
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />

{{- else if strings.HasPrefix .Destination "https:" -}}
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />

{{- else if strings.HasPrefix .Destination "/" -}}
{{ $destination := printf "%s%s" .Page.Site.BaseURL .Destination }}
<img src="{{ $destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />

{{- else if .Page.BundleType -}}
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />

{{- else -}}
{{ $destination := printf "../%s" .Destination }}
<img src="{{ $destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />

{{- end -}}

Unfortunately there is some logic involved in detecting a relative image Destination so we had to put this {{- else if -}} cascade.