JSRocksHQ / harmonic

The next static site generator
http://harmonicjs.com/
MIT License
282 stars 26 forks source link

Should not overwrite the existing RSS feed if nothing changed #147

Open UltCombo opened 9 years ago

UltCombo commented 9 years ago

Currently, if a new build is generated without any changes, the RSS's publication date still changes. I believe this is not good.

soapdog commented 9 years ago

Can we compute a hash or unique identifier for a build? As in building the site for the same files would result in the same hash being computed. This way we just compare the new build hash with the current build hash, if they are the same, no need to overwrite any RSS.

This hash can be computed concatenating all src/ files and calculating the md5 hash. Since this is a build step, it can be left for a gulp task.

What do you think?

UltCombo commented 9 years ago

@soapdog I guess that works, but isn't that overcomplicating things a bit? I was thinking about generating the RSS as usual (in memory), compare with the existing RSS (if any), and only overwrite if there are changes other than the publish date.

Only problem is that by the time we generate the RSS, the public dir has already been completely wiped, including the old RSS. I guess this is a big issue for any approach that we may take.

So, another approach would be to read the existing RSS (if any) before wiping out the public dir, so we can compare it with the new RSS and, if nothing changed besides the date, write the old RSS to disk. But this breaks down when there are multiple people deploying the site, as a second person may not have the public dir of the first person that deployed the site.

To solve this we would require to read a remote RSS (from the deployed site), but that's way too much effort and adds a requirement on supplying a deployment site URL config and add a dependency on having internet connection, plus slower build time due to the download. This is not good.

Unless we can think of something better, I guess it is better to leave this as is.

UltCombo commented 9 years ago

Actually, if we compute a hash (as you said) and save it to the harmonic.json (e.g. _lastBuildHash), then I guess we can make it work. :smile:

soapdog commented 9 years ago

Also comparing the RSS to see if everything remain the same but the date in non-trivial if you're doing it right by comparing node contents and attributes. Since Harmonic doesn't maintain a database of built data, its hard for it to detect if it is building the same things over and over or new things.

UltCombo commented 9 years ago

@soapdog Right. But we do have the posts and pages' data -- we could JSON.stringify and hash them.

soapdog commented 9 years ago

@UltCombo I like this! Let me try to build a POC...