ci: Change how we detect duplicate IDs for spec links
Starting with Matrix 1.11, the IDs are uniquified when generating the HTML rather than in the browser with JavaScript, so we need to check IDs that are already de-duplicated.
This commit is contained in:
parent
46781d70ef
commit
32d0e03575
@ -226,37 +226,36 @@ fn get_page_ids(url: &str) -> Result<HashMap<String, HasDuplicates>> {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let (id, has_duplicates) = uniquify_heading_id(id, &mut ids);
|
let has_duplicates = heading_id_has_duplicates(&id, &mut ids);
|
||||||
|
|
||||||
ids.insert(id, has_duplicates);
|
ids.insert(id, has_duplicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ids)
|
Ok(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make sure the ID is unique in the page, if not make it unique.
|
/// Check whether the given heading ID has duplicates in the given map.
|
||||||
///
|
///
|
||||||
/// This is necessary because Matrix spec pages do that in JavaScript, so IDs
|
/// This check is necessary because duplicates IDs have a number depending on their occurrence in a
|
||||||
/// are not unique in the source.
|
/// HTML page. If a duplicate ID is added, moved or removed from the spec, its number might change
|
||||||
///
|
/// from one version to the next.
|
||||||
/// This is a reimplementation of the algorithm used for the spec.
|
fn heading_id_has_duplicates(
|
||||||
///
|
id: &str,
|
||||||
/// See <https://github.com/matrix-org/matrix-spec/blob/6b02e393082570db2d0a651ddb79a365bc4a0f8d/static/js/toc.js#L25-L37>.
|
|
||||||
fn uniquify_heading_id(
|
|
||||||
mut id: String,
|
|
||||||
unique_ids: &mut HashMap<String, HasDuplicates>,
|
unique_ids: &mut HashMap<String, HasDuplicates>,
|
||||||
) -> (String, HasDuplicates) {
|
) -> HasDuplicates {
|
||||||
let base_id = id.clone();
|
// IDs that should be duplicates end with `-{number}`.
|
||||||
let mut counter: u16 = 0;
|
let Some((start, _end)) =
|
||||||
let mut has_duplicates = HasDuplicates::No;
|
id.rsplit_once('-').filter(|(_start, end)| end.chars().all(|c| c.is_ascii_digit()))
|
||||||
|
else {
|
||||||
|
return HasDuplicates::No;
|
||||||
|
};
|
||||||
|
|
||||||
while let Some(other_id_has_dup) = unique_ids.get_mut(&id) {
|
// Update the first duplicate ID, because it doesn't end with a number.
|
||||||
has_duplicates = HasDuplicates::Yes;
|
if let Some(other_id_has_dup) = unique_ids.get_mut(start) {
|
||||||
*other_id_has_dup = HasDuplicates::Yes;
|
*other_id_has_dup = HasDuplicates::Yes;
|
||||||
counter += 1;
|
|
||||||
id = format!("{base_id}-{counter}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(id, has_duplicates)
|
HasDuplicates::Yes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_link_err(error: &str, link: &SpecLink) {
|
fn print_link_err(error: &str, link: &SpecLink) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user