Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I am trying to render md files that are located in the root directory of where the docs folder is located. The build is run succesfully but I get a 404 not found error on the pages where I locate outside of docs. Can someone help me?

nav:
  - Get started:
    - Introduction:                         /../README.md                       
  - Documentation:
    - Creating a new report:             somefile.md
    - Roles and Access:                     someotherfile.md
  - Disaster Recovery:
    - Disaster Recovery Plan:               /../someotherdirectory/file.md
You must be logged in to vote

Replies: 14 comments · 7 replies

Comment options

Try the snippets extension: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/#snippets-notation

You must be logged in to vote
0 replies
Answer selected by awallemo
Comment options

@pawamoy not sure how this would help? I just want to use md files outside of the docs folder within my mkdocs-site. Is this possible?

You must be logged in to vote
0 replies
Comment options

Yes, that's what the snippets extension allows to do (among other things). I've found it to be the most reliable way to include files that are outside of the docs directory. For example, my docs/index.md file has the contents of my README.md: --8<-- "README.md" (the readme is located one directory above the docs dir, but by default snippets use . as base path, and I'm running MkDocs in my repository root).

Before that I was using symlinks, which didn't work well between different platforms, and after that I was using the markdown-include extension, which is kinda superseded by pymdownx snippets.

You must be logged in to vote
2 replies
@ssbarnea
Comment options

That history bit is extremely useful and to some extent I repeated over few days... Sadly I got stuck again when I realised that the spippets do not work with multiple mkdocs sides (monorepo) as they will try to open different files (relative to parent mkdocs.yml file instead of relative to current project mkdocs.yml).

@oprypin
Comment options

@ssbarnea With 1.5.0+ could you try this, it should help

markdown_extensions:
  - pymdownx.snippets:
      base_path: !relative $docs_dir
Comment options

Ahh, I see, but its a python extension, and Im not using Python??

You must be logged in to vote
0 replies
Comment options

You definitely are using Python since MkDocs is written in Python 😉
You don't have to write Python code though, only install pymdown-extensions (for example with pip install pymdown-extensions) and configure mkdocs.yml properly.

You must be logged in to vote
0 replies
Comment options

I'm trying to do a pip install but 1. I dont have pip 2. I wouldnt know where in my project to download pymdown-extensions :/

You must be logged in to vote
0 replies
Comment options

I'm familiar with npm and understand that you need to download in a directory where package.json is located, but I dont have any experience with pip

You must be logged in to vote
0 replies
Comment options

You need to learn about pip and how to use it. If you installed MkDocs with another package manager (for example your OS package manager), then you should try to install pymdownx using this same package manager. MkDocs bugtracker is not the right place for this unfortunately. But there are plenty resources on the internet, I'm sure you'll quickly find how to handle this.

You must be logged in to vote
0 replies
Comment options

Thank you for your help :)

You must be logged in to vote
0 replies
Comment options

@pawamoy Okay, I've now got the extension I think. If I understand the example correctly. If I have a root directory and within this root directory I have my docs folder which mkdocs reads from. If I wanted the introduction navigation to point to the README.md which is also located in the root directory (not within docs folder), would I do it like this?

nav:
  - Get started:
    - Introduction:                         --8<--"README.md"

You must be logged in to vote
0 replies
Comment options

Thank you for the help, @pawamoy!

@awallemo it took me some time to figure this out (stalked @pawamoy's repositories 😆) - the --8<-- "README.md" thing should be placed inside your index.md file (or, in general, whichever file you would like to redirect to README.md).

For example, see -

This will render README.md wherever index.md is specified for rendering!

You must be logged in to vote
1 reply
@Saransh-cpp
Comment options

Here is the repository that I am working on -

https://github.com/Saransh-cpp/OCRed

Note how the files present in root directory (CHANGELOG.md, CODE_OF_CONDUCT.md, etc.) are rendered in the documentation (https://ocred.readthedocs.io/en/latest/).

Comment options

found this discussion on a GG Search..

the only missing code snippet appears to be

markdown_extensions:
  - pymdownx.snippets:
      check_paths: true

which should be placed in mkdocs.yml to enable the extension

You must be logged in to vote
0 replies
Comment options

you can also do this:

```{include} ../README.md
You must be logged in to vote
4 replies
@jrynlds-pinc
Comment options

I'm intrigued... but do not possess enough experience to to understand your comment. How would I use this? Where?

Would it be like this?

nav:
  - Home: 'index.md' # lives in the /docs directory
  - Readme: '{include} ../README.md'

I don't think so, as it doesn't work. My apologies for being daft. I would love to know how to make this work.

@epignatelli
Comment options

I guess you would point to a file whose content is that one.

index.md

nav:
  - Home: 'index.md' # lives in the /docs directory
  - Readme: 'README.md' # lives in the /docs directory

README.md

{include} ../README.md  # lives one level up the /docs directory
@peekxc
Comment options

{include} ../README.md # lives one level up the /docs directory

This doesn't work.

@epignatelli
Comment options

@peekxc yes, that's exactly why this issue is open.

Comment options

This thread is a bit old but I had the same problems and none of the solutions worked super well so I made this: https://pypi.org/project/mkdocs-include-files/

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #2831 on August 03, 2022 15:40.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.