There’s something I love about web generators. Not the ones that make power, but ones that power the creation of stuff. The stuff of the useless web.
Everything from the tombstones to metal band names to church signs to luchador names. Maybe it’s because people make them for no other reason than because they can.
Then there is Lorem Ipsum the sites that generate random chunks of text you can use as placeholders for designing content or web sites:
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
There is a whole universe of different variations; I love the collection at Meet the Ipsums.
My go to has been Bacon Ipsum which is hosted in WordPress and even has an API. As much as I love bacon, it does present problems for vegans and those that keep kosher.
Last week I was working on some templates for content that is part of the Creative Commons Certification project. My working template had Bacon Ipsum in it.
So I said to myself, “Self…” No seriously, I wondered what it would take to build my own Lorem ipsum generator based on something from Creative Commons. To jump ahead to the demo, meet CC IP-SUM:
It generates a specified number of paragraphs (1-10) with (1-10) random sentences, all of which are taken from the Creative Commons FAQ. Like:
Modifying licenses creates friction that confuses users and undermines the key benefits of public, standardized licenses. What if I have received CC-licensed material with additional restrictions? CC does not recommend use of its NonCommercial (NC) or NoDerivatives (ND) licenses on databases intended for scholarly or scientific use.
Version 4.0 of CC’s Attribution-ShareAlike (BY-SA) license is one-way compatible with the GNU General Public License version 3.0 (GPLv3). How should I decide which license to choose? You may license your copyright or distribute your work under more than one set of terms.
Applying a Creative Commons license to your material is a serious decision. The answer will depend on the law in the relevant jurisdiction. For more details about adaptations in the database context, see the Data FAQ.
I did some looking first- I found Lorem Ipsum generator code that was in PHP, used databases. A lot of them are running with WordPress front ends, like Hipster Ipsum that is fed by a HipsterJesus API. Woah.
I was looking for something way simpler, something that would run from static HTML (e.g. could run from GitHub Pages). So I took my dog for a walk and thought it out in my head.
All mine needs is a JavaScript external file with a single array in it- each item a sentence that ends in a “.” and a space. The logic is a front form with fields for the number of paragraphs and second one for the number of sentences per paragraph to use. Then it’s just some jQuery to react to changes in the fields and/or a button click.
function get_sum( lines, paragraphs ) { // a place to put the generated stuff var stuff = ''; // loop over the number of desired paragraphs for (i = 0; i < paragraphs; i++) { // open that paragraph stuff += ''; // now loop for the number of desired sentences for (j = 0; j < lines; j++) { // append a random line from the source array stuff += all_lines[Math.floor(Math.random()*all_lines.length)]; } // close that paragraph stuff += '
'; } // update the div in our page $("#lorem").html(stuff); }
The construction logic is simple; do one loop for each of the desired numbers of paragraphs. In each, start with a <p>
tag, then run an inner loop for the number of sentences per paragraph. In that loop we pull a random element from the array and append it to our output string. Then end it with a closing </p>
tag. When all that is done, we use jQuery to update the html content of a specified div.
I first do this up as completely unstyled HTML, so I can get the function first. In fact, I have posted this as it’s own GitHub repo, so someone else can fork and make their own.
For my test/demo purpose, I exported all the titles of my blog posts, in my case using a bit of MySQL wrangling
SELECT `post_title` FROM `wp_posts` WHERE `post_status` = 'publish' AND `post_type` = 'post' LIMIT 0,18446744073709551615
And saved the results as a CSV file.
That part is totally not necessary in general (I’m just showing off), for the CC one I just copied the text from the web page and did some text editing to get it in the right format (replaced all '. '
end of sentence markers with '", /n"'
to wrap in quotes and separated by commas. This is the tedious part, you have to make sure there are no quotes in the real content, and sometimes you get headings or sentence fragments. If the site does not work, it almost means a problematic character. The inspector is your friend.
And voila:
What it needs is:
index.html
– the main pageassets/js/jquery.min.js
– a local copy of jQueryassets/js/ipso.js
– the code that interacts with the form and generates the stuff. It need not even be touched as long as you use the same form fields as in the demo.assets/js/cogdogblog.js
– the content source, in this case it’s just my stuff as an array. You can make your own data files, or have several. You just need to make sure you reference the right script in the bottom ofindex.html
Once running, I made it pretty… using the CC Licensed HTML5up TXT theme. I loooooove these thems.
In my first effort I used the text from a few of the Creative Commons license deeds, so you get things like:
For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material.
Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
A notice that refers to the disclaimer of warranties. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
It’s a bit of a legal language mouth full of marbles; I left a copy of this version running for purposes of making this link. Then I switched it to the current version that uses the text from the Creative Commons FAQ.
Once I started, I could not stop generating.
It’s ultimate use? Meh.
I did it because I can.
Featured Image: Public Domain image from Wikimedia Commons
Even though the site has no domain it is a perfect follow up to the previous post and a hymn to itch scratching. Like a dog with internet fleas.