I’m using GitHub Pages for my repository’s website. I use zola build
to build the website files to the docs
folder in the repository. This approach is working fine, the GitHub repository is here and the website is viewable here. However, when I’m working on the website, zola serve
does not render images defined in the markdown pages.
I have the base url in config.toml
defined as
base_url = "https://gavinw.me/swift-macos"
Image files for the site are located in the static/img/
folder.
Markdown pages are located in the content/swiftui/
folder. For example, the markdown page located at content/swiftui/appstorage.md
looks something like the following:
+++
title = "AppStorage"
date = 2022-11-13
+++
The `@AppStorage` property wrapper reads and writes values from user defaults. The example below saves a fruit name (a string) to the fruit key in user defaults. When the app is relaunched, the saved fruit name will be displayed in the text label. Enter a fruit in the text field then click the save fruit button to save a new fruit to the fruit key in user defaults.
<p><img src="/swift-macos/img/appstorage.png" style="max-width:400px;" alt="app storage property"></p>
The path for the image file src="/swift-macos/img/appstorage.png"
must start with /swift-macos/
because that is where the repository resides on GitHub. If I use src="/img/appstorage.png"
then zola serve
will show the images but zola build
does not have the proper path for the image files.
I tried using zola serve --base-url /swift-macos
but I still have the problem of the images not being found in the markdown pages.
I also tried using the get_url()
function but that seems to only work in template files.
<p><img src="{{ get_url(path='/img/appstorage.png') }}" style="max-width:400px;" alt="app storage property"></p>
So my question is, how can I use zola build
and zola serve
when the image path in markdown files is something like src="/swift-macos/img/appstorage.png"
and the image files are located in the static/img/
folder?