Skip to content

Commit

Permalink
Fixes #13095: Correctly generate nav in the reference doc
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Jul 31, 2018
1 parent 923d370 commit 88b9a2b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
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("^\[\[(.+),?.*\]\]$")

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))
15 changes: 0 additions & 15 deletions src/reference/tools/generate-nav.sh

This file was deleted.

0 comments on commit 88b9a2b

Please sign in to comment.