statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.

Home Page:https://statiq.dev/web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Images don't show on post listing

AlexHedley opened this issue · comments

Created a post - /input/posts/images.md
Added an image /input/posts/images/background.jpg

![background](images/background.jpg "background")

When deployed if you look at the listing, the html is

<img src="images/background.jpg" alt="background" title="background">

image

but fine on the specific post page.

Links

Good one, and also going to be pretty tricky. The issue is that the listing page grabs the blurb HTML straight from what's been rendered in the post (I think it's the first paragraph element by default). Since the image link is relative, and the post is under a subfolder that the listing isn't, the copied HTML from the post isn't referring to the correct location because the base path for the relative image link is different.

One quick workaround would be to root the image path so it's coming from the root of the site (including any top-level subfolders, I.e. LinkRoot).

I'll think about a better longer-term fix. Ideally I'd be able to specify an alternate base path for relative links just for the listing section of the post listing page, but I think alternate base paths ate only for an entire page (will need to research this). Alternatively I might be able to parse the HTML for the blurbs and rewrite any relative links, but that gets a little tricky and might break other stuff.

I'm also wondering if this would be best handled by some JavaScript in the theme on the post list page. I generally don't love JS for stuff like this and prefer to keep it to a minimum, but it might make sense to just clean these relative links up on the client if there any.