Skip to content

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

Closed
@roblillack

Description

@roblillack

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions