Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: mkdocs edit and view on github #5114

Merged
merged 12 commits into from
Feb 19, 2025
13 changes: 12 additions & 1 deletion man/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ DSTFILES := \
$(MDDIR)/mkdocs.yml \
$(MDDIR)/source/grass_logo.png \
$(MDDIR)/source/grassdocs.css \
$(MDDIR)/overrides/partials/footer.html
$(MDDIR)/scripts/hook_list_scripts.py \
$(MDDIR)/overrides/partials/footer.html \
$(MDDIR)/overrides/partials/actions.html

categories = \
d:display \
Expand Down Expand Up @@ -248,9 +250,18 @@ $(MDDIR)/mkdocs.yml: mkdocs/mkdocs.yml
$(MDDIR)/source/grassdocs.css: mkdocs/grassdocs.css
$(INSTALL_DATA) $< $@

$(MDDIR)/scripts/hook_list_scripts.py: mkdocs/scripts/hook_list_scripts.py | $(MDDIR)/scripts
$(INSTALL_DATA) $< $@

$(MDDIR)/scripts:
$(MKDIR) $@

$(MDDIR)/overrides/partials/footer.html: mkdocs/overrides/partials/footer.html | $(MDDIR)/overrides/partials
$(INSTALL_DATA) $< $@

$(MDDIR)/overrides/partials/actions.html: mkdocs/overrides/partials/actions.html | $(MDDIR)/overrides/partials
$(INSTALL_DATA) $< $@

$(MDDIR)/overrides/partials:
$(MKDIR) $@

Expand Down
13 changes: 9 additions & 4 deletions man/mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ site_url: https://grass.osgeo.org/grass-stable/manuals/
# Repository information
repo_name: GitHub
repo_url: https://github.com/OSGeo/grass
# edit_uri_template: edit/main/{path}
edit_uri_template: edit/main/{path!q}

# Project Configuration
docs_dir: source
Expand All @@ -33,20 +33,25 @@ theme:
# - navigation.expand
- navigation.tabs
- navigation.tabs.sticky

# - content.action.edit # Edit on GitHub
- content.action.view
- content.action.edit # Edit on GitHub
palette:
primary: custom
# accent: custom
icon:
repo: fontawesome/brands/github
# edit: material/pencil
edit: material/pencil
view: material/eye

# Customization
extra:
homepage: ./index.html

# Hooks
hooks:
- scripts/hook_list_scripts.py

# Custom CSS
extra_css:
- grassdocs.css

Expand Down
32 changes: 32 additions & 0 deletions man/mkdocs/overrides/partials/actions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% if page.edit_url %}

{% set toolname = page.file.src_path.split("/")[-1] | replace(".md", "") %}

{# Default to the normal edit URL #}
{% set custom_edit_url = page.edit_url %}
{% set ghpath = github_path(toolname, config.extra.scripts_tools) %}
<!-- {{ "ghpath: " ~ ghpath }}<br>
{{ "toolname: " ~ toolname }}<br> -->
{% if ghpath %}
{% set custom_edit_url = page.edit_url ~ ghpath %}
{% set custom_edit_url = page.edit_url | replace(toolname, ghpath ~ "/" ~ toolname) %}
{% if "content.action.edit" in features %}
<a href="{{ custom_edit_url }}" title="{{ lang.t('action.edit') }}" class="md-content__button md-icon">
{% set icon = config.theme.icon.edit or "material/file-edit-outline" %}
{% include ".icons/" ~ icon ~ ".svg" %}
</a>
{% endif %}

{% if "content.action.view" in features %}
{% if "/blob/" in custom_edit_url %}
{% set part = "blob" %}
{% else %}
{% set part = "edit" %}
{% endif %}
<a href="{{ custom_edit_url | replace(part, 'tree') }}" title="{{ lang.t('action.view') }}" class="md-content__button md-icon">
{% set icon = config.theme.icon.view or "material/file-eye-outline" %}
{% include ".icons/" ~ icon ~ ".svg" %}
</a>
{% endif %}
{% endif %}
{% endif %}
Loading
Loading