From fb347c2e029bfb53421512b94e789acda5f2be81 Mon Sep 17 00:00:00 2001 From: southerntofu <52931252+southerntofu@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:56:33 +0000 Subject: [PATCH] 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 --- components/site/src/link_checking.rs | 11 +++++++---- docs/content/documentation/content/page.md | 2 +- test_site_i18n/content/_index.fr.md | 7 ++++++- test_site_i18n/content/_index.md | 2 +- test_site_i18n/content/blog/_index.fr.md | 4 ++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/components/site/src/link_checking.rs b/components/site/src/link_checking.rs index 33dbe519..e22e684f 100644 --- a/components/site/src/link_checking.rs +++ b/components/site/src/link_checking.rs @@ -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)) } diff --git a/docs/content/documentation/content/page.md b/docs/content/documentation/content/page.md index c0e80796..0f018e04 100644 --- a/docs/content/documentation/content/page.md +++ b/docs/content/documentation/content/page.md @@ -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 diff --git a/test_site_i18n/content/_index.fr.md b/test_site_i18n/content/_index.fr.md index b7249018..46fe786d 100644 --- a/test_site_i18n/content/_index.fr.md +++ b/test_site_i18n/content/_index.fr.md @@ -2,4 +2,9 @@ title = "Accueil" +++ -Page d'accueil +Page d'accueil. [Notre blog](@/blog/_index.fr.md) + +[Lire notre description](#about) + + +# À propos {#about} diff --git a/test_site_i18n/content/_index.md b/test_site_i18n/content/_index.md index 814b9a0e..e9aadba8 100644 --- a/test_site_i18n/content/_index.md +++ b/test_site_i18n/content/_index.md @@ -2,4 +2,4 @@ title = "Home" +++ -Homepage +Homepage. [Our blog](@/blog/_index.md) diff --git a/test_site_i18n/content/blog/_index.fr.md b/test_site_i18n/content/blog/_index.fr.md index 2f97f2ff..8e1497c0 100644 --- a/test_site_i18n/content/blog/_index.fr.md +++ b/test_site_i18n/content/blog/_index.fr.md @@ -3,3 +3,7 @@ title = "Mon blog" sort_by = "date" insert_anchors = "right" +++ + +[Dernières nouvelles](#news) + +# News {#news}