Configuration

config.js is where you can overwrite various website default configurations:

const port = {
  https: 4000,
  http: 3000
};

const hostname = "0.0.0.0";

const i18nOptions = {
  defaultLocale: "en",
  crowdin: {
    id: "cmints-website"
  }
};

const templateData =
{
  site: {
    domain: "cmints.io",
    title: "CMintS",
    description: "CMS created with the internationalization in mind"
  }
};

module.exports = {templateData, i18nOptions, port, hostname};

This file suppose to overwrite default configurations set by the CMintS.

port

Specifies on which port to run the server, by default it's 3000 for http and 4000 for https.

const port = {
  https: 4000,
  http: 3000
};

module.exports = {port};

hostname

Specifies the hostname for server to accept connection on, by default 127.0.0.1 is used.

const hostname = "0.0.0.0";

module.exports = {hostname};

root

Specifies the root directory of the website. Makes CMintS root directory aware.

const root = "/project-root";

module.exports = {root};

i18nOptions

Used only for multilingual projects:

const i18nOptions = {
  defaultLocale: "en",
  type: "Index",
  prefix: "{",
  postfix: "}",
  crowdin: {
    id: "cmints-website",
    updateOption: "update_as_unapproved"
  }
};

module.exports = {i18nOptions};

defaultLocale

Specifies the default locale for the project. Learn more about defaultLocale.

type

  • Index (Default)
  • Double

There are two ways how the content of multilanguage website can be generated - by duplicating the content of the page of specific language to have a redirection path if needed from one of the version(ex.: for redirecting to the user preffered language) or generating default language content as root in content directory. By Default Index option is used, in which case only one version of the default language page is generated, on the other hand Double allows you to have that duplication where you can setup for example a redirection by using urllocale.

Example below shows generation for about page when en is the default language:

  • about.html
  • en/about.html Double
  • de/about/html

detectLang

This option can only be used when running CMintS server with i18nOptions.type being set to Double, this setting is using user language preference, set in the Browser for relevant language page redirection. Setting has no effect on Static Website Generation.

crowdin.id

Crowdin projectID name. Learn More about crowdin.id.

crowdin.updateOption

  • update_as_unapproved(Default) - Preserve translations of changed strings and remove validations of those translations if they exist.
  • update_without_changes - Preserve translations and validations of changed strings.
  • null - translations for changed strings will be lost after string update.
const i18nOptions = {
  defaultLocale: "en",
  crowdin: {
    id: "cmints-website",
    updateOption: null
  }
};

prefix, postfix

Used for specifing custom prefix and postfix for i18n strings. Learn More about custom prefix and postfix.

templateData

data and functions in templateData can be accessed from .ejs pages and layout files:

Consider:

/* config.js */

const templateData =
{
  site: {
    domain: "cmints.io",
    title: "CMintS",
    description: "CMS created with the internationalization in mind",
    navigations: [
      {path: "documentation", stringId: "header-menu-item-docs"},
      {path: "presentation", stringId: "header-menu-item-slides"}
    ]
  }
};

module.exports = {templateData};

So the specified data above can be accessed as in the example:

<!DOCTYPE html>
  <head>
    <title><%= site.title %> | <%= page.title %></title>
    <meta name="twitter:title" content="<%= site.title %> | {page.title}">
  </head>
  <body>
...

Or:

<% for (let navigation of site.navigations) { %>
  <li>
    <a <%-i18n.href(navigation.path)%>
      <% if (navigation.path == page.pathname) { %>class="active"<% } %>>
      {<%-navigation.stringId%>(header)}
    </a>
  </li>
<% } %>

jsModuleOptions

Can be used to assign various existing options to the JS Modules build process. The example below shows how to add source map to the generation file for debugging purposes:

const jsModuleOptions = {
  debug: true
}

module.exports = {jsModuleOptions};

Minification

Making output of the JS Modules minified is as simple as specifying minify option:

const jsModuleOptions = {
  minify: true
}

module.exports = {jsModuleOptions};

You can also use various uglify-es configurations for JS Modules minification. The example below adds sourceMap to the minified files:

const jsModuleOptions = {
  minify: {
    sourceMap: true
  }
}

module.exports = {jsModuleOptions};

lessOptions

Can be used to assign various options to the CSS build process. The example below shows how to add source map to the generation file for debugging purposes:

const lessOptions =
{
  sourceMap: {
    sourceMapFileInline: true
  }
};

module.exports = {lessOptions};

Minification

Making output of the LESS minified is as simple as by specifying minify option:

const lessOptions = {
  minify: true
}

module.exports = {lessOptions};

You can also use various clean-css configurations for JS Modules minification. The example below adds sourceMap to the minified files:

const lessOptions = {
  minify: {
    sourceMap: true
  }
}

module.exports = {lessOptions};

markdownOptions

Use markdownOptions to change variouse markdown configurations. The example below adds syntax highlighting to code blocks:

const markdownOptions = {
  highlight: (str, lang) => (lang && getLanguage(lang)) ? highlight(lang, str).value : ""
};

Markdown plugins

You can use markdown-it plugins to extend markdown parser. That can be done using plugins property of markdownOptions configuration. Each plugin item can be either array, with plugin as the first item and plugin params as the rest, or by just by passing plugin if no other parameter needs to be specified. The example below adds markdown-it-link-attributes plugin to the project with configuration to open all external links in the separate tab and markdown-it-footnote plugin:

// Open external links in the new tab
const markdownLink = require("markdown-it-link-attributes");
const markdownItFootnote = require("markdown-it-footnote");
const markdownOptions = {
  plugins: [
    [
      markdownLink, {
        pattern: /^https?:\/\//,
        attrs: {
          target: "_blank",
          rel: "noopener"
        }
      }
    ],
    markdownItFootnote
  ]
};

module.exports = {markdownOptions};

configReloadWatchers

config.js does more than configuration and it's can be used for a robust action also you can call other modules and/or JSON files from config.js and you might not want restart the development server each time you update the other file, for that reason you can specify configReloadWatchers:

const configReloadWatchers = ["data.json", "syncinit.js"];
module.exports = {configReloadWatchers};