Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Forked from gaby-de-wilde/README.md
Last active August 27, 2017 15:00
Show Gist options
  • Save tarlepp/810d195039317f07035e33d41ac5a527 to your computer and use it in GitHub Desktop.
Save tarlepp/810d195039317f07035e33d41ac5a527 to your computer and use it in GitHub Desktop.
Even Shorter Syndication [ESS] Node.js module

The module returns the ESS and has 2 arguments:

1 - the link to the RSS or Atom feed described. 2 - An array of objects formatted like this:

[
  { pubDate: 1503674340000, title: "hello world"},
  { pubDate: 1503674220000, title: "foo"        },
  { pubDate: 1503674160000, title: "bar"        }
];

ESS is a very compact description of an RSS or Atom site feed.

It is structured like this:

buildTime, feedUrl, minutesBeforeBuild, titleDumbChecksum, minutesBeforeBuild, titleDumbChecksum, minutesBeforeBuild, titleDumbChecksum, minutesBeforeBuild, titleDumbChecksum

Where:

buildTime = The build time of the ESS in seconds (rounded down to be divisable by 60) feedUrl = A link to the RSS or Atom feed described by the ESS minutesBeforeBuild = The publication date in minutes before buildTime titleDumbChecksum = A very dumb checksum in case the feed has multiple publications sharing the same date

module.exports = function(rssUrl,items){
  var buildTimeMinutes = Math.floor(Date.now()/60000);
  return [ buildTimeMinutes*60, rssUrl ].concat(
    items.map(x=> [ '\n'+
      (buildTimeMinutes - Math.floor((x.pubDate*1)/60000)),
      [...x.title].reduce((a,b)=>a+b.charCodeAt(0)&255,0)].join()
    )
  ).join()
}
{  
"name":        "ess",  
"description": "",
"version":     "1.0.0",
"main":        "index.js",
"homepage":    "http://go-here.nl/ess-and-nno"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment