Code Monkey home page Code Monkey logo

mkdocs-merge's Introduction

MkDocs Merge

This simple tool allows you to merge the source of multiple MkDocs sites into a single one converting each of the specified sites to a sub-site of the master site.

Supports unification of sites with the same site_name into a single sub-site.

Changelog

Access the changelog here: https://ovasquez.github.io/mkdocs-merge/changelog/

Note: Since version 0.6 MkDocs Merge added support for MkDocs 1.0 and dropped support for earlier versions. See here for more details about the changes in MkDocs 1.0.


PyPI version MkDocs Merge Validation Build

MkDocs-Merge officially supports Python versions 3.8, 3.9 and 3.10. It has been tested to work correctly in previous 3.X versions, but those are no longer officially supported.

Install

$ pip install mkdocs-merge

Usage

$ mkdocs-merge run MASTER_SITE SITES [-u]...

Parameters

  • MASTER_SITE: the path to the MkDocs site where the base mkdocs.yml file resides. This is where all other sites will be merged into.
  • SITES: the paths to each of the MkDocs sites that will be merged. Each of these paths is expected to have a mkdocs.yml file and a docs folder.
  • -u (optional): Unify sites with the same "site_name" into a single sub-site.

Example

$ mkdocs-merge run root/mypath/mysite /another/path/new-site /newpath/website

A single MkDocs site will be created in root/mypath/mysite, and the sites in /another/path/new-site and /newpath/website will be added as sub-pages.

Original root/mypath/mysite/mkdocs.yml

...
nav:
  - Home: index.md
  - About: about.md

Merged root/mypath/mysite/mkdocs.yml

...
nav:
  - Home: index.md
  - About: about.md
  - new-site: new-site/home/another.md # Page merged from /another/path/new-site
  - website: website/index.md # Page merged from /newpath/website

Development

Dev Install

Clone the repository and specify the dev dependencies on the install command. Project has been updated to use pyproject.toml so the version has to be manually synchronized in both __init__.py and pyproject.toml.

# Using quotes for zsh compatibility
$ pip install -e '.[dev]'

Test

The tests can be run using tox from the root directory. tox is part of the development dependencies:

$ tox

Publishing

The publishing process was updated to use GitHub Actions.

Project Status

Very basic implementation. The code works but doesn't allow to specify options for the merging.

Pending work

  • Refactoring of large functions.
  • GitHub Actions build.
  • Publish pip package.
  • Better error handling.
  • Merge configuration via CLI options.
  • Unit testing (work in progress).
  • CLI integration testing.
  • Consider more complex cases.
  • Make MkDocs Merge module friendly: thanks to mihaipopescu

mkdocs-merge's People

Contributors

acerinth avatar mihai-unity avatar ovasquez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mkdocs-merge's Issues

Create mkdocs-merge organization

Hi,
thanks for sharing your project!

This is just a thought, but it could be helpful to create a new organisation with two sub-project for example and integrate the publish of the doc with travis as sample/tutorial.
The third project (this one) will contain the merged documentations published on github.io with your tool from the other two.

Not sure if I can help somehow, but it was just an idea ;-)

Add support for section index pages

Hey there!

Firstly, thank you so much for this amazing tool!

In our company, we use it in combo with MkDocs Material. Not sure about original MkDocs, but in this version, there is an option to set index pages for sections. To get a better understanding, please take a look at feature description.

It's very simple, and what it means, is that basically you may now have a nav entry in mkdocs.yml that looks like this:

nav:
  - Home: index.md
  - Section:
    - section/index.md                             #   <--- this right here is new!
    - Page 1: section/page-1.md
    ...
    - Page n: section/page-n.md

Those kind of entries are currently not supported and result in "Error merging the "nav" entry in the site: xxxx".

I've taken a quick look at the code - to me seems like a new elif in recursive function update_navs should be added where nav can be instance of str, or sth like that.

I hope you'll have a bit of time to consider this.

Thanks!

remove nav entry and make it optional as it is not required

Hey Oscar,

I just found your tool, as it is currently the only one I found so far for combining many docs into a single source. Still, you built a pretty awesome base that could be extended further. ;)

I found, that providing the "nav" entry in mkdocs.yaml is pretty useless as mkdocs will discover all the files by itself.
I am a little new to this topic. but am I wrong?

Fail to load `mkdocs.yml`

Hi @ovasquez , thank you for this useful tool!

I encounter an issue when in my mkdocs.yml of a sub-site I'm using special characters, such as !:

markdown_extensions:
  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg

for example when you setup this extension: https://github.com/facelessuser/mkdocs-material-extensions#inline-svg-icons

turns into:

mkdocs-merge run master_site sub_site

Attempting to merge site: sub_site
Error loading the yaml file "sub_site/mkdocs.yml". This site will be skipped.

Sounds like the Ruamel Yaml parser is not working with such !! tag

When mkdocs-merge is used as a module, subsequent merges fail

First let me say thanks for this package. It's really good considering what I've seen out there and I've integrated it into my own package which I plan to open source in the near future. It's a mkdocs-merge-server which uses mkdocs-merge to merge multiple mkdocs documentation source packages and also serve the final merged website.

The problem that I hit with your package was that subsequent merges failed with a similar failure I saw here https://stackoverflow.com/questions/9160227/dir-util-copy-tree-fails-after-shutil-rmtree/28055993#28055993 where I also found the workaround.

So basically what I did was to do this this:

        distutils.dir_util._path_created = {}
        new_pages = mkdocsmerge.__main__.merge_sites(sites, self._main_site_folder, True)

Also, I have to admit that there was a bit of a friction when I use your package as a module due to the cli extensions and not a more detailed organization.

Relative links to other markdown pages are not updated after merge

Say you have a mkdocs site with a setup.md that links to other windows.md, macosx.md and linux.md files like this:

setup.md

Here you can find the setup instructions for:
- [Windows](windows.md)
- [MacOSx](macosx.md)
- [Linux](linux.md)

When you merge that to any other master site, the references will point to a non-existing location.

The workaround is to have the links that point to the html's instead:

Here you can find the setup instructions for:
- [Windows](windows/index.html)
- [MacOSx](macosx/index.html)
- [Linux](linux/index.html)

... but that will break the static markdown files making them aware that they will be compiled to html at one point.

Would be nice if mkdocs-merge would do this automatically (and be aware of some other relative links to other directory structure).

Also, the problematic is extended for paragraph bookmarks (index.html#topic1).

How can we solve that in a more consistent way to make all files agnostic of where they are being used? I think this is an open question for later.

Proper treatment of edit_uri after merge

Hi @ovasquez,

Thank you for this nice tool!

We are using mkdocs-merge to add a separate site repository into a central (MASTER_SITE) site as a sub-page.

It appears that the treatment of the edit_uri for the sub-page does not link back (via the edit icon) to the original repository, but links back to the central one and returns an error.

Is there a way this can be treated properly?

Best regards,
Mateusz

mkdocs-merge affected by setuptools moving to 70.2.0

Hi @ovasquez,

Suddenly mkdocs-merge stopped working for us:

Cloning into 'ps-instructions'...
$ mkdocs-merge run . ps-instructions
Attempting to merge site: ps-instructions
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs-merge", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocsmerge/__main__.py", line 44, in run
    merge.run_merge(master_site, sites, unify_sites, print_func=click.echo)
  File "/usr/local/lib/python3.9/site-packages/mkdocsmerge/merge.py", line 35, in run_merge
    new_navs = merge_sites(sites, master_docs_root, unify_sites, print_func)
  File "/usr/local/lib/python3.9/site-packages/mkdocsmerge/merge.py", line 105, in merge_sites
    dir_util.copy_tree(old_site_docs, new_site_docs, update=1)
  File "/usr/local/lib/python3.9/site-packages/setuptools/_distutils/dir_util.py", line 146, in copy_tree
    mkpath(dst, verbose=verbose)
  File "/usr/local/lib/python3.9/site-packages/setuptools/_distutils/dir_util.py", line 82, in mkpath
    _path_created.add(abs_head)
AttributeError: 'dict' object has no attribute 'add'

https://gitlab.cern.ch/cms-tsg/fog/documentation/-/jobs/40713402

Could you please help us understand the underlying issue?

Thanks a lot.

Cheers,
Mateusz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.