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

Support colocating subfolders #1582

Merged
merged 2 commits into from
Sep 4, 2021

Conversation

timakro
Copy link
Contributor

@timakro timakro commented Aug 8, 2021

Closes #894.

Comment on lines -49 to -55
// `find_related_assets` only scans the immediate directory (it is not recursive) so our
// filtering only needs to work against the file_name component, not the full suffix. If
// `find_related_assets` was changed to also return files in subdirectories, we could
// use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter
// against the remaining path. Note that the current behaviour effectively means that
// the `ignored_content` setting in the config file is limited to single-file glob
// patterns (no "**" patterns).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are centered around this advice. Above, I replaced read_dir by WalkDir to collect assets recursively. And everywhere where the collected assets are accessed I replaced .file_name() with .strip_prefix(&page.file.path.parent().unwrap()). Note that I wanted to use .strip_prefix(&page.file.parent) originally but there is a special case for pages, where parent is actually grand_parent, that breaks this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a special case for pages, where parent is actually grand_parent, that breaks this.

Do you mean when you have an asset folder? That's expected then since otherwise the parent would refer to the page itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I meant.

Comment on lines -77 to -83
/// Colocated asset links refers to the files in the same directory,
/// there it should be a filename only
fn is_colocated_asset_link(link: &str) -> bool {
!link.contains('/') // http://, ftp://, ../ etc
&& !starts_with_schema(link)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could adjust this to match files in colocated subfolders as well. But I'm proposing to get rid of this completely instead. Why change relative links to absolute links?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot remember

@timakro timakro force-pushed the pr-colocation-with-subfolders branch from 44d295d to bb41f78 Compare August 8, 2021 14:15
@timakro
Copy link
Contributor Author

timakro commented Aug 8, 2021

I've missed some tests which are failing for obvious reasons now. (I don't know how to run all tests combined instead of each component separately.) Before resolving this let's first talk about the proposed change itself: if links to colocated files should be left relative or converted to absolute links.

@timakro
Copy link
Contributor Author

timakro commented Aug 16, 2021

@Keats I'm worried you're holding off reviewing this because the checks are failing. Please take a look so we can decide on my proposed change. I will either undo my proposed change or adjust the unit tests then.

@Keats
Copy link
Collaborator

Keats commented Aug 18, 2021

I'm worried you're holding off reviewing this because the checks are failing

I will have a look after 0.14.1, just focusing on fixing bugs rather than new features first. That and also holidays.

@Keats
Copy link
Collaborator

Keats commented Aug 24, 2021

Can you rebase your commit on the latest next branch?

@timakro timakro force-pushed the pr-colocation-with-subfolders branch from bb41f78 to 523f367 Compare August 24, 2021 09:32
@timakro
Copy link
Contributor Author

timakro commented Aug 24, 2021

@Keats Done

@timakro
Copy link
Contributor Author

timakro commented Aug 24, 2021

With the proposed change two tests would have to be adjusted 1890e38. Still not sure if I'm missing something.

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines -49 to -55
// `find_related_assets` only scans the immediate directory (it is not recursive) so our
// filtering only needs to work against the file_name component, not the full suffix. If
// `find_related_assets` was changed to also return files in subdirectories, we could
// use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter
// against the remaining path. Note that the current behaviour effectively means that
// the `ignored_content` setting in the config file is limited to single-file glob
// patterns (no "**" patterns).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a special case for pages, where parent is actually grand_parent, that breaks this.

Do you mean when you have an asset folder? That's expected then since otherwise the parent would refer to the page itself

@Keats Keats merged commit 4086b07 into getzola:next Sep 4, 2021
@eberkund
Copy link

eberkund commented Sep 7, 2021

Amazing, this is the one feature I needed to migrate a site I'm working on to Zola 🎉

@timakro timakro mentioned this pull request Dec 3, 2021
@manu-cyber
Copy link

manu-cyber commented Feb 16, 2022

Hey @timakro , unfortounately this pull request seems to break a template of mine. It makes use of the child-page’s assets which cannot be rendered because their path is relative to the child page instead of the section. Could you please have a look?

The full discussion is in the forum: https://zola.discourse.group/t/assets-from-child-page-content-have-wrong-relative-paths-when-shown-in-sections/1181/

manu-cyber added a commit to manu-cyber/zola that referenced this pull request Feb 20, 2022
This check was removed in getzola#1582 but broke using page assets in
their parent section. I re-introduced them in a way that should still
work with co-located subdirectories.
This commit is breaking a test however, which I don't yet understand
how.

Further info:
- getzola#1582
- https://zola.discourse.group/t/assets-from-child-page-content-have-wrong-relative-paths-when-shown-in-sections/1181/6
timakro added a commit to timakro/zola that referenced this pull request Feb 24, 2022
In getzola#1582 I broke the asset colocation example from the documentation:
https://www.getzola.org/documentation/content/overview/#asset-colocation

The breakage was discovered by irimi1:
getzola#1582 (comment)

When I wrote getzola#1582 I was not aware of the old behavior: links to assets
used to be rewritten to absolute links, so that colocated assets could
be linked to from `pagename/index.md` simply as `asset.xyz` instead of
`pagename/asset.xyz`. I unintentionally changed this, so that currently
you have to write `pagename/asset.xyz`.

Read this commit as a partial revert of getzola#1582. It restores the old
behavior as described above.

Caveats:
1. This will break lots of sites, just like getzola#1582 unintentionally broke
   lots of sites (but no one seemed to notice).
2. The old behavior is restored, including the quirk, that when linking
   from a page `pagename.md` to a section asset `asset.xyz` you need to
   write `../asset.xyz`, even though both files are in the same folder
   on disk. You can make sense of it in the following way: the asset
   belongs to the section so that is one level up from the page.
Yaroslav-95 added a commit to Yaroslav-95/zola that referenced this pull request May 4, 2022
Restores the change of relative to absolute links for colocated files
that was removed in commit 4086b07 / PR getzola#1582.
Yaroslav-95 added a commit to Yaroslav-95/zola that referenced this pull request May 4, 2022
Restores change of relative links to absolute links of colocated files
removed by commit 4086b07 / PR getzola#1582.
thomasantony pushed a commit to thomasantony/zola that referenced this pull request Sep 17, 2022
* Support colocating subfolders

* Adjust tests
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.

4 participants