Directory Structure

Laika does not have any special directories and content can be nested in sub-directories down to arbitrary levels.

When you are using the sbt plugin or the tree transformer from the library API that accepts directories as input, Laika supports additional file types and navigation features on top of just parsing text markup. This section describes the supported Document Types, how Auto-Generated Navigation works with directory input and how the Virtual Tree Abstraction decouples the logic from the file system.

This set of functionality is not available when you are using a transformer or parser from the library API that expects a single input (file, stream or string) for processing.

Document Types

The library distinguishes between the following file types:

Markup Files

Files with the extensions .md, .markdown or .rst will be parsed and rendered to the target in the same directory structure and with the same file names apart from the suffix, which will be replaced depending on the output format (e.g. .html).

Apart from standard markup syntax, markup files in Laika can also contain the following non-standard elements (unless running in strict mode which disables all extensions):

Title Documents

Each directory can contain an optional title document. It is recognized by the file name pattern README.<suffix>, e.g. When rendering the name will change to index.<suffix>, e.g. index.html.

These defaults have been chosen so that markup files appear below directory navigation on GitHub and rendered HTML files can serve as index pages. The names can be overridden in Laika's global configuration (you need to omit the suffix, as it'll work with all formats):

laikaConfig := LaikaConfig.defaults
  .withConfigValue(LaikaKeys.titleDocuments.inputName, "title")
  .withConfigValue(LaikaKeys.titleDocuments.outputName, "title")
val transformer = Transformer
  .withConfigValue(LaikaKeys.titleDocuments.inputName, "title")
  .withConfigValue(LaikaKeys.titleDocuments.outputName, "title")

Title Documents will also render on a level above the other chapter documents in the navigation, (see Auto-Generated Navigation for details) and will be linked in Breadcrumbs components.

Configuration Files

Each directory can contain an optional directory.conf file for configuring the directory (and its sub-directories). The expected format of the document is HOCON.

The available options are described in Configuration for Directories below.

Template Files

You can provide a default template per directory with the name default.template.<suffix>, where the suffix matches the output format (e.g. .html). They will also be applied to sub-directories, unless overridden. Default templates in one of your input directories always override default template provided by themes.

Additionally you can add templates with the name pattern *.template.<suffix>, which will only be applied when a markup document explicitly refers to them in its configuration header.

For more details on the template engine, see the chapter Creating Templates.

Static Files

All other files, like CSS, JavaScript, images, etc., will be handled depending on the output format:

Auto-Generated Navigation

The directory structure in a Laika project is not only a way to organize files in a workspace, the structure will also be used by various features of the library that auto-generate navigation structures.

The presence of title documents would determine how exactly chapter title are rendered in the navigation structure.

Example for a structure with title documents

Input Directory with Title Documents

In this example each directory has a title document. The title of that document is taken from the first header. In the navigation tree on the right it is rendered one layer above the other documents in the same directory, and the title is linked to the document.

Example for a structure without title documents

Input Directory without Title Documents

In this example there are no title documents and chapter titles are taken from the file directory.conf in each directory. In the navigation tree on the right these titles now only serve as separators and are not linked to any document.

Configuration for Directories

Each directory can contain an optional directory.conf in HOCON format. The configuration applies to the directory and all its sub-directories unless overridden on a lower level.

Directory Title

The title for a directory can be set explicitly:

laika.title = Introduction

This title will then be used in auto-generated navigation structures. In case you are using Title Documents this step is not necessary as the title of that document will be used instead by default (either coming from its first headline or overridden in its own configuration header). If you still set this attribute for the directory it will override whatever title has been set for the title document.

You can also set the navigation order for the directory explicitly:

laika.navigationOrder = [

The directory in the example above contains both markup files and sub-directories. They would appear in this order in tables of contents and the same order would be applied when autonumbering.

The default ordering, when not provided explicitly, is alphabetical. Note that documents omitted from this list but present in the directory would still appear in navigation trees, below the entries with an explicit order from configuration. For excluding documents entirely, see Limiting the Output Formats below.

Limiting the Output Formats

If you produce multiple output formats, you may want to limit the formats that get rendered for some documents or directories. If, for example, you generate a documentation site that also contains blog entries, you might want to exclude the blog content from generated EPUB or PDF documents and point to the site instead.

In this case you first need to specify which target formats a directory or document should render to:

laika.targetFormats = [html]

The laika.targetFormats key expects an array of string values.

Secondly, you may want to benefit from Laika's convenient feature of auto-translating all internal links to documents that are excluded from some formats to an external link instead. For this to work, the library or plugin needs to know where your site is hosted.

If you are using the Helium theme, there is a property you can use for this purpose:"https://my-docs/site")

