Skip to content

Commit

Permalink
Treat _index.LANG.md as section, not page (close getzola#1694)
Browse files Browse the repository at this point in the history
Display more advanced information in case of a future crash here
  • Loading branch information
southerntofu committed Feb 25, 2022
1 parent 3dde2ce commit a817c48
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions components/site/src/link_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,26 @@ 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();
full_path.push("content");
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
// I don't think this is supported by zola so nothing should be broken
// Will also prevent having a section like content/_index.foobar/_index.md
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))
}
Expand Down
2 changes: 1 addition & 1 deletion test_site_i18n/content/_index.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title = "Accueil"
+++

Page d'accueil
Page d'accueil. [Notre blog](@/blog/_index.fr.md)
2 changes: 1 addition & 1 deletion test_site_i18n/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title = "Home"
+++

Homepage
Homepage. [Our blog](@/blog/_index.md)

0 comments on commit a817c48

Please sign in to comment.