From bfdcc0d294374f6bd9c8d3405c2d43eeef7eebf1 Mon Sep 17 00:00:00 2001 From: Jody Garnett Date: Tue, 19 Sep 2023 09:15:19 -0700 Subject: [PATCH] work on translating doc references # Conflicts: # docs/manual/docs/overview/index.md --- docs/manual/docs/overview/index.md | 21 +++++----- docs/translate/translate.py | 61 ++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/docs/manual/docs/overview/index.md b/docs/manual/docs/overview/index.md index 21e8bd41d66..57228bf33a6 100644 --- a/docs/manual/docs/overview/index.md +++ b/docs/manual/docs/overview/index.md @@ -4,7 +4,12 @@ The GeoNetwork project started out in year 2001 as a Spatial Data Catalogue Syst At present the project is widely used as the basis of Spatial Data Infrastructures all around the world (See [gallery](gallery.md)). -The GeoNetwork project is part of the Open Source Geospatial Foundation ([OSGeo](http://www.osgeo.org)) and can be found at [GeoNetwork opensource](http://geonetwork-opensource.org). +The GeoNetwork project is part of the Open Source Geospatial Foundation ([OSGeo](https://www.osgeo.org)) and can be found at [GeoNetwork opensource](https://geonetwork-opensource.org). + +- [About](about.md) +- [License](license.md) +- [Authors](authors.md) +- [Change Log](change-log/index.md) ## Documentation @@ -12,18 +17,16 @@ These docs are organized into specific guides targeting different audience: Help -: Online help for visitors to the catalogue (no login required). +: Online help for visitors to the catalogue (no login required). [Installation Guide](../install-guide/index.md) -: Install GeoNetwork-opensource on to your computer. +: Install GeoNetwork-opensource on to your computer. -[User-guide](../user-guide/index.md) +[user-guide](../user-guide/index/index.md) -: Operational user-guide describing the editing, review and management of records (requires-login). +: Operational user-guide describing the editing, review and management of records (requires-login). -[Maintainers Guide](../maintainer-guide) +[Maintainers Guide](../maintainer-guide.md) -- [Statistics Index](statistics/index.md) -- [Updating Index](updating/index.md) -- [Production Use Index](production-use/index.md) +: These docs are organized into specific guides targeting different audience \ No newline at end of file diff --git a/docs/translate/translate.py b/docs/translate/translate.py index 972f27cd156..a555682539c 100644 --- a/docs/translate/translate.py +++ b/docs/translate/translate.py @@ -186,6 +186,9 @@ def preprocess_rst(rst_file:str, rst_prep: str) -> str: if '.. toctree::' in text: text = _preprocess_rst_toctree(text) + if ':doc:' in text: + text = _preprocess_rst_doc(text) + # gui-label and menuselection represented: **Cancel** text = re.sub( r":guilabel:`(.*)`", @@ -236,8 +239,39 @@ def preprocess_rst(rst_file:str, rst_prep: str) -> str: with open(rst_prep,'w') as rst: rst.write(text) -def _preprocess_rst_toctree(text: str): - # scan document for toctree directives to process +def _preprocess_rst_doc(text: str) -> str: + """ + Preprocess rst file replacing doc references with links. + """ + # doc links processed in order from most to least complicated + # :doc:`normal ` + text = re.sub( + r":doc:`(.*) <(.*).rst>`", + r"`\1 <\2.md>`_", + text, + flags=re.MULTILINE + ) + # :doc:`../folder/index.rst` + # `folder `_ + text = re.sub( + r":doc:`((\.\./)*(.*)/index)\.rst`", + r"`\3 <\1/index.md>`_", + text, + flags=re.MULTILINE + ) + # :doc:`simple.rst` + text = re.sub( + r":doc:`(.*)\.rst`", + r"`\1 <\1.md>`_", + text, + flags=re.MULTILINE + ) + return text + +def _preprocess_rst_toctree(text: str) -> str: + """ + scan document for toctree directives to process + """ toctree = None process = '' for line in text.splitlines(): @@ -254,16 +288,13 @@ def _preprocess_rst_toctree(text: str): if line[0:3] == ' ': # processing directive link = line[3:-4] - label = link - label = label.replace("/index", "") - label = label.replace("-", " ") - label = label.replace("/", " ") - label = label.title() + label = _labelify(link) toctree += f"* `{label} <{link}.md>`__\n" else: # end directive - process += toctree + process += toctree + '\n' + process += line + '\n' toctree = None else: process += line + '\n' @@ -274,6 +305,20 @@ def _preprocess_rst_toctree(text: str): return process +def _labelify(link: str) -> str: + """ + Create a label basde on a link + """ + label = link.replace('.rst','') + label = label.replace('.md','') + label = label.replace('/index', '') + label = label.replace('-', ' ') + label = label.replace('_', ' ') + label = label.replace('/', ' ') + label = label.title() + + return label + def postprocess_rst_markdown(md_file: str, md_clean: str): """ Postprocess pandoc generated markdown for mkdocs use.