[
  {
    "path": ".gitignore",
    "content": "node_modules\n"
  },
  {
    "path": "Dockerfile",
    "content": "FROM node:12-alpine\nCOPY package* ./\nRUN npm install -g foreman && npm install\nCOPY . .\nEXPOSE 5000\nCMD [\"nf\", \"start\"]\n"
  },
  {
    "path": "Procfile",
    "content": "web: node web.js"
  },
  {
    "path": "README.md",
    "content": "# Lorem RSS\n\nGenerates RSS feeds with content updated at regular intervals. I wrote this to\nanswer a [question I asked on Stack Overflow](http://stackoverflow.com/questions/18202048/are-there-any-constantly-updating-rss-feed-services-to-use-for-testing-or-just).\n\n## API\n\nVisit [http://lorem-rss.herokuapp.com/feed](http://lorem-rss.herokuapp.com/feed), with the following optional parameters:\n\n*   _unit_: one of second, minute, day, month, or year\n*   _interval_: an integer to repeat the units at. For seconds and minutes this interval must evenly divide 60, for month it must evenly divide 12, and for day and year it can only be 1.\n*   _length_: an integer that determines the number of items in the feed. Must be greater or equal to 0 and smaller or equal to 1000. Defaults to 10 items.\n\n## Examples\n\n*   The default, updates once a minute, with 10 entries: [/feed](http://lorem-rss.herokuapp.com/feed)\n*   Update every second instead of minute: [/feed?unit=second](http://lorem-rss.herokuapp.com/feed?unit=second)\n*   Update every 30 seconds: [/feed?unit=second&interval=30](http://lorem-rss.herokuapp.com/feed?unit=second&interval=30)\n*   Update once a day: [/feed?unit=day](http://lorem-rss.herokuapp.com/feed?unit=day)\n*   Update every 6 months: [/feed?unit=month&interval=6](http://lorem-rss.herokuapp.com/feed?unit=month&interval=6)\n*   Update once a year: [/feed?unit=year](http://lorem-rss.herokuapp.com/feed?unit=year)\n*   Default feed with 42 entries: [/feed?length=42\"](http://lorem-rss.herokuapp.com/feed?length=42)\n*   **Invalid example:** update every 7 minutes (does not evenly divide 60): [/feed?unit=minute&interval=7](http://lorem-rss.herokuapp.com/feed?unit=minute&interval=7)\n\n## Running locally\n\nThe project contains a Dockerfile that can be used to run Lorem RSS locally. Build via:\n\n```\ndocker build . -t lorem-rss\n```\n\nRun via:\n\n```\ndocker run --rm -it -p 5000:5000 lorem-rss\n```\n\nWith thanks given to [eelkevdbos](https://github.com/eelkevdbos), who contributed the Dockerfile.\n\n## Copyright\n\n### The feed and documentation\n\nLicensed by Michael Bertolacci under a Creative Commons Attribution 3.0 Unported License.\n\n### The code\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Michael Bertolacci\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"lorem-rss\",\n  \"version\": \"0.0.1\",\n  \"description\": \"\",\n  \"main\": \"web.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"author\": \"\",\n  \"license\": \"BSD\",\n  \"dependencies\": {\n    \"crypto\": \"~0.0.3\",\n    \"express\": \"^4.18.2\",\n    \"lodash\": \"^4.17.21\",\n    \"lorem-ipsum\": \"~0.1.1\",\n    \"moment\": \"^2.29.4\",\n    \"morgan\": \"^1.9.1\",\n    \"rss\": \"^1.2.2\",\n    \"seed-random\": \"~1.0.1\"\n  }\n}\n"
  },
  {
    "path": "web.coffee",
    "content": "###\nThe MIT License (MIT)\n\nCopyright (c) 2013 Michael Bertolacci\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n###\n\nexpress = require 'express'\nRSS = require 'rss'\nmoment = require 'moment'\n_ = require 'lodash'\nmorgan = require 'morgan'\n\nloremIpsum = require 'lorem-ipsum'\nseedRandom = require 'seed-random'\ncrypto = require 'crypto'\n\napp = express()\n\napp.use morgan('combined')\n\nunits = {\n    second: {\n        nextUp: 'minute',\n        mustDivide: 60\n    }\n    minute: {\n        nextUp: 'hour'\n        mustDivide: 60\n    }\n    hour: {\n        nextUp: 'day'\n        mustDivide: 24\n    }\n    day: {\n        nextUp: 'year'\n        mustDivide: 1\n    }\n    month: {\n        nextUp: 'year'\n        mustDivide: 12\n    }\n    year: {\n        mustDivide: 1\n    }\n}\n\ngetNearest = (interval, unit) ->\n    if interval == 1\n        return moment().utc().startOf(unit)\n    else\n        unitOptions = units[unit]\n        if unitOptions.mustDivide % interval != 0\n            throw \"When using #{unit}s the interval must divide #{unitOptions.mustDivide}\"\n\n        now = moment().utc()\n        returnDate = now.clone().startOf(unitOptions.nextUp || unit)\n\n        returnDate[unit](now[unit]() - now[unit]() % interval)\n\n        return returnDate\n\napp.get '/', (request, response) ->\n    response.send \"\"\"\n    <!DOCTYPE html>\n    <html>\n    <head>\n        <meta charset=\"utf-8\">\n        <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n        <title>Lorem RSS</title>\n        <meta name=\"description\" content=\"Web service that generates lorem ipsum RSS feeds\">\n\n        <link rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/foundation/4.2.3/css/normalize.min.css\">\n        <link rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/foundation/4.2.3/css/foundation.min.css\">\n\n        <style type=\"text/css\">\n            ul.indent {\n                position: relative;\n                left: 20px;\n            }\n        </style>\n    </head>\n    <body>\n        <div class=\"row\">\n            <div class=\"large-12 columns\">\n                <h1>Lorem RSS</h1>\n                <p>\n                    Generates RSS feeds with content updated at regular intervals. I wrote this to\n                    answer a <a href=\"http://stackoverflow.com/questions/18202048/are-there-any-constantly-updating-rss-feed-services-to-use-for-testing-or-just\">question I asked on Stack Overflow</a>.\n                </p>\n                <p>\n                    The code for this service is <a href=\"https://github.com/mbertolacci/lorem-rss\">available on GitHub</a>.\n                </p>\n                <h2>API</h2>\n                <p>\n                    Visit <a href=\"/feed\">/feed</a>, with the following optional parameters:\n                </p>\n                <ul class=\"disc indent\">\n                    <li>\n                        <em>unit</em>: one of second, minute, day, month, or year\n                    </li>\n                    <li>\n                        <em>interval</em>: an integer to repeat the units at.\n                        For seconds and minutes this interval must evenly divide 60,\n                        for month it must evenly divide 12, and for day and year it\n                        can only be 1.\n                    </li>\n                    <li>\n                        <em>length</em>: an integer that determines the number of items in the feed.\n                        Must be greater or equal to 0 and smaller or equal to 1000. Defaults to 10 items.\n                    </li>\n                </ul>\n                <h2>Examples</h2>\n                <ul class=\"disc indent\">\n                    <li>\n                        The default, updates once a minute, with 10 entries: <a href=\"/feed\">/feed</a>\n                    </li>\n                    <li>\n                        Update every second instead of minute: <a href=\"/feed?unit=second\">/feed?unit=second</a>\n                    </li>\n                    <li>\n                        Update every 30 seconds: <a href=\"/feed?unit=second&interval=30\">/feed?unit=second&interval=30</a>\n                    </li>\n                    <li>\n                        Update once a day: <a href=\"/feed?unit=day\">/feed?unit=day</a>\n                    </li>\n                    <li>\n                        Update every 6 months: <a href=\"/feed?unit=month&interval=6\">/feed?unit=month&interval=6</a>\n                    </li>\n                    <li>\n                        Update once a year: <a href=\"/feed?unit=year\">/feed?unit=year</a>\n                    </li>\n                    <li>\n                        Default feed with 42 entries: <a href=\"/feed?length=42\">/feed?length=42</a>\n                    </li>\n                    <li>\n                        <strong>Invalid example:</strong>\n                        update every 7 minutes (does not evenly divide 60):\n                        <a href=\"/feed?unit=minute&interval=7\">/feed?unit=minute&interval=7</a>\n                    </li>\n                </ul>\n                <hr/>\n                <p class=\"copyright\">\n                    <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/deed.en_US\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"http://i.creativecommons.org/l/by/3.0/88x31.png\" /></a><br /><span xmlns:dct=\"http://purl.org/dc/terms/\" href=\"http://purl.org/dc/dcmitype/Text\" property=\"dct:title\" rel=\"dct:type\">Lorem RSS</span> (this page and the feeds generated) by <span xmlns:cc=\"http://creativecommons.org/ns#\" property=\"cc:attributionName\">Michael Bertolacci</span> are licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/deed.en_US\">Creative Commons Attribution 3.0 Unported License</a>.\n                </p>\n            </div>\n        </div>\n    </body>\n</html>\n    \"\"\"\n\n\napp.get '/feed', (request, response) ->\n    if request.query.interval?\n        interval = parseInt request.query.interval\n    else\n        interval = 1\n\n    if not interval\n        response.send(500, \"Interval must be an integer\")\n        return\n    if interval <= 0\n        response.send(500, \"Interval must be greater than 0\")\n        return\n\n    unit = request.query.unit || 'minute'\n\n    if not units[unit]\n        response.send(500, \"Unit must be one of #{_.keys(units).join(', ')}\")\n        return\n\n    length = request.query.length || 10\n\n    if length < 0 or length > 1000\n        response.send(500, \"Length must be greater or equal to 0 and smaller or equal to 1000\")\n        return\n\n    pubDate = getNearest(interval, unit)\n\n    feed = new RSS({\n        title: \"Lorem ipsum feed for an interval of #{interval} #{unit}s with #{length} item(s)\",\n        description: 'This is a constantly updating lorem ipsum feed'\n        site_url: 'http://example.com/',\n        copyright: 'Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.',\n        ttl: Math.ceil(moment.duration(interval, unit).asMinutes()),\n        pubDate: pubDate.clone().toDate()\n    })\n\n    pubDate = getNearest(interval, unit)\n\n    for i in [0...length]\n        feed.item {\n            title: \"Lorem ipsum #{pubDate.format()}\",\n            description: loremIpsum(\n                random: seedRandom(pubDate.unix())\n            )\n            url: \"http://example.com/test/#{pubDate.format('X')}\"\n            author: 'John Smith',\n            date: pubDate.clone().toDate()\n        }\n        pubDate = pubDate.subtract(interval, unit)\n\n    etagString = feed.pubDate + interval + unit\n\n    response.set 'Content-Type', 'application/rss+xml'\n    response.set 'ETag', \"\\\"#{crypto.createHash('md5').update(etagString).digest(\"hex\");}\\\"\"\n    response.send feed.xml()\n\n\nport = process.env.PORT || 5000;\n\napp.listen port, () ->\n  console.log(\"Listening on \" + port);\n"
  },
  {
    "path": "web.js",
    "content": "// Generated by CoffeeScript 2.5.1\n(function() {\n  /*\n  The MIT License (MIT)\n\n  Copyright (c) 2013 Michael Bertolacci\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n  */\n  var RSS, _, app, crypto, express, getNearest, loremIpsum, moment, morgan, port, seedRandom, units;\n\n  express = require('express');\n\n  RSS = require('rss');\n\n  moment = require('moment');\n\n  _ = require('lodash');\n\n  morgan = require('morgan');\n\n  loremIpsum = require('lorem-ipsum');\n\n  seedRandom = require('seed-random');\n\n  crypto = require('crypto');\n\n  app = express();\n\n  app.use(morgan('combined'));\n\n  units = {\n    second: {\n      nextUp: 'minute',\n      mustDivide: 60\n    },\n    minute: {\n      nextUp: 'hour',\n      mustDivide: 60\n    },\n    hour: {\n      nextUp: 'day',\n      mustDivide: 24\n    },\n    day: {\n      nextUp: 'year',\n      mustDivide: 1\n    },\n    month: {\n      nextUp: 'year',\n      mustDivide: 12\n    },\n    year: {\n      mustDivide: 1\n    }\n  };\n\n  getNearest = function(interval, unit) {\n    var now, returnDate, unitOptions;\n    if (interval === 1) {\n      return moment().utc().startOf(unit);\n    } else {\n      unitOptions = units[unit];\n      if (unitOptions.mustDivide % interval !== 0) {\n        throw `When using ${unit}s the interval must divide ${unitOptions.mustDivide}`;\n      }\n      now = moment().utc();\n      returnDate = now.clone().startOf(unitOptions.nextUp || unit);\n      returnDate[unit](now[unit]() - now[unit]() % interval);\n      return returnDate;\n    }\n  };\n\n  app.get('/', function(request, response) {\n    return response.send(`<html><head> <meta charset=\"utf-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <title>Lorem RSS</title> <meta name=\"description\" content=\"Web service that generates lorem ipsum RSS feeds\"> <link rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/foundation/4.2.3/css/normalize.min.css\"> <link rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/foundation/4.2.3/css/foundation.min.css\"> <style type=\"text/css\"> ul.indent{position: relative; left: 20px;}</style></head><body> <div class=\"row\"> <div class=\"large-12 columns\"> <h1>Lorem RSS</h1> <p> Generates RSS feeds with content updated at regular intervals. I wrote this to answer a <a href=\"http://stackoverflow.com/questions/18202048/are-there-any-constantly-updating-rss-feed-services-to-use-for-testing-or-just\">question I asked on Stack Overflow</a>. </p><p> The code for this service is <a href=\"https://github.com/mbertolacci/lorem-rss\">available on GitHub</a>. </p><h2>API</h2> <p> Visit <a href=\"/feed\">/feed</a>, with the following optional parameters: </p><ul class=\"disc indent\"> <li> <em>unit</em>: one of second, minute, day, month, or year </li><li> <em>interval</em>: an integer to repeat the units at. For seconds and minutes this interval must evenly divide 60, for month it must evenly divide 12, and for day and year it can only be 1. </li><li> <em>length</em>: an integer that determines the number of items in the feed. Must be greater or equal to 0 and smaller or equal to 1000. Defaults to 10 items. </li></ul> <h2>Examples</h2> <ul class=\"disc indent\"> <li> The default, updates once a minute, with 10 entries: <a href=\"/feed\">/feed</a> </li><li> Update every second instead of minute: <a href=\"/feed?unit=second\">/feed?unit=second</a> </li><li> Update every 30 seconds: <a href=\"/feed?unit=second&interval=30\">/feed?unit=second&interval=30</a> </li><li> Update once a day: <a href=\"/feed?unit=day\">/feed?unit=day</a> </li><li> Update every 6 months: <a href=\"/feed?unit=month&interval=6\">/feed?unit=month&interval=6</a> </li><li> Update once a year: <a href=\"/feed?unit=year\">/feed?unit=year</a> </li><li> Default feed with 42 entries: <a href=\"/feed?length=42\">/feed?length=42</a> </li><li> <strong>Invalid example:</strong> update every 7 minutes (does not evenly divide 60): <a href=\"/feed?unit=minute&interval=7\">/feed?unit=minute&interval=7</a> </li></ul> <hr/> <p class=\"copyright\"> <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/deed.en_US\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"http://i.creativecommons.org/l/by/3.0/88x31.png\"/></a><br/><span xmlns:dct=\"http://purl.org/dc/terms/\" href=\"http://purl.org/dc/dcmitype/Text\" property=\"dct:title\" rel=\"dct:type\">Lorem RSS</span> (this page and the feeds generated) by <span xmlns:cc=\"http://creativecommons.org/ns#\" property=\"cc:attributionName\">Michael Bertolacci</span> are licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/deed.en_US\">Creative Commons Attribution 3.0 Unported License</a>. </p></div></div></body></html>`);\n  });\n\n  app.get('/feed', function(request, response) {\n    var etagString, feed, i, interval, j, length, pubDate, ref, unit;\n    if (request.query.interval != null) {\n      interval = parseInt(request.query.interval);\n    } else {\n      interval = 1;\n    }\n    if (!interval) {\n      response.send(500, \"Interval must be an integer\");\n      return;\n    }\n    if (interval <= 0) {\n      response.send(500, \"Interval must be greater than 0\");\n      return;\n    }\n    unit = request.query.unit || 'minute';\n    if (!units[unit]) {\n      response.send(500, `Unit must be one of ${_.keys(units).join(', ')}`);\n      return;\n    }\n    length = request.query.length || 10;\n    if (length < 0 || length > 1000) {\n      response.send(500, \"Length must be greater or equal to 0 and smaller or equal to 1000\");\n      return;\n    }\n    pubDate = getNearest(interval, unit);\n    feed = new RSS({\n      title: `Lorem ipsum feed for an interval of ${interval} ${unit}s with ${length} item(s)`,\n      description: 'This is a constantly updating lorem ipsum feed',\n      site_url: 'http://example.com/',\n      copyright: 'Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.',\n      ttl: Math.ceil(moment.duration(interval, unit).asMinutes()),\n      pubDate: pubDate.clone().toDate()\n    });\n    pubDate = getNearest(interval, unit);\n    for (i = j = 0, ref = length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {\n      feed.item({\n        title: `Lorem ipsum ${pubDate.format()}`,\n        description: loremIpsum({\n          random: seedRandom(pubDate.unix())\n        }),\n        url: `http://example.com/test/${pubDate.format('X')}`,\n        author: 'John Smith',\n        date: pubDate.clone().toDate()\n      });\n      pubDate = pubDate.subtract(interval, unit);\n    }\n    etagString = feed.pubDate + interval + unit;\n    response.set('Content-Type', 'application/rss+xml');\n    response.set('ETag', `\\\"${crypto.createHash('md5').update(etagString).digest(\"hex\")}\\\"`);\n    return response.send(feed.xml());\n  });\n\n  port = process.env.PORT || 5000;\n\n  app.listen(port, function() {\n    return console.log(\"Listening on \" + port);\n  });\n\n}).call(this);\n"
  }
]