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

vi serve change detection fix #2269

Open
wants to merge 23 commits into
base: next
Choose a base branch
from
Open

Conversation

Raymi306
Copy link
Contributor

@Raymi306 Raymi306 commented Aug 13, 2023

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)?

Fixes #2266

A little bit of code duplication going on.
I made sure to leave a helpful comment explaining the extra branch.

Side note: I noticed that notify library is 2 major versions behind. Would you be interested in PRs for bumping major versions of dependencies, or don't fix what isn't broken?

Keats and others added 22 commits March 19, 2023 20:37
* Reuse Client when checking urls and add timeout for requests
* Implement replace_re filter

* Cargo fmt

* add regex caching

* cargo fmt

* update docs, update unit test

* rename replace_re -> regex_replace
Relative links in the entry content do not currently have a base URI, so
will be resolved relative to the feed URI:

Given an entry with the content:

    <a href="some-resource.bin">

And URIS of:

 * entry: https://example.org/blog/some-entry/
 * feed:  https://example.org/atom.xml

The link URI will end up as:

    https://example.org/some-resource.bin

rather than the URI that ends up resolved in the rendered page:

   https://example.org/blog/some-entry/some-resource.bin

The atom and RSS formats allow for an xml:base attribute (itself
specified in [1]) to provide a base URI of a subset of a document. This
change adds xml:base attributes to each entry, using the page permalink.

This gives us something equivalent to:

    <entry>
     <content xml:base="https://example.org/blog/some-entry/">
      <![CDATA[
       <a href="some-resource.bin">
      ]]>
     </content>
    </entry>

[1]: https://www.w3.org/TR/xmlbase/

Signed-off-by: Jeremy Kerr <[email protected]>
* Fix multi-ligual json index

* multi-lingual search Fix cargo fmt
…tzola#2196)

* Add search into the serialized config (getzola#2165)

* Only expose index_format

* Create config.search struct

* cargo fmt
* Fix hard link panic and add better error info to std:fs errors

* cargo fmt

* Remove erroneously committed config change

* Remove console import; Use with context to provide additional error info

* improve error wording
* Add optional decoding="async" loading="lazy" for img

In theory, they can make the page load faster and show content faster.

There’s one problem: CommonMark allows arbitrary inline elements in alt text.
If I want to get the correct alt text, I need to match every inline event.

I think most people will only use plain text, so I only match Event::Text.

* Add very basic test for img

This is the reason why we should use plain text when lazy_async_image is enabled.

* Explain lazy_async_image in documentation

* Add test with empty alt and special characters

I totaly forgot one can leave the alt text empty.
I thought I need to eliminate the alt attribute in that case,
but actually empty alt text is better than not having an alt attribute at all:
https://www.w3.org/TR/WCAG20-TECHS/H67.html
https://www.boia.org/blog/images-that-dont-need-alternative-text-still-need-alt-attributes
Thus I will leave the empty alt text.

Another test is added to ensure alt text is properly escaped.
I will remove the redundant escaping code after this commit.

* Remove manually escaping alt text

After removing the if-else inside the arm of Event::Text(text),
the alt text is still escaped.
Indeed they are redundant.

* Use insta for snapshot testing

`cargo insta review` looks cool!

I wanted to dedup the cases variable,
but my Rust skill is not good enough to declare a global vector.
…atter (getzola#2237)

* Prevent spans crossing line boundaries in class formatter

* Add snapshot tests for classed highlighting
* sort page.assets by filename

Uses .to_str() to sort files and subfolders.

The .unwrap() may need work or be replaced by unwrap_or_default(). Given
earlier checks in the function it should work however.

* add tests for assets sorting

* fix rustfmt

* use existing loop instead of windows

* also check the non-recursive test

* use .zip() and add assert msg
* templates:atom: add support for multiple authors

Atom 1.0 [0] support multiple `<author>` entries in the feed. This commit
modified the template to generate as many `<author>` as the page's
metadata contains.

[0] https://validator.w3.org/feed/docs/atom.html#recommendedEntryElements

* Test we can have multiple authors in ATOM feeds
The `rel` and `type` HTML attributes are needed in the `base_url` (or
`section.permalink`) link so feed aggregators know that's the HTML page
that corresponds to the atom feed.

Note: The RSS template doesn't have this issue.
* use fs canonicalize to prevent path traversal

* fix cargo fmt
* Add ignored_static to config

* Make  handle ignored static files correctly

* cargo fmt

* Match on relative path rather than incorrect target path

* path -> partial path for serve static ignore

* remove debug println

* copy static directory if there is no ignored globset

* Update docs

* Deduplicate code with additional Option argument

* cargo fmt
* template:feeds: add extra block

* add missing >

* Revert "add missing >"

This reverts commit 45c6b9c.

* Revert "template:feeds: add extra block"

This reverts commit 596f7f1.

* Update docs for feed templates
@@ -653,6 +653,29 @@ pub fn serve(
};
messages::report_elapsed_time(start);
}
NoticeRemove(path) => {
// Some editors, like those in the vi family, replace the file you're
Copy link
Collaborator

Choose a reason for hiding this comment

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

vim works for me, is it only vi having issues?

Choose a reason for hiding this comment

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

On macOS, hot reloading works with vim/nvim for me. On Linux, neither work for me with zola built from master.

@Raymi306
Copy link
Contributor Author

Raymi306 commented Aug 14, 2023 via email

@donovanglover
Copy link

I also experience this issue with NixOS + Neovim. Is there any reason why the CI is failing?

@Keats
Copy link
Collaborator

Keats commented Sep 12, 2023

CI failure was unrelated I believe.
Does this patch fix the issue for you? I want to narrow down the exact editor/OS cause for the comment to be sure it's accurate

@donovanglover
Copy link

Patch fixes it for me 👍

@Keats
Copy link
Collaborator

Keats commented Sep 15, 2023

Ok, probably just need to update the comment to mention it's not on Mac then

@donovanglover
Copy link

FWIW I occasionally get the following error when saving config.toml. Restarting zola serve fixes it but I'm not sure if it's related to this patch.

Error: Failed to build the site
Error: A base URL is required in config.toml with key `base_url`

@donovanglover
Copy link

Not sure if related but I also occasionally get this error that requires restarting:

Error: Failed to build the site
Error: Failed to open file /path/to/website/config.toml
Error: Reason: No such file or directory (os error 2)

Race condition?

@Raymi306
Copy link
Contributor Author

Raymi306 commented Sep 17, 2023

Not sure if related but I also occasionally get this error that requires restarting:

Error: Failed to build the site
Error: Failed to open file /path/to/website/config.toml
Error: Reason: No such file or directory (os error 2)

Race condition?

Oof, it is likely.
vi is essentially deleting the file and moving over a copy on top of the old one when you save.
I can play with a short sleep and wait for the file to show over maybe 300ms?

If the site rebuilds and the config.toml file hasn't been moved over on top of the removed version, the site cannot rebuild correctly
@Raymi306
Copy link
Contributor Author

I couldn't replicate the race condition locally, I did some very quick and dirty testing and there was only ever 1 try to find the new file

@Raymi306
Copy link
Contributor Author

FWIW I occasionally get the following error when saving config.toml. Restarting zola serve fixes it but I'm not sure if it's related to this patch.

Error: Failed to build the site
Error: A base URL is required in config.toml with key `base_url`

I'm not sure what to make of this

@donovanglover
Copy link

I'll test out the new changes and see how it goes 👍

@donovanglover
Copy link

donovanglover commented Sep 19, 2023

Looks like #2269 (comment) still occurs unfortunately. If it helps I'm using auto-save.nvim.

Edit: Still get #2269 (comment) as an error as well.

I'm fine with the original commit being merged though. It works well enough to be useful.

@Raymi306
Copy link
Contributor Author

Looks like #2269 (comment) still occurs unfortunately. If it helps I'm using auto-save.nvim.

Edit: Still get #2269 (comment) as an error as well.

I'm fine with the original commit being merged though. It works well enough to be useful.

If my sleep and loop code doesn't fix it I should remove it before merge as it appears to have no function for me and it does not fix the intended problem.
Wish I knew what to make of this, I might look at the plugin you are using but I am not sure when I will have get to that

@donovanglover
Copy link

Got a new error today where zola terminated automatically. Previously I would have to manually stop the server.

Error: Failed to build the site
Error: Failed to open file /path/to/website/config.toml
Error: Reason: No such file or directory (os error 2)
Error: Failed to serve the site
Error: Can't watch `config.toml` for changes in folder `/path/to/website`. Does it exist, and do you have correct permissions?
Error: Reason: entity not found

FWIW I'm not using the race condition patch anymore.

@Keats
Copy link
Collaborator

Keats commented Sep 26, 2023

Is there some known docs about what weird things vi is doing? Or another tool handling it correctly?

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