-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #13095: Correctly generate nav in the reference doc
- Loading branch information
Showing
3 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import re | ||
|
||
PAGESDIR = "modules/ROOT/pages/" | ||
TITLE = re.compile("^(=+) (.+)$") | ||
ID = re.compile("^\[\[(.+),?.*\]\]$") | ||
|
||
def remove_duplicate_underscore(string): | ||
prev = ' ' | ||
res = [] | ||
for char in string: | ||
if prev == '_' and char == '_': | ||
pass | ||
else: | ||
res.append(char) | ||
prev = char | ||
return ''.join(res) | ||
|
||
# reproduce asciidoc's behavior | ||
def slugify(s): | ||
s = "_" + s | ||
s = s.lower() | ||
s = s.strip() | ||
s = re.sub('\W', '_', s) | ||
s = remove_duplicate_underscore(s) | ||
return s | ||
|
||
os.chdir(PAGESDIR) | ||
|
||
# Get all standalone .adoc pages, sorted alphanumerically | ||
# We exclude files in root (the index of the doc), _partials which are not actual pages | ||
files = sorted([ root.split('/', 1)[-1]+"/"+file for root, dirs, files in os.walk('.') for file in files if file.endswith(".adoc") and not "_partials" in root and not root == "." ]) | ||
|
||
result = ["// Automatically generated list of content - do not edit"] | ||
|
||
for file in files: | ||
with open(file) as f: | ||
content = f.read().splitlines() | ||
|
||
prev = "" | ||
for line in content: | ||
search_title = TITLE.search(line) | ||
if search_title: | ||
level = search_title.group(1).count("=") | ||
title = search_title.group(2) | ||
search_id = ID.search(prev) | ||
if search_id: | ||
id = search_id.group(1) | ||
else: | ||
id = slugify(title) | ||
result.append("*" * level + " xref:" + file + "#" + id + "[" + title + "]") | ||
prev = line | ||
|
||
print("\n".join(result)) |
This file was deleted.
Oops, something went wrong.