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

Fix cachebust for files in the output path #1586

Merged
merged 4 commits into from
Aug 19, 2021
Merged

Conversation

InputUsername
Copy link
Contributor

@InputUsername InputUsername commented Aug 14, 2021

The search_for_file helper function now accepts an optional output path. If passed, the file will also be searched there.
This is used in the get_url Tera function to search in the Site::output_path.

In practice, this means cachebust works again for files in the output path.
I've tested this with one of my sites and it seems to work perfectly.

This should fix the main issue of #1570. That issue's thread also discusses other things related to getting urls of files in the output path though, so you might want to keep it open.

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

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.

I think we should always pass the output_dir so we remove the Option

components/templates/src/global_fns/helpers.rs Outdated Show resolved Hide resolved
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.

Can you add a test? It could be added in one of the existing ones

@InputUsername
Copy link
Contributor Author

Can you add a test? It could be added in one of the existing ones

Sure thing. Where should I add it exactly? Do I add a test to components/templates/src/global_fns/files.rs? Or should I add one for load_data, get_file_hash etc too?

I was thinking a test like this:

#[test]
fn can_link_to_file_in_output_path() {
    let dir = create_temp_dir();
    let public = dir.path().join("public");
    create_dir(&public).expect("Failed to create output directory");
    create_file(&public.join("style.css"), "// Hello world")
        .expect("Failed to create file in output directory");

    let static_fn = GetUrl::new(dir.path().to_path_buf(), Config::default(), HashMap::new(), public);
    let mut args = HashMap::new();
    args.insert("path".to_string(), to_value("style.css").unwrap());
    assert_eq!(static_fn.call(&args).unwrap(), "http://a-website.com/style.css");
}

Sorry for all the questions 😅

@Keats
Copy link
Collaborator

Keats commented Aug 18, 2021

Just one is fine, the test you wrote seems ok

@InputUsername
Copy link
Contributor Author

Just one is fine, the test you wrote seems ok

Thanks, done.

The search_for_file helper function now accepts an optional
output path. If passed, the file will also be searched there.
This is used in the get_url function to search in the
Site::output_path.

In practice, this means cachebust works for files in the
output path.
@Keats Keats merged commit 5ca2b29 into getzola:next Aug 19, 2021
@Keats
Copy link
Collaborator

Keats commented Aug 19, 2021

Thanks!

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