mdtodocu is a Python script designed to convert markdown files structured for mdbook into a format compatible with Docusaurus. It automates the process of reorganizing files, adding frontmatter, creating directory structures, and handling images required by Docusaurus. This tool is ideal for developers migrating documentation from mdbook to Docusaurus.
- Converts mdbook
SUMMARY.md
hierarchy into Docusaurus-compatible directory structures. - Automatically generates
_category_.json
files for Docusaurus sidebar categories. - Adds frontmatter (title and sidebar position) to markdown files.
- Recursively searches for and organizes markdown files.
- Handles image references in markdown files:
- Updates image paths to use
./img/
prefix. - Copies images to the appropriate
./img/
directory. - Verifies and logs missing images.
- Updates image paths to use
- Processes
!!wiki.include
statements to include external markdown content. - Preserves the original content while adapting it for Docusaurus.
The repository includes a Makefile to simplify installation, rebuilding, and uninstallation of the script.
-
Clone the repository:
git clone https://github.com/threefoldfoundation/mdtodocu.git cd mdtodocu
-
Install the script system-wide using the Makefile:
make build
This will:
- Copy the script to
/usr/local/bin/
. - Make the script executable.
- If necessary, you will be prompted for your password to complete the installation.
- Copy the script to
-
To rebuild the installation (e.g., after updating the script):
make rebuild
-
To uninstall the script:
make delete
Run the script with the following command:
mdtodocu <userinput>
Replace <userinput>
with the name of the mdbook directory you want to convert. The script will look for a SUMMARY.md
file in ../books/<userinput>/SUMMARY.md
and process the markdown files accordingly.
<userinput>
: The name of the mdbook directory to convert. This is a required argument.
mdtodocu my-mdbook
This will:
- Parse the
SUMMARY.md
file in../books/my-mdbook/SUMMARY.md
. - Create a Docusaurus-compatible directory structure in
docu_books/my-mdbook
. - Add frontmatter to markdown files and generate
_category_.json
files. - Update image paths and copy images to the
./img/
directory. - Process
!!wiki.include
statements to include external markdown content.
- Parsing
SUMMARY.md
: The script reads theSUMMARY.md
file to extract the hierarchy of markdown files, including titles, indentation levels, and positions. - Directory Structure: It creates a directory structure in the output folder (
docu_books/<userinput>
) based on the hierarchy. - Frontmatter: Adds Docusaurus-compatible frontmatter (title and sidebar position) to each markdown file.
- Category Files: Generates
_category_.json
files for directories to define sidebar categories in Docusaurus. - Image Handling:
- Updates image paths in markdown files to use
./img/
. - Copies images to the appropriate
./img/
directory. - Logs missing images in
mdtodocu.log
.
- Updates image paths in markdown files to use
- Include Statements: Processes
!!wiki.include
statements to include external markdown content. - File Copying: Copies and updates markdown files while preserving their content.
- Ensure the
SUMMARY.md
file follows the standard mdbook format. - The script assumes markdown files are located in the current directory or its subdirectories.
- Binary files and non-markdown files are ignored.
- If a file or image is not found in the source directory, a warning is displayed, and the file is skipped.
- The script logs missing images in
mdtodocu.log
.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page or submit a pull request.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.