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

Integration Tests and handling for alternates and canonical #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SteveGZr
Copy link

I have added the ability to specify language alternates and the canonical URL, so that they can be included in the sitemap.
I have also added integration tests for generating the sitemaps.

Please review the changes made and notify me if anything doesn't fit correctly. I'll be happy to make any necessary adjustments accordingly.

let mut unique_hreflangs = HashSet::new();
for alternate in &alternates {
if !unique_hreflangs.insert(&alternate.hreflang) {
return Err(UrlError::DuplicateAlternateHreflangs(
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of manually checking for uniqueness within a Vec, could pub alternates: Option<Vec<Alternate>>, be refactored to be pub alternates: Option<Set<Alternate>>, from the beginning?

Copy link
Author

Choose a reason for hiding this comment

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

Going to take a look at that.

src/url.rs Outdated Show resolved Hide resolved
@@ -100,6 +113,22 @@ impl Url {
}
};

let alternates: Option<Vec<Alternate>> = match alternates {
None => None,
Some(alternates) => {
Copy link
Owner

@goddtriffin goddtriffin Jun 26, 2023

Choose a reason for hiding this comment

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

In this Some(alternates) condition, I like to check if alternates.is_empty() and return None if so. This helps limit the total number of ways to represent "I have zero alternates".

Copy link
Author

Choose a reason for hiding this comment

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

Going to take a look at that.

@goddtriffin
Copy link
Owner

Thanks for writing these great integration tests!

@SteveGZr
Copy link
Author

Sorry it took me so long to take another look at this. I will make the according changes in the next weeks.

@goddtriffin
Copy link
Owner

Take your time - I appreciate your work!

self
}

pub fn push_alternate(&mut self, hreflang: String, href: String) -> &mut Self {
Copy link

Choose a reason for hiding this comment

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

Can you use impl ToString instead of String for hreflang and href here? This makes for a nicer interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants