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: Add mkdocs edit on GitHub features #5104

Closed
wants to merge 16 commits into from
Closed
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
30 changes: 29 additions & 1 deletion man/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ DSTFILES := \
$(HTMLDIR)/parser_standard_options.css \
$(HTMLDIR)/parser_standard_options.js \
$(MDDIR)/mkdocs.yml \
$(MDDIR)/gh-paths.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,12 +252,36 @@ $(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) $@

# Get all Markdown files from the scripts directory
MDPATHS := $(wildcard $(MODULE_TOPDIR)/scripts/**/*.md)

# Generate the YAML file listing the Markdown files
$(MDDIR)/gh-paths.yml: | $(MDDIR)
@echo "scripts_tools:" > $@
@for file in $(MDPATHS); do \
echo " - $$file" >> $@; \
done

# Target to list the YAML file contents
list-md-files: $(MDDIR)/gh-paths.yml
@echo "Generated YAML file: $(MDDIR)/gh-paths.yml"
@cat $(MDDIR)/gh-paths.yml

build-mkdocs:
@cd $(MDDIR) ; SITE_NAME="GRASS GIS $(GRASS_VERSION_NUMBER) Reference Manual" \
COPYRIGHT="&copy; 2003-$(GRASS_VERSION_DATE) GRASS Development Team, GRASS GIS $(GRASS_VERSION_NUMBER) Reference Manual" \
Expand Down
143 changes: 122 additions & 21 deletions man/mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,147 @@
---
# Project information
site_name: !ENV SITE_NAME
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!q}

# Project Configuration
docs_dir: source
extra:
homepage: ./index.html
use_directory_urls: false

# Copyright
copyright: !ENV COPYRIGHT

# Theme configuration
theme:
name: material
custom_dir: overrides
language: en
logo: grass_logo.png
# logo: grass_icon.png
# favicon: grass-favicon-16x16.png
features:
- search.suggest
- search.highlight
- content.code.copy
- navigation.footer
# - navigation.sections
- navigation.indexes
# - navigation.expand
- navigation.tabs
- navigation.tabs.sticky

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

hooks:
- scripts/hook_list_scripts.py
# Customization
extra:
homepage: ./index.html

extra_css:
- grassdocs.css

# Plugins
plugins:
- search
- glightbox
use_directory_urls: false
nav:
- GUI: wxGUI.md
- Startup: grass.md
- Databases: database.md
- Display: display.md
- General: general.md
- Imagery: imagery.md
- Misc: miscellaneous.md
- Postscript: postscript.md
- Raster: raster.md
- Raster 3D: raster3d.md
- SQL: sql.md
- Temporal: temporal.md
- Variables: variables.md
- Vector: vector.md
- Keywords: keywords.md
- Topics: topics.md
# - social
# - tags
# - git-revision-date-localized:
# enable_creation_date: true
# - git-committers:
# repository: OSGeo/grass
# branch: main

# Markdown extensions
markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.superfences
- attr_list
- md_in_html

# Navigation
nav:
- Interfaces:
- Shell:
- Overview: grass.md
# - Getting Started: grassintro.md # Does not exist yet
- Environmental Variables: variables.md
- GUI:
- Overview: wxguiintro.md
- Features: wxGUI.md
- Project Management: grass_database.md
- Tool Dialogs: wxGUI.modules.md
- Attrribute Table Management: wxGUI.dbmgr.md
- Cartographic Composer: wxGUI.psmap.md
- Data Catalog: wxGUI.datacatalog.md
- Vector Digitizer: wxGUI.vdigit.md
- Raster Digitizer: wxGUI.rdigit.md
- Graphical Modeler: wxGUI.gmodeler.md
- Ground Control Points Manager: wxGUI.gcp.md
- Network Analysis: wxGUI.vnet.md
- Help: helptext.md
- List of Components: wxGUI.components.md

# - Scripting:
# - Overview: scriptingintro.md
# - Python: python.md
# - Shell Scripting: shell.md
# - Batch Processing: batch.md
# - R: r.md
# - Jupyter Notebook: jupyter.md

- Project Management:
- General Tools: general.md
- Projection and Transformations: projectionintro.md

- Processing Tools:
- Raster:
- Overview: rasterintro.md
- Raster Tools: raster.md
- Raster 3D:
- Overview: raster3dintro.md
- Raster 3D Tools: raster3d.md
- Vectors:
- Overview: vectorintro.md
- Vector Tools: vector.md
- Databases Overview: databaseintro.md
- Database Tools: database.md
- Supported Database Drivers: sql.md
# - GUI Tools:
- Imagery:
- Overview: imageryintro.md
- Imagery Tools: imagery.md
- GUI Tools:
- Image Classification: wxGUI.iclass.md
- Temporal:
- Overview: temporalintro.md
- Temporal: temporal.md

- Visualization:
# - Overview: visualizationintro.md # Does not exist yet
- Display Tools: display.md
- GUI Tools:
- Animation: wxGUI.animation.md
- "3D Visualization": wxGUI.nviz.md
- Interactive Scatter Plot: wxGUI.iscatt.md
- Map Swipe: wxGUI.mapswipe.md
- Timeline: wxGUI.timeline.md
- Temporal Plot: wxGUI.tplot.md

# - Other:
# - Misc: miscellaneous.md
# - Postscript: postscript.md
57 changes: 57 additions & 0 deletions man/mkdocs/overrides/partials/actions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% if page.edit_url %}

{% set toolname = page.file.src_path.split("/")[-1] | replace(".md", "") %}
{% if toolname.startswith("r.") %}
{% set category = "raster" %}
{% elif toolname.startswith("g.") %}
{% set category = "general" %}
{% elif toolname.startswith("v.") %}
{% set category = "vector" %}
{% elif toolname.startswith("i.") %}
{% set category = "imagery" %}
{% elif toolname.startswith("t.") %}
{% set category = "temporal" %}
{% elif toolname.startswith("r3.") %}
{% set category = "raster3d" %}
{% elif toolname.startswith("m.") %}
{% set category = "misc" %}
{% elif toolname.startswith("ps.") %}
{% set category = "ps" %}
{% elif toolname.startswith("db.") %}
{% set category = "db" %}
{% elif toolname.startswith("d.") %}
{% set category = "display" %}
{% else %}
{% set category = "" %}
{% endif %}


{# Special case: Some tools always go in the scripts directory #}
{# script_tools is auto-generated using scripts/hooks.py #}
{% if toolname in config.extra.scripts_tools %}
{% set category = "scripts" %}
{% endif %}

<!-- {{ "CUSTOM ACTIONS TEMPLATE LOADED" }}
{{ config.extra.scripts_tools }} -->

{% set custom_edit_url = page.edit_url | replace(toolname, category ~ "/" ~ toolname ~ "/" ~ 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 %}
24 changes: 24 additions & 0 deletions man/mkdocs/scripts/hook_list_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pathlib import Path


def on_config(config):
scripts_dir = Path("gh-paths.yml")
scripts_tools = []
# Read the mkdocs.yml file
with open(scripts_dir) as file:
for line in file:
if line.startswith("scripts_tools:"):
pass
else:
toolname = line.split("/")[-1].replace(".md", "").strip()
scripts_tools.append(toolname)

# Store in MkDocs extra config
config["extra"]["scripts_tools"] = scripts_tools
return config


# if __name__ == "__main__":
# mock_config = {"extra": {"scripts_tools": []}}
# script_list = on_config(mock_config)
# assert len(script_list["extra"]["scripts_tools"]) > 0
Loading