Skip to content

Commit

Permalink
work on translating doc references
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/manual/docs/overview/index.md
  • Loading branch information
jodygarnett committed Sep 19, 2023
1 parent fcd420f commit bfdcc0d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
21 changes: 12 additions & 9 deletions docs/manual/docs/overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ 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

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
61 changes: 53 additions & 8 deletions docs/translate/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:`(.*)`",
Expand Down Expand Up @@ -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 <link.rst>`
text = re.sub(
r":doc:`(.*) <(.*).rst>`",
r"`\1 <\2.md>`_",
text,
flags=re.MULTILINE
)
# :doc:`../folder/index.rst`
# `folder <index.md>`_
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():
Expand All @@ -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'
Expand All @@ -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.
Expand Down

0 comments on commit bfdcc0d

Please sign in to comment.