Using a theme

Note

You need version 1.4.0 or newer.

To get started with using themes, all you need to do is define them inside your umejs config!

Take the following example code:

const ume = require('@dantenl/umejs');
const path = require('path');
ume({
    themes: ['./path/to/local/theme.ume.js', '@example/umejs-theme']

    // example contentDir
    contentDir: path.join(__dirname, 'content'),
});

Note the themes key inside the config. This can be either be a theme stored locally pointing to a file which exports a theme object to umejs or to a module, which should do the same. Because you can point directly to a module, you can easily install themes with npm!

This is basically all there is to using themes in terms of code. However, when using themes there are certain things to keep in mind.

The main thing to keep in mind is overrides. umejs generally has the following order of operations, where each step can override the last one.

  1. Themes
  2. User
  3. Frontmatter inside markdown

What does this mean in practice though? Well, say a theme has defined the following helper in its config:

module.exports = {
    name: 'example',

    helpers: {
        random: {
            cache: true,
            helper: () => '4',
            // returns the result of a random dice roll i had once
        },
    },
};

Arguably, what this theme does is kind of stupid. Whenever the helper {random} is called somewhere, it just replaces it with the number four. Imagine if it were needed for something secure!

Therefore, it's possible to override this ourselves. There are two ways we could do this. First would be to utilise our local theme at ./path/to/local/theme.ume.js we previously defined to create a new function. It's a bit over-complicated though. It's easier to just directly define a new helper in this case:

const ume = require('@dantenl/umejs');
const path = require('path');
ume({
    themes: ['./path/to/local/theme.ume.js', '@example/umejs-theme']

    // define our own helper
    helpers {
        // non cached function! it's different per page load
        random: () => Math.floor(Math.random() * 6) + 1
        // create a random number from 1-6
    }

    contentDir: path.join(__dirname, 'content'),
});

Because we defined another helper with the same name, anywhere we use {random}, our helper is used instead.

Tip

If you notice that one of your themes are broken, there's a good chance you or another theme might have overriden one of their core parts!

You can override various aspects; such as:

  • Helpers
  • Partials
  • Templates
  • Assets
  • Theme configuration options