Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ mike deploy 0.3 'experimental' -t '0.3: Experimental development' --push
```

Note the format for the title (-t). Keep a consistent naming structure. Also note that this version is aliased as `experimental`.

Also, edit the edit_uri in mkdocs.yml to have the new version as a branch name.

## Adding a New Submodule Repo
```commandline
cd ~/repos/hello-robot.github.io/repos
Expand Down
7 changes: 6 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ site_description: "Hello Robot User Documentation"
copyright: 'Copyright © 2020-2025 Hello Robot Inc'
site_author: Hello Robot Inc
use_directory_urls: True
edit_uri: ''
repo_url: https://github.com/hello-robot/hello-robot.github.io
edit_uri: blob/0.3/docs

theme:
name: material
Expand All @@ -18,6 +19,7 @@ theme:
- scheme: default
primary: hello-robot-light
features:
- content.action.edit
- navigation.footer

extra_css:
Expand Down Expand Up @@ -52,6 +54,9 @@ plugins:
- glightbox-skip
- include-markdown

hooks:
- plugins/edit_links_across_submodules.py

extra:
version:
provider: mike
Expand Down
64 changes: 64 additions & 0 deletions plugins/edit_links_across_submodules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Replaces the edit_url for documentation included in other submodules.

For example, the file robot_parameters.md [1] is included using the submodule located at repos/stretch_body

When edit_uri is defined in the mkdocs.yml, the edit link for that page is
https://github.com/hello-robot/hello-robot.github.io/blob/0.3/repos/stretch_body/docs/robot_parameters.md
which does not link properly.

The code contained in this module is inspired by the submodule-edit-uri plugin [2]
and uses the mkdocs hooks [3] functionality.

It reads the submodules from `.gitmodules` using GitPython during the configuration step,
and then substitutes the proper url in the full output.

The resulting link is now correct, linking to the full github blob url [1]

[1] https://github.com/hello-robot/stretch_body/blob/master/docs/robot_parameters.md
[2] https://github.com/sondregronas/mkdocs-submodule-edit-uri
[3] https://www.mkdocs.org/user-guide/configuration/#hooks


"""
from git import Repo


def urljoin(*a):
s = ''
for sub in a:
if s and not s.endswith('/'):
s += '/'
s += sub
return s


def on_config(config):
submod_d = {}
config['submodules'] = submod_d
repo = Repo('.')
for submod in repo.submodules:
url = submod.url
if url.endswith('.git'):
url = url[:-4]
submod_d[submod.name] = {
'path': submod.path,
'url': url,
'branch': submod.branch.name,
}


def on_post_page(output, page, config):
# Assume that the edit uri is (blob|edit)/(branch_name)/docs/
edit_pieces = config['edit_uri'].split('/')
assert len(edit_pieces) == 4, config['edit_uri']
verb = edit_pieces[0]
branch = edit_pieces[1]

base = urljoin(config['repo_url'], verb, branch)

for name, submod in config['submodules'].items():
old_path = urljoin(base, submod['path'])
new_path = urljoin(submod['url'], verb, submod['branch'])
output = output.replace(old_path, new_path)
return output
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "This repository generates the documentation hosted at [docs.hello
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"GitPython>3.1",
"jinja2==3.0.3",
"mike>=2.1.3",
"mkdocs>=1.6.1",
Expand Down
35 changes: 35 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.