Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong URLs created for assets in a page with date specified in directory name #1943

Closed
roblillack opened this issue Jul 29, 2022 · 3 comments
Labels

Comments

@roblillack
Copy link

Bug Report

Environment

Zola version: 0.16.0 (macOS)

Expected Behavior

Calling get_url(path=X) with X being the path to a page asset should correctly create a resolvable URL. This should be true even for pages that have a date specified as part of their directory name. For example, for page 2022-07-29-post/index.md with a page asset img.jpg, calling get_url(path="/2022-07-29-post/img.jpg") should lead to the URL https://example.com/post/img.jpg.

Current Behavior

Currently, for a page 2022-07-29-post/index.md with a page asset img.jpg, calling get_url(path="/2022-07-29-post/img.jpg") leads to the unresolvable URL https://example.com/2022-07-29-post/img.jpg.

Step to reproduce

  1. In an empty directory, create a simple site:

    echo 'base_url="https://example.com"' > config.toml
    mkdir -p content/2022-07-29-post templates
    touch content/2022-07-29-post/img.jpg
    cat > templates/page.html <<EOF
    {% for asset in page.assets %}
    <a href="{{ get_url(path=asset) }}">click</a>
    {%- endfor %}
    EOF
    cat > content/2022-07-29-post/index.md <<EOF
    ---
    title: Test
    ---
    EOF
  2. Run zola build

  3. Check the contents of public/post/index.html. It should contain

    <a href="https://example.com/post/img.jpg">click</a>

    but contains

    <a href="https://example.com/2022-07-29-post/img.jpg">click</a>
@Keats Keats added the bug label Jul 29, 2022
@Infides
Copy link

Infides commented Nov 6, 2022

This is a known issue and a duplicate of: #788 and #1035

@Keats Keats closed this as completed Jan 12, 2023
@Infides
Copy link

Infides commented Mar 19, 2023

I am sorry to bring this topic up again. The behavior is still not solved with 0.17.x
I tried to find the root problem and I have the following theory:
When a page is created, the from_file() method from page.rs will be called and in this method the find_related_assets() method is called to find all assets. This will generate a vector with assets, which contain the path to the assets, in the case when a date is in the folder name, the date will also be in this path.
In order to see this I created a PR here: #2146
This PR prints the paths for each asset, in the case with the date in the folder it will look like this:

Entry path: /tmp/.tmpGZlN57/content/posts/2013-06-02_with-assets
Entry path: /tmp/.tmpGZlN57/content/posts/2013-06-02_with-assets/fail.png
Entry path: /tmp/.tmpGZlN57/content/posts/2013-06-02_with-assets/graph.jpg
Entry path: /tmp/.tmpGZlN57/content/posts/2013-06-02_with-assets/example.js

Am I on the right track here? What do you think @Keats?

@Keats
Copy link
Collaborator

Keats commented Mar 19, 2023

That represents the path to the asset in the filesystem, so it's normal to have the date in the path

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

No branches or pull requests

3 participants