Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

BUG: Incorrect image paths #32

Closed
VincentTam opened this issue Jul 4, 2019 · 3 comments · Fixed by #33
Closed

BUG: Incorrect image paths #32

VincentTam opened this issue Jul 4, 2019 · 3 comments · Fixed by #33

Comments

@VincentTam
Copy link
Collaborator

VincentTam commented Jul 4, 2019

Bug Report

Describe the bug

I tried building a demo site for this theme on Framagit: https://vincenttam.frama.io/fish-demo/blog/creating-a-new-theme/ with

baseurl = "https://vincenttam.frama.io/fish-demo/"

in config.toml. However, the images aren't rendered. Rendered HTML shows

<article class="mini-post">
      <section>
        
<a href="/fish-demo/blog/hugoisforlovers/" class="image featured">
  <img src="/img/2014/04/pic01.jpg" alt="Pic 1">
</a>


      </section>
      <header>
        <h1><a href="/fish-demo/blog/hugoisforlovers/">Getting Started with Hugo</a></h1>
        <time class="published" datetime="">April 2, 2014</time>
      </header>
    </article>

The src of the <img> is incorrect in case of GitHub/GitLab project pages. I'm not an expert in web design/development. You're going to be more proficient than me to fix this.

{{ if .Params.featured }}
<a href="{{ .RelPermalink }}" class="image featured">
<img src="/img/{{ if eq .Params.featuredpath "date" }}{{ .Page.Date.Format "2006/01" }}/{{ else }}{{ .Params.featuredpath }}{{ end }}{{ .Params.featured }}" alt="{{ .Params.featuredalt }}">
</a>
{{ end }}

Besides, I also get error on nav bar and page redirect after submitting Staticman comment. The images in the posts have incorrect URL's.

To Reproduce

  1. Use this theme on a GitHub/GitLab project pages
  2. See broken images

Expected behavior

Screenshot from 2019-07-04 13-26-34

Screenshots

Screenshot from 2019-07-04 13-23-12

Environment

@pacollins
Copy link
Owner

That is an interesting bug I will have to look into. It is due to the URL being relative for multilingual, so I think Hugo might be parsing it odd? I'll check back.

@VincentTam
Copy link
Collaborator Author

Thanks for reply. I should have said that the contents of the demo site are copied from exampleSite by

cp -r exampleSite/* LICENSE.md .

@pacollins
Copy link
Owner

pacollins commented Jul 4, 2019

On mobile, so I'm not certain on this, but I think this should solve it. It probably does not need the parenthesis around the path.Join, but I played it safe.

<img src="{{ (path.Join "img" (cond (eq .Params.featuredpath "date") (.Page.Date.Format "2006/01") (.Params.featuredpath)) .Params.featured) | relurl }}" alt="{{ .Params.featuredalt }}">

https://gohugo.io/functions/relurl/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants