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

WIP: Pages "inherit" assets from a section they colocate with (#877) #1107

Closed
wants to merge 5 commits into from

Conversation

southerntofu
Copy link
Contributor

The problem described in #877 is solved by this patch though in a very unoptimal way because all assets shared between pages in a section will be copied over to all pages output folders. This is because declaring the files as page assets will trigger their copy when rendering the page. I don't see a more elegant way to solve it (yet). Any ideas?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Keats
Copy link
Collaborator

Keats commented Jul 29, 2020

How about having a flag on a page whether it's a page with colocated assets or not. If there is, do like right now but if there isn't, in the markdown renderer (L125 of markdown.rs) make a link from the parent instead.

@southerntofu
Copy link
Contributor Author

How about having a flag on a page whether it's a page with colocated assets or not

Markdown links would work but then page.assets would be empty for those pages which is not expected behavior (eg. if a template lists a page's related assets). I'll try to dig deeper into how asset management works.

@Keats
Copy link
Collaborator

Keats commented Jul 30, 2020

I think that's fine, page.assets is only for colocated assets and if the asset is in the directory it isn't colocated with anything.

@southerntofu
Copy link
Contributor Author

The latest commit only copies assets once, but has them declared in the associated section/pages as expected. Relative links from Markdown are fixed on the go, and assets still returns paths from the content folder, which means we can't use page.assets in templates as relative URLs, but have to concatenate with the base_url (as was already the case).

This commit was tested with the following page.html:

{% for i in page.assets %}
{% if i is ending_with(".png") %}
<img src="{{ resize_image(path=i, width=400, op="fit_width") }}">
<img src="{{ config.base_url }}/{{ i }}">
{% endif %}
{% endfor %}

Waiting for feedback before i add some tests.

Not very interesting but worth mentioning for #687: for a "page in page" where the "parent" page has a different path/slug, the link produced in the "child" page will be incorrect.

@Keats
Copy link
Collaborator

Keats commented Aug 16, 2020

I still don't know whether to support that or not...

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

Successfully merging this pull request may close these issues.

None yet

2 participants