If you are not using Helium, you can use the standard configuration API to set this value:

laikaConfig := LaikaConfig.defaults
  .withConfigValue(LaikaKeys.siteBaseURL, "https://my-docs/site")
val transformer = Transformer
  .withConfigValue(LaikaKeys.siteBaseURL, "https://my-docs/site")

You can also set an empty array and prevent the rendering of any output format:

laika.targetFormats = []

This might be useful if you have a directory that contains only snippets and partial documents you want to use via the @:include or @:embed directives. With an empty array you prevent not only the rendering of those document, they also won't show up in any navigation structure.

Finally, the laika.targetFormats key can also be used for individual documents, by placing it in the configuration header of a text markup document.

Normally an internal link will be validated and (with default error handling) cause the transformation to fail if one or more targets are invalid. A target is invalid if either the linked document does not exist, does not contain the specified id or fragment, or does not support the same set of output formats as the referring document.

In some cases this kind of strict validation may not be desired. You may, for example, have an external process that populates a directory before or after Laika is run. In this case you can disable validation for all link targets within that directory or its sub-directories:

laika.validateLinks = false

Versioned Documentation

Laika supports versioned documentation, where the current inputs are interpreted as belonging to one version only. The Helium theme contains a version switcher in the top navigation bar.

Each directory and each individual document can be marked as either versioned or unversioned. All versioned document will be rendered to a sub-directory of the root that contains only content for this specific version.

Therefore, configuration for versioned documentation involves two steps:

1) Configure all existing versions

This is a global configuration artifact that you can define with the Helium configuration API:

val versions = Versions(
  currentVersion = Version("0.42.x", "0.42"),
  olderVersions = Seq(
    Version("0.41.x", "0.41"),
    Version("0.40.x", "0.40", fallbackLink = "toc.html")
  newerVersions = Seq(
    Version("0.43.x", "0.43", label = Some("dev"))

The two required properties of the Version class are displayValue which is the version name to be used in UI elements and pathSegment which is the string to be used as part of URLs pointing to this version.

Two optional properties are label which can be used to associate categories like EOL, Stable or Dev with each version. Those three values come with default styles in the Helium CSS, but you can define additional labels if you manually include the CSS for those.

Finally, fallbackLink allows to define a link target that the version switcher should pick, if a target version does not have a page corresponding to the current page the user is on.

Note that this kind of "smart linking" currently only works if existing rendered versions can be found in the output directory of the transformer operation. In all other cases, the version switcher will always use the fallbackLink.

2) Configure which directories and documents are versioned

This step is necessary as each documentation site may contain any number of documents with content that is independent of the version of the project, e.g. a landing page, a blog/news section, a contributor guide, a COC, etc.

The most common scenario will be that most documents are versioned while only a few are not. You can benefit from Laika's support for hierarchical configuration for this purpose, where a value can be set for an entire directory, including sub-directories, unless overridden in a directory or document.

So most likely you would put a directory.conf into the root directory that switches versioning on:

laika.versioned = true

And then exclude individual directories or documents by overriding this value with false. When overriding for an individual document, you can do this with the standard HOCON headers (frontmatter), enclosed between {% and %}.

Virtual Tree Abstraction

While in most scenarios a single directory to provide all input files is probably sufficient, Laika's functionality is not tied to the file system in any way, but instead builds on top of a virtual tree abstraction.

As a consequence, you can alternatively merge multiple directories into one logical tree or generate additional files programmatically and "mount" them at a specific point in the virtual tree.

When merged directories contain sub-folders with the same name, those will be merged recursively. Only files with the same name in the same folder are treated as errors.

Merging Directories

In the example above two directories get merged into a single virtual root (/). The images directory exists in both sources, so it will be merged recursively.

The configuration mechanism for specifying multiple input directories is different for the sbt plugin and the Library API

Internally, the virtual path is represented by the laika.ast.Path type and relative links between them by laika.ast.RelativePath. These types are used frequently throughout the classes forming the document AST. All internal links are expressed with with these virtual paths and not with file system paths.