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

Bugfix check links i18n (close #1694) #1780

Merged
merged 3 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the root section starts with /? I can't remember

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point i removed the / as initially suggested on #1694. I added a note in the docs that any page whose path contains _index. is unsupported.

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)
4 changes: 4 additions & 0 deletions test_site_i18n/content/blog/_index.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ title = "Mon blog"
sort_by = "date"
insert_anchors = "right"
+++

[Dernières nouvelles](#news)

# News {#news}