My first bit production-racket
I just wrote my very first bit of racket code which actually runs somewhere. Want to find out what it is?
Well, it is a rather simple piece of code, and it helps me generating this very blog. If you visit this blog frequently, you may have noticed that the layout changed a bit. Chaning the layout was a thing I wanted to do for months and the adaptions I just did are exactly what I wanted to do all the time: Move the content in the center of the page, the lines are now shorter as the div in which the content lives got reduced in its width.
I also moved the tags and dates on the left of the articles, both on the index page and on the article pages. I really like that style. It wasn't that easy (for me as racket-newbie), because the blog engine I use (frog) has no method to insert a html-list of tags somewhere. So I coded it myself, right in the templates for the article and index pages.
Here's how I did that:
- First, I put everything into a subcontainer of the bootstrap layout. The date and tags (lets call it metadata) lives in a two-column-container to the left of the ten-column-container which holds the content
- I wrote a bit of racket code to generate a html-bullet-list out of the comma seperated list of tags frog gives me:
@(string-join
(map (lambda (str)
(string-append "<li>" str "</li>"))
(string-split tags ",")))
What it does is simple: It splits the string in tags
, which holds a
list of tag-links by the seperator, the comma. Then it maps a lambda over the
list of strings, which appends the string to "<li>"
and "</li>"
to that.
Afterwards, the whole list gets joined together, so we have one big string
left.
The template itself contains the <ul>
and </ul>
tags around the list.
This way, I generate a nice bullet list for both the index pages and the
article pages.
Unfortunately, the solution is not very DRY, as both templates contain the same code. There is no possibility to pass custom code to frog, yet. But I opened a feature request on github to include such an option (providing a pull request would be much nicer, I know – but as you already know, I'm a racket newbie and I'm not sure I can figure out such a thing myself).
tags: #blog #racket #programming