A Jekyll plugin for better (?) Rust blogging


#1

While blogging about Rust I wished that my code samples could link to runnable samples in the Playground. So I wrote a Jekyll plugin that does just that:

Some examples of it in action can be found towards the bottom of my most-recent post, here: http://designisrefactoring.com/2015/11/27/simple-rust-part-three/


#2

If anyone gets this to work with octopress, let me know. IIRC octopress sort of works with Jekyll plugins.


#3

I use it with Octopress 3. No problems. But it might not work with Github Pages, since I haven’t marked it as safe. I’ll have to look into that.


#4

Nope, won’t work with Github Pages. I misunderstood the note at the top of http://jekyllrb.com/docs/plugins/


#5

Why link to the playground when you can just use a Javascript POST to run it through there?

I use a script similar to this on my blog: here which takes all of the code blocks that are tagged with rust and runs them through the playpen using the latest build (nightly branch) and using optimization level 2 just for the heck of it.

DISCLAIMER: I’m the author of that script.

The script doesn’t require anything so it’ll work on Github pages, Octopress, [Insert bogging platform here], …

If only there was a way to use crates, but that’s an issue for another time.


#6

I think that script looks great. If I’m reading correctly, the code sample & the code in Playground will always be exactly the same, right?

If so, that’s one difference between our two approaches. The Jekyll plugin can let you show part of your code in the sample, but have the full code in Playground. For example, your code sample can leave out the main function boilerplate and only show the important code, while your Playground code can contain everything necessary for compilation.


#7

Oh! I didn’t have time to test yours out, but the showing only a piece is awesome! And yes, you read it right it requires a main method.

Definitely looking forward to trying it out because it’s awesome to be able to link to an editor. Thanks for the hard work!