docs: cleanup build

This commit is contained in:
Matthias Ringwald 2017-12-23 22:22:41 +01:00
parent 8c2863b837
commit 4f9c2a8601
3 changed files with 29 additions and 32 deletions

View File

@ -1,43 +1,46 @@
all: update_docs_and_apis html pdf all: update_apis_and_listings html pdf
html: html:
rm -rf docs_tmp
rm -rf docs_final rm -rf docs_final
cp -r docs docs_tmp
cp -r docs docs_final cp -r docs docs_final
# create docs/ports/existing_ports.md
./ports2markdown.py ./ports2markdown.py
# docs -> docs_final
./markdown2mkdocs.py ./markdown2mkdocs.py
rm -rf docs_tmp
mkdocs build --clean mkdocs build --clean
./mkdocs2html.py ./mkdocs2html.py
pdf: pdf:
mkdir -p latex mkdir -p latex
cp -r docs/picts latex cp -r docs/picts latex
# create docs/ports/existing_ports.md
./ports2markdown.py ./ports2markdown.py
./markdown2pdf.py # create latex/btstack_generated.md -> latex/btstack_final.tex
./markdown2tex.py
cp btstack_gettingstarted.tex latex cp btstack_gettingstarted.tex latex
cd latex && pdflatex btstack_gettingstarted.tex && pdflatex btstack_gettingstarted.tex cd latex && pdflatex btstack_gettingstarted.tex && pdflatex btstack_gettingstarted.tex
mv latex/btstack_gettingstarted.pdf btstack.pdf mv latex/btstack_gettingstarted.pdf btstack.pdf
rm -rf latex tmp rm -rf latex tmp
preview: update_docs_and_apis html preview: update_apis_and_listings html
# race condition, open browser before startnig MKdocs # race condition, open browser before startnig MKdocs
open http://127.0.0.1:8000 open http://127.0.0.1:8000
mkdocs serve mkdocs serve
update_docs_and_apis: update_apis_and_listings:
sed -e "s|../doc/manual/docs/||g" ../../chipset/README.md > docs/chipsets.md sed -e "s|../doc/manual/docs/||g" ../../chipset/README.md > docs/chipsets.md
rm -rf tmp rm -rf tmp
mkdir tmp mkdir tmp
# create docs/appendix/apis.md
./update_apis.py ./update_apis.py
# create docs/examples/examples.md
./update_listings.py ./update_listings.py
clean: clean:
rm -rf docs_final tmp btstack *.pdf latex/btstack_generated.* latex/btstack_final.tex rm -rf docs_final tmp btstack *.pdf latex/btstack_generated.* latex/btstack_final.tex
rm -rf docs/appendix/apis.md docs/appendix/index.md docs/examples/examples.md docs/chipsets.md rm -rf docs/appendix/apis.md docs/appendix/index.md docs/examples/examples.md docs/chipsets.md
rm -rf docs_tmp latex btstack help rm -rf latex btstack help

View File

