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

get_url returns unprocessed path name #1098

Closed
adriangoransson opened this issue Jul 24, 2020 · 8 comments
Closed

get_url returns unprocessed path name #1098

adriangoransson opened this issue Jul 24, 2020 · 8 comments

Comments

@adriangoransson
Copy link

Bug Report

First off, thanks for a great tool. I really appreciate all the time and effort that have been put into Zola.

I'm having issues where my directory names contain umlauts (åäö in Swedish). It's for a gallery listing and in order to have correct alphabetical sorting this is the best solution I have found. The umlauts are removed when building so it works well.

For every page in the gallery there is an associated image as well. This is resized and processed without issues, but the link to the original is broken.

Environment

Zola version: 0.11.0

Expected Behavior

get_url should return a processed url to match the directory structure that is built by zola.

Current Behavior

get_url returns the path before the directory name has been transformed.

Step to reproduce

Directory structure.

content/frukt
├── _index.md
├── apelsin
│   ├── apelsin.jpg
│   ├── index.md
├── björnbär                 <- umlauts
│   ├── bjornbar.jpg
│   ├── index.md

In the page template.

<a href="{{ get_url(path=image_asset) }}">
    <img src="{{ resize_image(path=image_asset, width=400, op="fit_width") }}"" />
</a>

My workaround uses a relative url instead. I'm including it so anyone can tell me if it's unsound or something. Else it may help others. :)

{% if image_asset %}
<a href="{{ image_asset | split(pat="/") | last }}">
    <img src="{{ resize_image(path=image_asset, width=400, op="fit_width") }}" />
</a>
</div>
@adriangoransson adriangoransson changed the title get_url returns path that get_url returns unprocessed path name Jul 24, 2020
@Keats
Copy link
Collaborator

Keats commented Jul 24, 2020

For context: that's because the get_url by default just does a concatenation. It can also resolves internal links but only for .md files.

I've tagged it as bug/enhancement as it is not really a bug, more like a missing feature that people assume should be there.

@Keats
Copy link
Collaborator

Keats commented Jul 24, 2020

What's image_asset in that case? How about using page.assets[0] instead?

@adriangoransson
Copy link
Author

For context: that's because the get_url by default just does a concatenation. It can also resolves internal links but only for .md files.

I understand, but I don't agree that it makes much sense. It's not obvious that get_url only might resolve to a valid url.
In that case I think it should only accept paths that it can resolve and fail early if it won't. Maybe a filter or different function to get paths instead?

What's image_asset in that case? How about using page.assets[0] instead?

image_asset is just page.assets[index]. I have an associated csv for each entry as well so before the template body I'm looping over the assets and setting the variables that I'm going to use later on.

{% for asset in page.assets %}
  {% if asset is matching("[.](jpg|png)$") %}
    {% set_global image_asset = asset %}
  {% elif asset is matching("nutrition.csv") %}
    {# load tabular data #}
    {% set_global nutrition = data.records[0] %}
  {% endif %}
{% endfor %}

@Keats
Copy link
Collaborator

Keats commented Jul 25, 2020

I understand, but I don't agree that it makes much sense. It's not obvious that get_url only might resolve to a valid url.
In that case I think it should only accept paths that it can resolve and fail early if it won't. Maybe a filter or different function to get paths instead?

It's an ongoing process to ensure they are consistent (see issue linked above your comment) as features are added. Hopefully we can get to something good!

@bitemyapp
Copy link

I'm having this issue but with markdown files.

            <li class="nav" {%- if current_path is starting_with("contact/") %} id="selected" {%- endif %}>
                <a href="{{ get_url(path="./contact.md") | safe }}">contact</a>
            </li>

Turns into ./contact.md

<a href="http://127.0.0.1:1111/./contact.md">contact</a>

Repros with 0.13.0, 0.12 panics on building my site, 0.11 repros, as do 10, 9, and 8. 0.7.0 is where it starts working again:

<a href="http://127.0.0.1:1111/contact/">contact</a>

I read the docs for get_url and I can't figure out what I might be doing wrong. What happened?

@Keats
Copy link
Collaborator

Keats commented May 14, 2021

If you want to point to a .md in your content directory, you have to use @/contact.md, the @/ prefix tells Zola that you are looking to link to some other content and will find the right link.

@bitemyapp
Copy link

That fixed it! Thank you so much.

@Keats
Copy link
Collaborator

Keats commented Jul 19, 2021

Everything should be working with 0.14. Open a new issue if it doesn't.

@Keats Keats closed this as completed Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants