Zola: `check_external_links` should check anchors

Created on 26 Nov 2018  路  14Comments  路  Source: getzola/zola

When running with check_external_links, it should also check whether the given anchor targets are present. That is, when I link

https://test.com/page#link

Zola should check that the page

  • https://test.com/page exists and
  • has an <a id="link"> tag
enhancement

Most helpful comment

I just realized that I have been using the #target checker for several weeks now, and it has been incredibly helpful finding moved pages we link to in the Rust Cheat Sheet. Thank you so much for implementing this @wyze and @Keats!

All 14 comments

That's a bit trickier as we are rendering markdown concurrently and anchors are generated while rendering. It would have to be done in a post-rendering phase somehow

I have it locally but it relies on Zola being aware of all the anchors obviously and it won't parse HTML links for anchors (at least for now). You are defining them like so:

### <a name="data_structures"></a> Data Structures

which would have to change to

### Data Structures {#data_stuctures}

since named anchors is also coming for Zola 0.8. What do you think?

For internal links this is perfect, I didn't know of the {#data_stuctures} syntax, but it's nicer than injecting <a name>.

Long term, having the ability to check for external anchors (e.g., from shortcode-templated HTML to external HTML) would still be nice.

How would default checking work with serve during development?

I'd be fine having build only do build stuff and focus on speed, with an option check_on_build that can be enabled. Then check can do more expensive checks by default (again, probably with TOML options for better control), which can be run before deployment.

Anchor checking is done after the markdown for all pages is rendered (since we need that info to know their ToC). I don't think it would cause a noticeable slowdown like the external links, it's pretty much just creating one path from a string + some hashmaps lookup. Nothing like a HTTP request.
At the same time, since Zola does check internal links by default, I think it makes sense to check the anchors by default as well in build/serve...

I don't know if you've seen it but there is a new command in the upcoming version zola check that does all the verification without actually writing anything to disk. This is the new way to check for external links validity, rather than an option in the config.

At the same time, since Zola does check internal links by default, I think it makes sense to check the anchors by default as well in build/serve...

Ah, in that case yes, I agree.

I don't know if you've seen it but there is a new command in the upcoming version zola check that does all the verification without actually writing anything to disk.

I've seen some comments. I actually wanted to check the next branch out this morning but unfortunately I'm getting build errors (in sass-sys on Windows). As soon as a new release is available, I'd love to try it and upgrade.

in sass-sys on Windows

The pain everyone on Windows seems to encounter :(

Having something like this would still be very helpful for the Rust cheat sheet.

Just the other day @wyze found a target that was dead for some time, and I'm sure we have quite a few more ...

That looks good, a few comments but can be done on the PR

Hi, I've seen the PR seems to have been merged; if I try 0.9, would the target-checker work?

Yes, although some issues persist: https://github.com/getzola/zola/issues/805

I just realized that I have been using the #target checker for several weeks now, and it has been incredibly helpful finding moved pages we link to in the Rust Cheat Sheet. Thank you so much for implementing this @wyze and @Keats!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

porglezomp picture porglezomp  路  7Comments

porglezomp picture porglezomp  路  7Comments

RealOrangeOne picture RealOrangeOne  路  6Comments

svenstaro picture svenstaro  路  5Comments

nikhiljha picture nikhiljha  路  5Comments