wilhelmer / mkdocs-multirepo

A bit like monorepo, but keeps MkDocs projects separate.
MIT License
40 stars 2 forks source link

mkdocs-multirepo

PyPI version

A bit like monorepo, but keeps MkDocs projects separate.

Note: This tool is in beta.

Use Case

This CLI tool allows you to build multiple MkDocs documentation projects and generate a landing page for them:

Landing Page Example

Unlike monorepo, multirepo doesn't merge projects into one.

Instead, multirepo adds the MkDocs projects as Git submodules, builds them individually, and generates an HTML landing page based on a template file.

This has a number of advantages, for example:

Installation

  1. Install via pip install mkdocs-multirepo.
  2. Create a directory and put two files named config.yml and index.tpl in it.
  3. Configure the files as described below.
  4. Change to the directory created in step 1.
  5. Run git init.
  6. Run mkdocs-multirepo --init.

Usage

Usage: mkdocs-multirepo [OPTIONS]

Options:
  --init      Initialize the repos as Git submodules.  [default: False]
  --update    Update the repos, i.e., the Git submodules.  [default: False]
  --build     Build all MkDocs projects and generate the landing page.
              [default: False]

Configuration

Sample Project

See mkdocs_multirepo/demo for a sample project.

Note: Search is not functional. You must implement it yourself, e.g., using Docsearch.

config.yml

Use the config.yml file to configure the build process. Example:

repos:
  - name: repo-1
    title: My Repository 1
    image: images/icon-repo-1.png
    url: https://github.com/giansalex/mkdocs-sample.git
    branch: master
  - name: repo-2
    title: My Repository 2
    image: images/icon-repo-2.png
    url: https://github.com/hristo-mavrodiev/mkdocs-sample.git
    branch: master
    index_html: install/index.html
element_id: multirepo
target_dir: site
repos_dir: src
index_tpl: index.tpl
extra_files:
    - styles.css
    - images/search.svg

Each entry under repos configures an MkDocs project:

Additionally, the following general settings are available:

index.tpl

Use the index.tpl file to configure the landing page. Example:

<html>
    <head>
        <title>Multirepo Demo Page</title>
        <link rel="stylesheet" type="text/css" href="https://github.com/wilhelmer/mkdocs-multirepo/blob/master/styles.css">
    </head>
    <body>
        <section id="multirepo"></section>
    </body>
</html>

The template must be written in HTML and must contain a node with an ID called "multirepo" or as defined using the element_id setting.

From this template, a landing page named index.html will be generated and placed into target_dir.

Sample output:

<html>
    <head>
        <title>Multirepo Demo Page</title>
        <link href="https://github.com/wilhelmer/mkdocs-multirepo/blob/master/styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <section id="multirepo">
            <ul>
                <li><a href="https://github.com/wilhelmer/mkdocs-multirepo/blob/master/repo-1/index.html"><img src="https://github.com/wilhelmer/mkdocs-multirepo/raw/master/images/icon-repo-1.png" /><span>My Repository 1</span></a></li>
                <li><a href="https://github.com/wilhelmer/mkdocs-multirepo/blob/master/repo-2/01_index.html"><img src="https://github.com/wilhelmer/mkdocs-multirepo/raw/master/images/icon-repo-2.png" /><span>My Repository 2</span></a></li>
            </ul>
        </section>
    </body>
</html>