J.Kirchartz Web Yinzer

Blog Post Bookmarklet, or Stealing Stefan's Idea…

A fine fellow told me about their bookmarklet for making GHpages posts so I’ve decided to steal their idea, I love bookmarklets.

Theirs is a little more involved, I simplified it for my uses…

var isoDate = (new Date()).toISOString();
var date = isoDate.split('T')[0];
var t = prompt("title", "");
var title = t.replaceAll(/([&$\+,:;'"=\?@#\s<>\[\]\{\}[\/]|\\\^%])+/g, '-').toLowerCase();

var filename = date + "-" + title + '.md';

var html = [
'published: false',
'layout: post',
'title: ' + t,
'tags: article',

window.location.href = "https://github.com/jkirchartz/jkirchartz.github.com/new/master/" + "?filename=_posts/" + filename + "&value=" + html;

I even used the https://caiorss.github.io/bookmarklet-maker/ tool they did to turn it into a bookmarklet… which looks kinda like this:


There’s nothing wrong with any of that, but it’s a lot noiser than the style I use when I write my own bookmarklets. It works, it’s just missing my usual bookmarklet finesse. I’ve been thinking that it’s time to use es6 for them (and everything else) because IE11 is surely dead by now, right? Is anyone even tracking their browser share anymore? Here’s a hand-optimized es6 alternative:

((t, h)=>{
    'published: false',
    'layout: post',
    'title: \"' + t + '\"',
    'tags: article',
    t = t.replaceAll(/([&$\+,:;'"=\?@#\s<>\[\]\{\}[\/]|\\\^%\.])+/g, '_').toLowerCase();
    window.location = `https://github.com/jkirchartz/jkirchartz.github.com/new/master/?filename=_posts/${new Date().toISOString().split('T')[0]}-${t}.md&value=${h.join('%0A')}`;

which crunches down to

javascript:((t,h)=>{h=['---','published: false','layout: post','title:\"'+t+'\"','tags: article','---','','','<!--more-->',];t=t.replaceAll(/([&$\+,:;'"=\?@#\s<>\[\]\{\}[\/]|\\\^%\.])+/g,'_').toLowerCase();window.location=`https://github.com/jkirchartz/jkirchartz.github.com/new/master/?filename=_posts/${newDate().toISOString().split('T')[0]}-${t}.md&value=${h.join('%0A')}`;})(prompt("title"));

Anyhow. This bookmarket might’ve helped me stick to the “100 days to offload” thing a little better, but 100 blog posts in 100 days? that’s not the way I write, not anymore, not since… the incident… Pardon the digression, I would probably write more if Github had a vim-mode on their editor, at least something to swallow the :w I habitually drop to save my work.

As if I need another project, I think a fork of the bookmark generator is in order. I don’t think anyone today is writing a minifier that splits the difference with PACKER’s Base62 encoding - or at least follows sort of that style, the Base62 obsfucation is a bit much for me, I just want the shortest script possible - and that means shrinking variables names way too short to be really meaningful. I probably should be working on my other projects before hacking my preferences in minification into an existing minifier.

Like, if document appears more than once in your bookmarklet, it can easily be shrunk to d=document for future reference - heck d=document,$=d.querySelectorAll has its uses… but no… I don’t need another project… at least not one that I can’t put together in a night or two.

For more information about crunching down JS to it’s bare bits, check out: