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

Fixes #13095: Correctly generate nav in the reference doc #463

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/reference/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ content: $(GRAPHVIZ_IMAGES) $(ADOC_DYN_FILES) modules/ROOT/nav.adoc
cp dependencies/$@ modules/ROOT/pages/_partials/dyn/$@

modules/ROOT/nav.adoc: $(ADOC_SRC_FILES)
./tools/generate-nav.sh
./tools/generate-nav.py > modules/ROOT/nav.adoc

modules/ROOT/assets/images/graphviz/%.png: modules/ROOT/assets/graphviz/%.dot
mkdir -p modules/ROOT/assets/images/graphviz
Expand Down
56 changes: 56 additions & 0 deletions src/reference/tools/generate-nav.py
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(r"^[[(.+),?.*]]$")

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:
page_id = search_id.group(1)
else:
page_id = slugify(title)
result.append("*" * level + " xref:" + file + "#" + page_id + "[" + title + "]")
prev = line

print("\n".join(result))
15 changes: 0 additions & 15 deletions src/reference/tools/generate-nav.sh

This file was deleted.