Bugfix check links i18n (close #1694) (#1780)

* Treat _index.LANG.md as section, not page (close #1694)
Display more advanced information in case of a future crash here

* Add link to translated local section in test_site_i18n to catch #1694
It appears linking to another translated page does not trigger the bug,
but linking to a section within the same (translated) page does.

* Allow (and test for) homepage internal links in broken link detection

Co-authored-by: southerntofu <southerntofu@thunix.net>
This commit is contained in:
southerntofu 2022-02-26 20:56:33 +00:00 committed by GitHub
parent 3dde2ce562
commit fb347c2e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 7 deletions

View File

@ -47,7 +47,7 @@ pub fn check_internal_links_with_anchors(site: &Site) -> Result<()> {
// Check for targets existence (including anchors), then keep only the faulty
// entries for error reporting purposes.
let missing_targets = links_with_anchors.filter(|(_, md_path, anchor)| {
let missing_targets = links_with_anchors.filter(|(page, md_path, anchor)| {
// There are a few `expect` here since the presence of the .md file will
// already have been checked in the markdown rendering
let mut full_path = site.base_path.clone();
@ -55,15 +55,18 @@ pub fn check_internal_links_with_anchors(site: &Site) -> Result<()> {
for part in md_path.split('/') {
full_path.push(part);
}
if md_path.contains("_index.md") {
// NOTE: This will also match _index.foobar.md where foobar is not a language
// as well as any other sring containing "_index." which is now referenced as
// unsupported page path in the docs.
if md_path.contains("_index.") {
let section = library
.get_section(&full_path)
.expect("Couldn't find section in check_internal_links_with_anchors");
.expect(&format!("Couldn't find section {} in check_internal_links_with_anchors from page {:?}", md_path, page.strip_prefix(&site.base_path).unwrap()));
!section.has_anchor(anchor)
} else {
let page = library
.get_page(&full_path)
.expect("Couldn't find section in check_internal_links_with_anchors");
.expect(&format!("Couldn't find page {} in check_internal_links_with_anchors from page {:?}", md_path, page.strip_prefix(&site.base_path).unwrap()));
!(page.has_anchor(anchor) || page.has_anchor_id(anchor))
}

View File

@ -4,7 +4,7 @@ weight = 30
+++
A page is any file ending with `.md` in the `content` directory, except files
named `_index.md`.
named `_index.md`. **Note:** page file names must not contain `_index.` [at all](https://github.com/getzola/zola/pull/1694).
If a file ending with `.md` is named `index.md`, it will generate a page
with the name of its directory (for example, `/content/about/index.md` would

View File

@ -2,4 +2,9 @@
title = "Accueil"
+++
Page d'accueil
Page d'accueil. [Notre blog](@/blog/_index.fr.md)
[Lire notre description](#about)
# À propos {#about}

View File

@ -2,4 +2,4 @@
title = "Home"
+++
Homepage
Homepage. [Our blog](@/blog/_index.md)

View File

@ -3,3 +3,7 @@ title = "Mon blog"
sort_by = "date"
insert_anchors = "right"
+++
[Dernières nouvelles](#news)
# News {#news}