Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Handle unspecified siteOrigin #81

Merged
merged 4 commits into from
Jul 17, 2017

Conversation

jfurrow
Copy link
Contributor

@jfurrow jfurrow commented Jul 13, 2017

If a user doesn't specify siteOrigin, then Batfish will now do the following:

  • Throw an error when using prefixUrl.absolute
  • Skip sitemap generation and display an explanatory message

I also modified lib/generate-sitemap.js. I added a try/catch block to fix promise resolution, because it turns out the sitemap-static package doesn't accept a callback (check out the function).

Closes #43

@davidtheclark 👀

sitemapStatic(
sitemapWriter,
{
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that try-catch is not going to work here, either. On closer inspection, I think we'll have to rely on sitemapWriter emitting its stream events. We should add sitemapWriter.on('error', reject) and sitemapWriter.on('finish', () => resolve()), I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, done!

Is there a reason you used the anonymous function wrapper in your example? Just curious, I wrote it as follows, but I can change it!

sitemapWriter.on('error', reject);
sitemapWriter.on('finish', resolve);

Copy link
Contributor

Choose a reason for hiding this comment

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

The only reason I had in mind was strict control over the value with which the Promise will resolve. With () => resolve() we can say that this function returns a Promise that resolves with undefined. With just resolve, I'm not exactly sure what it will resolve with — would have to check the Node docs — and I'm not sure it'd be valuable to the consumer of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! I updated it.

@davidtheclark
Copy link
Contributor

Interested in sending a PR to sitemap-static for fixing the docs in https://github.com/tmcw/sitemap-static#library-api?

Copy link
Contributor

@davidtheclark davidtheclark left a comment

Choose a reason for hiding this comment

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

Other than that stream-related trickery, looks great 👍

@davidtheclark davidtheclark merged commit 9d5ef6f into master Jul 17, 2017
@davidtheclark davidtheclark deleted the furrow/43/handle-undefined-siteOrigin branch July 17, 2017 17:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is siteOrigin required?
2 participants