Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hpc-compendium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZIH
hpcsupport
hpc-compendium
Commits
5cd82f17
Commit
5cd82f17
authored
2 years ago
by
Martin Schroschk
Browse files
Options
Downloads
Patches
Plain Diff
Adopt file name to style
parent
7b43167e
No related branches found
No related tags found
2 merge requests
!811
Automated merge from preview to main
,
!799
Created a new check-TOC.py without importing pd, and yaml
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc.zih.tu-dresden.de/util/check_TOC.py
+0
-74
0 additions, 74 deletions
doc.zih.tu-dresden.de/util/check_TOC.py
with
0 additions
and
74 deletions
doc.zih.tu-dresden.de/util/check_TOC.py
deleted
100644 → 0
+
0
−
74
View file @
7b43167e
"""
#!/usr/bin/env python
Check for consistency between TOC and page headings.
Provide as an command line argument the path to the mkdocs.yml file.
Author: Michael Bommhardt-Richter
"""
import
argparse
import
sys
from
pathlib
import
Path
# {path/filename.md: [toc_heading, file_heading], ... }
TOCData
=
dict
()
whitelist
=
[
"
index.md
"
]
# ["archive"]
def
get_heading_in_file
(
filename
,
docs_path
):
# TODO join path filename
# Read until first level one heading is found
f
=
Path
.
joinpath
(
docs_path
,
filename
)
with
open
(
f
,
"
r
"
)
as
file
:
for
line
in
file
:
if
line
.
startswith
(
"
#
"
):
# TODO Make sure it is really a level one heading!
# Will be empty if there is more than one "#".
return
line
.
split
(
"
#
"
)[
1
].
strip
()
def
main
():
scriptpath
=
Path
(
__file__
).
resolve
().
parent
mkdocsyaml
=
Path
.
joinpath
(
scriptpath
,
"
../
"
,
"
mkdocs.yml
"
)
if
Path
.
exists
(
mkdocsyaml
):
docs_path
=
Path
.
joinpath
(
scriptpath
,
"
../
"
,
"
docs
"
)
# print(docs_path)
with
open
(
mkdocsyaml
,
"
r
"
)
as
file
:
c
=
file
.
readlines
()
for
line
in
c
:
line
=
line
.
rstrip
()
# "headline: path/file.md" -> "Headline" = "path/file.md"
if
line
.
endswith
(
"
.md
"
):
line
=
line
.
split
(
"
-
"
)[
1
]
line
=
line
.
split
(
"
:
"
)
key
=
line
[
1
]
file_heading
=
get_heading_in_file
(
line
[
1
],
docs_path
)
TOCData
[
line
[
1
]]
=
[
line
[
0
],
file_heading
]
# Check TOC vs heading in corresponding md-file
cnt
=
0
for
key
,
value
in
TOCData
.
items
():
if
key
in
whitelist
:
continue
if
value
[
0
]
==
"
Overview
"
:
continue
if
value
[
0
]
!=
value
[
1
]:
cnt
+=
1
print
(
f
"
{
key
:
<
40
}{
value
[
0
]
:
<
30
}
!=
{
value
[
1
]
}
"
)
sys
.
exit
(
cnt
)
else
:
print
(
"
Error: Could not find mkdocs.yml file.
"
)
sys
.
exit
(
-
1
)
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Find differences in TOC and top level headings of md-files.
"
)
args
=
parser
.
parse_args
()
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment