-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(utils): add discoverValidSitemaps utility
#3339
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
base: master
Are you sure you want to change the base?
Conversation
barjin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm @foxt451 , thank you!
I'll let @janbuchar have a second look as the original author of this, but if it's a direct port from WCC, I think we can merge safely.
I have just these nits:
packages/utils/test/sitemap.test.ts
Outdated
| it('extracts sitemap from robots.txt', async () => { | ||
| nock('http://sitemap-discovery.com') | ||
| .get('/robots.txt') | ||
| .reply(200, 'Sitemap: http://sitemap-discovery.com/sitemap.xml') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this so the robots.txt-referenced sitemap is not the well-known /sitemap.xml? This example passes even if robots.txt is missing (see test below).
|
|
||
| /** | ||
| * Given a list of URLs, discover related sitemap files for these domains by checking the `robots.txt` file, | ||
| * the default `sitemap.xml` file and the URLs themselves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this doesn't mention sitemap.txt
Related to apify/apify-sdk-js#486. I'm developing generic sitemap scraper and it's going to share a big utility function (main chunk of logic) with wcc -
discoverValidSitemaps. I've asked @barjin if I could factor it out and he told this util could fit into crawlee. It's mainly copied from wcc, but to keep the dependencies unchanged, it's using got-scraping to check for url existence instead of impit (I think it doesn't matter for sitemaps), andurlExistsis inlined (until we don't add http client to these utils in v4 as @barjin told me). It's also turned into an async generator. Let me know if you see a better place for this util.