Generate random string for permalink jekyll

Viewed 351
3 Answers

There are many ways to generate a random string. Jekyll can do that too for you if you want. You just need to write a plugin that sets the permalink. Nobody has done this before... of that I am sure.

The question remains... WHY? Because it seems like a bad idea.

However, if you want to do this, the simplest way is to generate the random string in your text-editor. You will have to (manually) create the blog post anyway. Just find a good random string creator and install it on your computer or keep it at hand in a browser. Simply paste the string to the permalink YML variable.

You can also create a command-line script that renames your files to random strings. That should be pretty easy too. Again... you will not find this online... but renaming from the command line is pretty easy. Generating a random string probably too. Combine the two and you have a solution.

Anyway... just my thoughts. Hope it helps. Good luck!

With Visual Studio Code (VScode) you can create snippets.

Just create a file jekyll.code-snippets inside the .vscode folder. The format is just json.

{
    "Insert a Post Header for Jekyll in markdown":{
        "prefix": "kw-jekyll-postheader",
        "scope": "markdown",
        "body": [
            "---",
            "layout: post", 
            "title: \"${TM_FILENAME_BASE/\\d{4}-\\d{2}-\\d{2}-//gi}\"",
            "date: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND +0200", 
            "categories: kargware",
            "tags: [ \"jekyll\" ]",
            "post_key6: $RANDOM_HEX",
            "---"
        ],
        "description": "Insert a post header for jekyll in markdown"
    }
}

When you type kw-jekyll-postheader (defined in prefix) on a open markdown-file and start the tab-completion you will see a front matter code-snippet, and random value is placed in post_key6.

You could also take a random element of an array with the new sample filter, it was posted here.

{% assign prefix = page.prefix | sample: 2 %}
Related