fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
318 stars 50 forks source link

Include directory not found when running gh-deploy #213

Open wragge opened 5 months ago

wragge commented 5 months ago

I'm deploying my site to GH pages organisation using mkdocs gh-deploy. As documented, you build the organisation site in a separate directory. However, when I set include_dir in the macros config, the build fails, complaining that the include directory could not be found. This seems to be because the macros plugin is looking for the include directory in the build directory rather than the site directory.

A workaround is to create a copy of the mkdocs.yml file specifically for deployment that uses a relative path to the include directory eg: ../site/includes.

github-actions[bot] commented 5 months ago

Welcome to this project and thank you!' first issue

fralau commented 5 months ago

Thanks! I am new with mkdocs gh-deploy so I had to look up what it does, in relations to GitHub Pages (which is a Docs deployment platform not unlike Read The Docs).

This seems to be because the macros plugin is looking for the include directory in the build directory rather than the site directory.

The relevant code is here:

        # -------------------
        # Create the jinja2 environment:
        # -------------------
        DOCS_DIR = config.get('docs_dir')
        debug("Docs directory:", DOCS_DIR)
        # define the include directory:
        # NOTE: using DOCS_DIR as default is not ideal,
        # because those files get rendered as well, which is incorrect
        # since they are partials; but we do not want to break existing installs
        include_dir = self.config['include_dir'] or DOCS_DIR
        if not os.path.isdir(include_dir):
            raise FileNotFoundError("MACROS ERROR: Include directory '%s' "
                                    "does not exist!" %
                                    include_dir)
        if self.config['include_dir']:
            trace("Includes directory:", include_dir)
        else:
            debug("Includes directory:", include_dir)

What you mean by "build directory" is, I suppose the MkDocs project directory, where the original MkDocs config file is?

I suppose you defined the include_dir originally with a relative path? Perhaps mkdocs gh-deploy is getting confused because now the current directory is different. Have you tried to use an absolute path for include_dir?