Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
@oprypin How open would mkdocs be to support this natively instead of in a plugin? I made a plugin that was also initially made to address this issue (https://github.com/athackst/mkdocs-simple-plugin). It would be great if mkdocs could just natively handle this. I think now is the right time for this due to some of the improvements that have been made to mkdocs. I prototyped this change for mkdocs. I'm happy to share/create a pull request. It boils down to removing a couple of validations and adding a check within get_files to skip files within the site_dir. |
Beta Was this translation helpful? Give feedback.
-
The project that I work on has a few of the most important docs (like
README.md
andcontributing.md
) in the root directory of the git repository, and a bunch of other docs in adocs/
directory. I want to use all of these as source files for our MkDocs site.I apologize for creating the N+1th issue about this, but I have a combination of:
README.md
todocs/
, and make a symlink atREADME.md
targeting/docs/README.md
. GitHub's web UI traverses this symlink (showing people the contents of the target), but GitLab's web UI does not, so it would break any existing links to (e.g.)https://gitlab.com/exosphere/exosphere/-/blob/master/README.md
, and show a mostly empty page when people browse tohttps://gitlab.com/exosphere/exosphere
.README.md
contains relative links to other docs, likedocs/run-exosphere.md
. I want these links to continue working in GitLab/GitHub's Web UI, but also work on the site generated by MkDocs.Noting my solution to help others. Feel free to close this issue.
What Worked
In your repository, create a
mkdocs/
folder structure with symlinks like this:Now, the structure of
mkdocs/src/
mirrors the structure of the repo. You can set yourdocs_dir
tosrc
.That's it! No extensions needed. Links inside
README.md
targetingdocs/foobar.md
continue to work on the MkDocs site, and on the repo site (GitLab/GitHub).The only case where this may break is when developing on a Windows machine (which doesn't respect symlinks) -- fortunately not a problem for us. If you have developers on Windows, you could use this overall structure with snippets extension (per below) instead of symlinks.
Things that Didn't Work
mkdocs.yml
in repo root, anddocs_dir
set to repo root (.
)This breaks
mkdocs build
for two reasons:Since there's no higher-level directory in which to place
mkdocs.yml
, this is a dead end.mkdocs.yml
in repo root,docs_dir
set todocs/
, withnav
containing relative paths to (e.g.)../README.md
This breaks
mkdocs build
andmkdocs serve
:So
nav:
cannot specify relative paths to files outside thedocs_dir
.mkdocs.yml
in repo root,docs_dir
set todocs/
, withdocs/
containing symlinks targeting (e.g.)../README.md
(per #1279)This was promising: MkDocs renders
README.md
. The problem is thatREADME.md
contains several links to pages inside thedocs/
directory, e.g.:These links need to work on both the repo site (GitLab/GitHub) and on our MkDocs site. Alas, a link target of
docs/run-exosphere.md
doesn't work on the MkDocs site, and a target ofrun-exosphere.md
doesn't work on the repo site. @cruisercoder also got stuck on this here.mkdocs.yml
in repo root,docs_dir
set todocs/
, with snippets extension to embedREADME.md
as a snippet indocs/README.md
Per #2831, you can
pip install pymdown-extensions
and do this inmkdocs.yml
:Then make a
docs/README.md
with contents--8<-- "README.md"
.This renders the
README.md
but suffers the same issue as the symlinks option above. It renders the page, but links on the page are either broken on the docs site (if targetingdocs/run-exosphere.md
), or broken on the repo site (if targetingrun-exosphere.md
).Beta Was this translation helpful? Give feedback.
All reactions