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 all 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
// 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))
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/documentation/content/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion test_site_i18n/content/_index.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
title = "Accueil"
+++

Page d'accueil
Page d'accueil. [Notre blog](@/blog/_index.fr.md)

[Lire notre description](#about)


# À propos {#about}
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}