Lorem ipsum shortcode for Hugo?


#1

Requirement: In Ruby (I am moving from Middleman to Hugo) there are a number of wonderful plugins for generating Lorum Ipsum text, in any amount of paragraphs, words, headings, subheadings etc. ( https://loremipsum.io/plugins/ ) I might be wrong but there does not seem to be an equivalent for Hugo. I created a crude shortcode called Lorem to do just that and though it now has parameters returning differing lengths, my advanced abilities regarding sophisticated shortcodes in Hugo are basically zero.

Question: Is there anything like a Lorem shortcode or implementation out there for Hugo?

Suggested feature: It would be very useful if such a feature is included as a shortcode within Hugo.

Any pointers will be appreciated.


#2

I think your request, while useful, does not fit as a Hugo’s built-in shortcode. Those are supposed to be either widely used of help enforce consistency in the way certain aspect of the websites are implemented (opengraph etc…)

I would suggest you create a set of shortcodes and/or partials doing just that and bundle them in a “theme component”. This would allow any other Hugo user out there to easily add them to their project, use them in developement, and remove them once in production (as I suppose those will not be useful there)

If you need help building those shortcodes, please ask in the discourse, many would gladly welcome this shortcode bundle and help you I’m sure!


#3

Thanks, it makes sense.


#4

@casperl – You got me curious, and turns out the seq function comes in handy here.

Let’s say you wanted to generate 20 paragraphs of lorem text.

Usage:

{{< loremGen 20 >}}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse accumsan rutrum consectetur. Vivamus eu ex quis leo posuere convallis. Nunc laoreet velit sed ullamcorper mollis. Mauris porta consequat tortor aliquet maximus. Quisque sed purus condimentum orci sodales aliquam non vel tellus. Praesent lorem arcu, scelerisque a semper at, iaculis eget purus. Etiam ullamcorper orci a porttitor sodales. Nullam tincidunt nibh et hendrerit auctor. Quisque vitae quam ut lorem vehicula condimentum. In commodo cursus elit, non volutpat lectus sagittis non.</p>
{{</ loremGen >}}

Definition:

{{ $times := .Get 0 }}
{{ $lorem := .Inner }}

{{ range seq $times }}
  {{ $lorem | safeHTML }}
{{ end }}