@ -9,9 +9,9 @@ def insert_anchor(mdout, reference):
def insert_reference(mdout, text, link): def insert_reference(mdout, text, link):
mdout.write("") mdout.write("")
def process_sections(temp_file, dest_file): def process_sections(source_file, dest_file):
with open(dest_file, 'w') as mdout: with open(dest_file, 'w') as mdout:
with open(temp_file, 'r') as mdin: with open(source_file, 'r') as mdin:
for line in mdin: for line in mdin:
section = re.match('(#+.*){#(sec:.*)}',line) section = re.match('(#+.*){#(sec:.*)}',line)
if section: if section:
@ -20,12 +20,9 @@ def process_sections(temp_file, dest_file):
else: else:
mdout.write(line) mdout.write(line)
shutil.copyfile(dest_file, temp_file) def process_figures(source_file, dest_file):
return
def process_figures(temp_file, dest_file):
with open(dest_file, 'w') as mdout: with open(dest_file, 'w') as mdout:
with open(temp_file, 'r') as mdin: with open(source_file, 'r') as mdin:
for line in mdin: for line in mdin:
# detect figure # detect figure
figure = re.match('\s*(\!.*)({#(fig:.*)})',line) figure = re.match('\s*(\!.*)({#(fig:.*)})',line)
@ -38,12 +35,10 @@ def process_figures(temp_file, dest_file):
md_reference = "[below](#"+figure_ref.group(2)+")" md_reference = "[below](#"+figure_ref.group(2)+")"
line = line.replace(figure_ref.group(1), md_reference) line = line.replace(figure_ref.group(1), md_reference)
mdout.write(line) mdout.write(line)
shutil.copyfile(dest_file, temp_file)
return
def process_tables(temp_file, dest_file): def process_tables(source_file, dest_file):
with open(dest_file, 'w') as mdout: with open(dest_file, 'w') as mdout:
with open(temp_file, 'r') as mdin: with open(source_file, 'r') as mdin:
for line in mdin: for line in mdin:
# detect table # detect table
table = re.match('\s*(Table:.*)({#(tbl:.*)})',line) table = re.match('\s*(Table:.*)({#(tbl:.*)})',line)
@ -56,13 +51,11 @@ def process_tables(temp_file, dest_file):
md_reference = "[below](#"+table_ref.group(2)+")" md_reference = "[below](#"+table_ref.group(2)+")"
line = line.replace(table_ref.group(1), md_reference) line = line.replace(table_ref.group(1), md_reference)
mdout.write(line) mdout.write(line)
shutil.copyfile(dest_file, temp_file)
return
def process_listings(temp_file, dest_file): def process_listings(source_file, dest_file):
with open(dest_file, 'w') as mdout: with open(dest_file, 'w') as mdout:
with open(temp_file, 'r') as mdin: with open(source_file, 'r') as mdin:
for line in mdin: for line in mdin:
listing_start = re.match('.*{#(lst:.*)\s+.c\s+.*',line) listing_start = re.match('.*{#(lst:.*)\s+.c\s+.*',line)
listing_end = re.match('\s*~~~~\s*\n',line) listing_end = re.match('\s*~~~~\s*\n',line)
@ -72,14 +65,10 @@ def process_listings(temp_file, dest_file):
mdout.write("\n") mdout.write("\n")
else: else:
mdout.write(line) mdout.write(line)
shutil.copyfile(dest_file, temp_file)
return
def main(argv): def main(argv):
md_template = "docs" md_template = "docs"
md_temp = "docs_tmp"
md_final = "docs_final" md_final = "docs_final"
yml_file = "mkdocs.yml" yml_file = "mkdocs.yml"
@ -87,13 +76,12 @@ def main(argv):
doc = yaml.load(yin) doc = yaml.load(yin)
for page in doc["pages"]: for page in doc["pages"]:
source_file = md_template +"/"+ page[0] source_file = md_template +"/"+ page[0]
temp_file = md_temp +"/"+ page[0]
dest_file = md_final +"/"+ page[0] dest_file = md_final +"/"+ page[0]
process_sections(temp_file, dest_file) process_sections(source_file, dest_file)
process_figures(temp_file, dest_file) process_figures(source_file, dest_file)
process_tables(temp_file, dest_file) process_tables(source_file, dest_file)
process_listings(temp_file, dest_file) process_listings(source_file, dest_file)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -47,6 +47,11 @@ def fix_appendix_pagebreak(line):
line = "\leavevmode\pagebreak\n" + line line = "\leavevmode\pagebreak\n" + line
return line return line
def fix_tightlist(line):
if 'tightlist' in line:
return ''
else:
return line
def main(argv): def main(argv):
docs_folder = "docs" docs_folder = "docs"
@ -92,6 +97,7 @@ def main(argv):
line = fix_listing_hyperref_into_ref(line) line = fix_listing_hyperref_into_ref(line)
line = fix_figure_width_and_type(line) line = fix_figure_width_and_type(line)
line = fix_appendix_pagebreak(line) line = fix_appendix_pagebreak(line)
line = fix_tightlist(line)
aout.write(line) aout.write(line)