{"id":16630104,"url":"https://github.com/codecalm/jekyll-random","last_synced_at":"2025-03-21T15:31:21.904Z","repository":{"id":56878748,"uuid":"124246507","full_name":"codecalm/jekyll-random","owner":"codecalm","description":"A Jekyll plugin that generates pseudo-random data.","archived":false,"fork":false,"pushed_at":"2019-11-29T11:03:49.000Z","size":11,"stargazers_count":17,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T03:47:53.530Z","etag":null,"topics":["jekyll","jekyll-filters","jekyll-plugin"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codecalm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T14:18:55.000Z","updated_at":"2024-01-22T17:14:25.000Z","dependencies_parsed_at":"2022-08-20T23:10:21.300Z","dependency_job_id":null,"html_url":"https://github.com/codecalm/jekyll-random","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecalm%2Fjekyll-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecalm%2Fjekyll-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecalm%2Fjekyll-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecalm%2Fjekyll-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codecalm","download_url":"https://codeload.github.com/codecalm/jekyll-random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244822639,"owners_count":20516144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jekyll","jekyll-filters","jekyll-plugin"],"created_at":"2024-10-12T04:45:01.643Z","updated_at":"2025-03-21T15:31:21.520Z","avatar_url":"https://github.com/codecalm.png","language":"Ruby","readme":"# Jekyll-Random\n\nA Jekyll plugin that generates _pseudo-random_ data. Very useful when you want to generate a large amount of random data. The plugin is prepared to work with other Jekyll plugins like `jekyll-timeago` or `jekyll-humanize`.\n\n**The data is generated based on index, so that every time when you run `jekyll build`, the generated data is the same.**\n\n[![Gem Version](https://badge.fury.io/rb/jekyll-random.svg)](https://badge.fury.io/rb/jekyll-random)\n\n\n## Installation\n\n1. Add the following to your site's `Gemfile`:\n\n  ```ruby\n  gem 'jekyll-random'\n  ```\n\n2. Add the following to your site's `_config.yml`:\n\n  ```yml\n  plugins:\n    - jekyll-random\n  ```\n\nIf you are using a Jekyll version less than `3.5.0`, use the `gems` key instead of `plugins`.\n\n### Manual installation\n\nSimply download the `lib/jekyll-random.rb` file and place it in the `_plugins` directory of your Jekyll site.\n\n\n## Usage\n\nEach of the methods in the file presents an available Fluid type filter to be used in Jekyll templates. Thanks to this you can manipulate the generated data.\n\n### random_number(_index_, _min=0_, _max=100_, _round=0_)\n\nReturn a number between _min_ and _max_ based on _index_. By default it returns a number between 0 and 100.\n\n```ruby\n{% for i in (1..100) %}\n  {{ i }} - {{ forloop.index | random_number: 0, 10 }}\n{% endfor %}\n```\n\nThe code above returns random numbers like:\n\n```\n1 - 6\n2 - 1\n3 - 6\n4 - 8\n5 - 4\n6 - 7\n7 - 1\n...\n```\n\nYou can also change the `round` parameter to generate fractions:\n\n```ruby\n{% for i in (1..100) %}\n  {{ i }} - {{ forloop.index | random_number: 0, 100, 2 }}\n{% endfor %}\n```\n\nThe result of code above:\n\n```\n1 - 42.98\n2 - 0.08\n3 - 96.59\n4 - 6.81\n5 - 36.91\n6 - 7.06\n7 - 80.38\n...\n```\n\n### random_item(_index_, _items_)\n\nReturn random item from _items_ array based on _index_. _items_ can be array, collection, or data file. \n\n```ruby\n{% assign colors = 'red|green|blue|yellow|orange' | split: '|' %}\n{% for i in (1..100) %}\n  {{ i }} - {{ forloop.index | random_item: colors }}\n{% endfor %}\n```\n\nThe results:\n\n```\n1 - blue\n2 - blue\n3 - red\n4 - yellow\n5 - yellow\n6 - red\n7 - red\n8 - yellow\n...\n```\n\n### random_date(_index_, _start_date=false_, _end_date=false_)\n\nReturn random date between _start_date_ and _end_date_. By default, it returns the date between 100 days ago and now. Returned date you can format by `date` filter to get expected result. This filter is useful when you generate birth date or register date. \n\n```ruby\n{% for i in (1..100) %}\n  {{ i }} - {{ forloop.index | random_date: \"2010-01-01\", \"2018-01-01\" | date: '%B %d, %Y' }}\n{% endfor %}\n```\n\n```\n1 - May 23, 2016\n2 - January 31, 2017\n3 - August 10, 2014\n4 - December 08, 2016\n5 - January 22, 2016\n6 - November 16, 2015\n7 - June 09, 2013\n...\n```\n\n### random_date_ago(_index_, _days_ago=100_)\n\nThis filter works similar to `random_date`, but returns random date between today and date _days_ago_ ago. By default return date between now and 100 days ago. It is helpful to generate random data like last login date. If you additionally use the `jekyll-timeago` filter you can get date in _2 days ago_ format.\n\n```ruby\n{% for i in (1..100) %}\n  {{ i }} - {{ forloop.index | random_date_ago: 10 | timeago }}\n{% endfor %}\n```\n\nResults:\n\n```\n1 - 6 days ago\n2 - yesterday\n3 - 6 days ago\n4 - 1 week ago\n5 - 4 days ago\n6 - 1 week ago\n7 - yesterday\n...\n```\n\nYou can also change _days_ago_ parameter to negative number like `{{ forloop.index | random_date_ago: -10 | timeago }}` to get date in future:\n\n```\n1 - today\n2 - in 1 week\n3 - tomorrow\n4 - tomorrow\n5 - in 2 days\n6 - in 2 days\n7 - in 4 days\n8 - in 5 days\n9 - in 1 week\n...\n```\n\n## Generate data based on the same index\n\nSometimes you want to generate data in the same row with the same parameters. Because this plugin generate pseudo-random data every returned number will be the same:\n\n```ruby\n{% for i in (1..5) %}\n  {{ i }} - {{ forloop.index | random_number }}, {{ forloop.index | random_number }}, {{ forloop.index | random_number }}\n{% endfor %}\n```\n\nThe above code returns a code that does not meet our expectations, because every time returns the same data:\n\n```\n1 - 42, 42, 42\n2 - 0, 0, 0\n3 - 96, 96, 96\n4 - 6, 6, 6\n5 - 36, 36, 36\n...\n```\n\nTo fix it, simply add a random number to `index` parameter: `{{ forloop.index | plus: 156 | random_number }}`. Thanks to this the results will be different to every index.\n\n```\n1 - 42 - 47 - 55\n2 - 0 - 87 - 96\n3 - 96 - 15 - 81\n4 - 6 - 12 - 59\n5 - 36 - 8 - 20\n...\n```\n\n## Sample code\n\nTo see how useful this plugin is, try to run the code below. Remember to set few random data in `_config.yml` file:\n\n```yml\nusers:\n  - name: Tate\n    surname: Nesfield\n    email: tnesfield0@scribd.com\n  - name: Thelma\n    surname: Muirden\n    email: tmuirden1@google.com\n  ...\n  \ncommits:\n  - Push poorly written test can down the road another ten years\n  - This will definitely break in 2020 (TODO)\n  ...\n```\n\n_index.html_\n\n```html\n{% assign colors = 'red|green|blue|yellow|orange' | split: '|' %}\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eID\u003c/th\u003e\n        \u003cth\u003eName\u003c/th\u003e\n        \u003cth\u003eEmail\u003c/th\u003e\n        \u003cth\u003ePercentage\u003c/th\u003e\n        \u003cth\u003eAge\u003c/th\u003e\n        \u003cth\u003eStatus\u003c/th\u003e\n        \u003cth\u003eRegister date\u003c/th\u003e\n        \u003cth\u003eLast login\u003c/th\u003e\n        \u003cth\u003eCommit\u003c/th\u003e\n    \u003c/tr\u003e\n    {% for user in site.users %}\n    \u003ctr\u003e\n        \u003ctd\u003e{{ forloop.index }}\u003c/td\u003e\n        \u003ctd\u003e{{ user.name }} {{ user.surname }}\u003c/td\u003e\n        \u003ctd\u003e{{ user.email }}\u003c/td\u003e\n        \u003ctd\u003e{{ forloop.index | random_number }}%\u003c/td\u003e\n        \u003ctd\u003e{{ forloop.index | random_number: 25, 55 }}\u003c/td\u003e\n        \u003ctd\u003e{{ forloop.index | random_item: colors }}\u003c/td\u003e\n        \u003ctd\u003e{{ forloop.index | random_date: \"2010-01-01\", \"2018-01-01\" | date: '%B %d, %Y' }}\u003c/td\u003e\n        \u003ctd\u003e{{ forloop.index | random_date_ago: 10 | timeago }}\u003c/td\u003e\n        \u003ctd\u003e{{ site.commits[forloop.index] }}\u003c/td\u003e\n    \u003c/tr\u003e\n    {% endfor %}\n\u003c/table\u003e\n```\n\nResults:\n\n```\nID  Name                Email                        Percentage  Age  Status  Register date       Last login   Commit\n1   Tate Nesfield       tnesfield0@scribd.com        42%         31   blue    May 23, 2016        6 days ago   This will definitely break in 2020 (TODO)\n2   Thelma Muirden      tmuirden1@google.com         0%          50   green   January 31, 2017    yesterday    yet another quality commit\n3   Ros Rawstorne       rrawstorne2@furl.net         96%         37   red     August 10, 2014     6 days ago   fuckup.\n4   Marco Newburn       mnewburn3@eventbrite.com     6%          47   blue    December 08, 2016   1 week ago   some brief changes\n5   Tessie Lack         tlack4@nytimes.com           36%         33   green   January 22, 2016    4 days ago   herpderp (redux)\n6   Cinderella Illwell  cillwell5@mayoclinic.com     7%          28   red     November 16, 2015   1 week ago   PEBKAC\n7   Jermaine Marston    jmarston6@independent.co.uk  80%         40   green   June 09, 2013       yesterday    Hide those navs, boi!\n8   Harlan Oliveti      holiveti7@cam.ac.uk          83%         26   blue    May 31, 2013        2 days ago   I'm totally adding this to epic win. +300\n9   Lillis Riddler      lriddler8@de.vu              73%         27   green   July 31, 2011       1 week ago   Bit Bucket is down. What should I do now?\n10  Marlowe Rabson      mrabson9@wufoo.com           79%         31   green   October 08, 2013    3 days ago   This really should not take 19 minutes to build.\n11  Vera Doggart        vdoggarta@fastcompany.com    94%         36   red     July 28, 2014       6 days ago   This is why the cat shouldn't sit on my keyboard.\n12  Lari Webling        lweblingb@umn.edu            90%         39   red     April 29, 2013      3 days ago   The same thing we do every night, Pinky - try to take over the world!\n13  Annabela Apps       aappsc@lulu.com              8%          32   green   December 02, 2013   1 week ago   Does this work\n14  Hurlee Teaser       hteaserd@webeden.co.uk       44%         31   green   August 03, 2011     4 days ago   Some bugs fixed\n15  Natty Blois         nbloise@zdnet.com            0%          36   green   June 16, 2016       5 days ago   I was wrong...\n```\n\n## Development\n\nAny kind of feedback, bug report, idea or enhancement are really appreciated. To contribute, just fork the repo, hack on it and send a pull request.\n\n## License\n\nCopyright (c) Paweł Kuna. Jekyll-Random is released under the MIT License.\n\n## Contribute\n\n1. [Fork](https://github.com/codecalm/jekyll-random/fork) this repo.\n2. Create a branch `git checkout -b my_feature`\n3. Commit your changes `git commit -am \"Added Feature\"`\n4. Push to the branch `git push origin my_feature`\n5. Open a [Pull Request](https://github.com/codecalm/jekyll-random/pulls)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecalm%2Fjekyll-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecalm%2Fjekyll-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecalm%2Fjekyll-random/lists"}