diff --git a/documentation/tools/books-toc-creator.py b/documentation/tools/books-toc-creator.py index 5d05448801..f5b4721a69 100644 --- a/documentation/tools/books-toc-creator.py +++ b/documentation/tools/books-toc-creator.py @@ -1,204 +1,204 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will generate the Table of Contents of the Handbook """ #!/usr/bin/env python3 import sys, getopt import re languages = [] def setAppendixTitle(language): languages = { 'en': 'Appendix', 'de': 'Anhang', 'el': 'Παράρτημα', 'es': 'Apéndice', 'fr': 'Annexe', 'hu': 'függelék', 'it': 'Appendice', 'ja': '付録', 'mn': 'Хавсралт', 'nl': 'Bijlage', 'pl': 'Dodatek', 'pt-br': 'Apêndice', 'ru': 'Приложение', 'zh-cn': '附录', 'zh-tw': '附錄' } return languages.get(language) def setPartTitle(language): languages = { 'en': 'Part', 'de': 'Teil', 'el': 'Μέρος', 'es': 'Parte', 'fr': 'Partie', 'hu': 'rész', 'it': 'Parte', 'ja': 'パート', 'mn': 'хэсэг', 'nl': 'Deel', 'pl': 'Część', 'pt-br': 'Parte', 'ru': 'Часть', 'zh-cn': '部分', 'zh-tw': '部' } return languages.get(language) def setChapterTitle(language): languages = { 'en': 'Chapter', 'de': 'Kapitel', 'el': 'Κεφάλαιο', 'es': 'Capítulo', 'fr': 'Chapitre', 'hu': 'Fejezet', 'it': 'Capitolo', 'ja': '章', 'mn': 'Бүлэг', 'nl': 'Hoofdstuk', 'pl': 'Rozdział', 'pt-br': 'Capítulo', 'ru': 'Глава', 'zh-cn': '章', 'zh-tw': '章' } return languages.get(language) def setTOCTitle(language): languages = { 'en': 'Table of Contents', 'de': 'Inhaltsverzeichnis', 'el': 'Πίνακας Περιεχομένων', 'es': 'Tabla de contenidos', 'fr': 'Table des matières', 'hu': 'Tartalom', 'it': 'Indice', 'ja': '目次', 'mn': 'Гарчиг', 'nl': 'Inhoudsopgave', 'pl': 'Spis treści', 'pt-br': 'Índice', 'ru': 'Содержание', 'zh-cn': '目录', 'zh-tw': '內容目錄' } return languages.get(language) def getPartNumber(number): numbers = { 1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V' } return numbers.get(number) def checkIsPart(chapter): if "part" in chapter: return True return False def checkIsPreface(chapterContent): if "[preface]" in chapterContent: return True return False def checkIsAppendix(chapterContent): if "[appendix]" in chapterContent: return True return False def main(argv): try: opts, args = getopt.getopt(argv,"hl:",["language="]) except getopt.GetoptError: print('books-toc-creator.py -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('books-toc-creator.py -l ') sys.exit() elif opt in ("-l", "--language"): languages = arg.split(',') for language in languages: with open('./content/{0}/books/handbook/chapters-order.adoc'.format(language), 'r', encoding = 'utf-8') as chaptersFile: chapters = [line.strip() for line in chaptersFile] - toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + toc = "// Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" toc += "[.toc]\n" toc += "--\n" toc += '[.toc-title]\n' toc += setTOCTitle(language) + '\n\n' chapterCounter = 1 subChapterCounter = 1 partCounter = 1 for chapter in chapters: with open('./content/{0}/books/handbook/{1}'.format(language, chapter), 'r', encoding = 'utf-8') as chapterFile: chapterContent = chapterFile.read().splitlines() chapterFile.close() chapter = chapter.replace("/_index.adoc", "").replace(".adoc", "") if checkIsPart(chapter): for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^={1} [^!<\n]+", chapterLine): toc += "* link:{0}[{1} {2}. {3}]\n".format(chapter, setPartTitle(language), getPartNumber(partCounter), chapterLine.replace("=", "").strip()) partCounter += 1 elif checkIsPreface(chapterContent): for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^={1} [^!<\n]+", chapterLine): toc += "* link:{0}[{1}]\n".format(chapter, chapterLine.replace("=", "").strip()) elif checkIsAppendix(chapterContent): for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^={1} [^!<\n]+", chapterLine): toc += "** link:{0}[{1} {2}]\n".format(chapter, setAppendixTitle(language), chapterLine.replace("=", "").strip()) elif re.match(r"^={2} [^\n]+", chapterLine): toc += "*** link:{0}/#{1}[{2}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterLine.replace("==", "").lstrip()) else: # Normal chapter for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^={1} [^!<\n]+", chapterLine): toc += "** link:{0}[{1} {2}. {3}]\n".format(chapter, setChapterTitle(language), chapterCounter, chapterLine.replace("=", "").strip()) elif re.match(r"^={2} [^\n]+", chapterLine): toc += "*** link:{0}/#{1}[{2}.{3}. {4}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterCounter, subChapterCounter, chapterLine.replace("==", "").lstrip()) subChapterCounter += 1 chapterCounter += 1 subChapterCounter = 1 # Reset subChapterCounter toc += "--\n" with open('./content/{0}/books/handbook/toc.adoc'.format(language), 'w', encoding = 'utf-8') as tocFile: tocFile.write(toc) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-examples-creator.py b/documentation/tools/books-toc-examples-creator.py index 1040b3cdfb..f72ffa945e 100644 --- a/documentation/tools/books-toc-examples-creator.py +++ b/documentation/tools/books-toc-examples-creator.py @@ -1,122 +1,122 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will generate the Table of Contents of the Handbook """ #!/usr/bin/env python3 import sys, getopt import re languages = [] """ To determine if a chapter is a chapter we are going to check if it is anything else, an appendix, a part, the preface ... and if it is not any of those, it will be a chapter. It may not be the best option, but it works :) """ def checkIsChapter(chapter, chapterContent): if "part" in chapter: return False elif "[preface]" in chapterContent: return False elif "[appendix]" in chapterContent: return False else: return True def setTOCTitle(language): languages = { 'en': 'List of Examples', 'de': 'Liste der Beispiele', 'el': 'Κατάλογος Παραδειγμάτων', 'es': 'Lista de ejemplos', 'fr': 'Liste des exemples', 'hu': 'A példák listája', 'it': 'Lista delle tabelle', 'ja': '例の一覧', 'mn': 'Жишээний жагсаалт', 'nl': 'Lijst van voorbeelden', 'pl': 'Spis przykładów', 'pt-br': 'Lista de Exemplos', 'ru': 'Список примеров', 'zh-cn': '范例清单', 'zh-tw': '範例目錄' } return languages.get(language) def main(argv): try: opts, args = getopt.getopt(argv,"hl:",["language="]) except getopt.GetoptError: print('books-toc-examples-creator.py -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('books-toc-examples-creator.py -l ') sys.exit() elif opt in ("-l", "--language"): languages = arg.split(',') for language in languages: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] for book in books: with open('./content/{0}/books/{1}/chapters-order.adoc'.format(language, book), 'r', encoding = 'utf-8') as chaptersFile: chapters = [line.strip() for line in chaptersFile] - toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + toc = "// Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" toc += "[.toc]\n" toc += "--\n" toc += '[.toc-title]\n' toc += setTOCTitle(language) + '\n\n' chapterCounter = 1 exampleCounter = 1 for chapter in chapters: with open('./content/{0}/books/{1}/{2}'.format(language, book, chapter), 'r', encoding = 'utf-8') as chapterFile: chapterContent = chapterFile.read().splitlines() chapterFile.close() chapter = chapter.replace("/_index.adoc", "").replace(".adoc", "").replace("/chapter.adoc", "") exampleId = "" exampleTitle = "" for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^\[example\]+", chapterLine) and re.match(r"^[.]{1}[^\n]+", chapterContent[lineNumber-2]) and re.match(r"^\[\[[^\n]+\]\]", chapterContent[lineNumber-3]): exampleTitle = chapterContent[lineNumber-2] exampleId = chapterContent[lineNumber-3] if book == "handbook": toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, exampleCounter, chapter, exampleId.replace("[[", "").replace("]]", ""), exampleTitle[1:]) else: toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, exampleCounter, "", exampleId.replace("[[", "").replace("]]", ""), exampleTitle[1:]) exampleCounter += 1 else: exampleId = "" exampleTitle = "" if checkIsChapter(chapter, chapterContent): chapterCounter += 1 exampleCounter = 1 # Reset example counter toc += "--\n" with open('./content/{0}/books/{1}/toc-examples.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: tocFile.write(toc) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-figures-creator.py b/documentation/tools/books-toc-figures-creator.py index 05139ffa80..46bea6226b 100644 --- a/documentation/tools/books-toc-figures-creator.py +++ b/documentation/tools/books-toc-figures-creator.py @@ -1,121 +1,121 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will generate the Table of Contents of the Handbook """ #!/usr/bin/env python3 import sys, getopt import re languages = [] """ To determine if a chapter is a chapter we are going to check if it is anything else, an appendix, a part, the preface ... and if it is not any of those, it will be a chapter. It may not be the best option, but it works :) """ def checkIsChapter(chapter, chapterContent): if "part" in chapter: return False elif "[preface]" in chapterContent: return False elif "[appendix]" in chapterContent: return False else: return True def setTOCTitle(language): languages = { 'en': 'List of Figures', 'de': 'Abbildungsverzeichnis', 'el': 'Κατάλογος Σχημάτων', 'es': 'Lista de figuras', 'fr': 'Liste des illustrations', 'hu': 'Az ábrák listája', 'it': 'Lista delle figure', 'ja': '図の一覧', 'mn': 'Зургийн жагсаалт', 'nl': 'Lijst van afbeeldingen', 'pl': 'Spis rysunków', 'pt-br': 'Lista de Figuras', 'ru': 'Список иллюстраций', 'zh-cn': '插图清单', 'zh-tw': '附圖目錄' } return languages.get(language) def main(argv): try: opts, args = getopt.getopt(argv,"hl:",["language="]) except getopt.GetoptError: print('books-toc-figures-creator.py -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('books-toc-figures-creator.py -l ') sys.exit() elif opt in ("-l", "--language"): languages = arg.split(',') for language in languages: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] for book in books: with open('./content/{0}/books/{1}/chapters-order.adoc'.format(language, book), 'r', encoding = 'utf-8') as chaptersFile: chapters = [line.strip() for line in chaptersFile] - toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + toc = "// Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" toc += "[.toc]\n" toc += "--\n" toc += '[.toc-title]\n' toc += setTOCTitle(language) + '\n\n' chapterCounter = 1 figureCounter = 1 for chapter in chapters: with open('./content/{0}/books/{1}/{2}'.format(language, book, chapter), 'r', encoding = 'utf-8') as chapterFile: chapterContent = chapterFile.read().splitlines() chapterFile.close() chapter = chapter.replace("/_index.adoc", "").replace(".adoc", "").replace("/chapter.adoc", "") figureId = "" figureTitle = "" for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^image::+", chapterLine) and re.match(r"^[.]{1}[^\n]+", chapterContent[lineNumber-2]) and re.match(r"^\[\[[^\n]+\]\]", chapterContent[lineNumber-3]): figureTitle = chapterContent[lineNumber-2] figureId = chapterContent[lineNumber-3] if book == "handbook": toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, figureCounter, chapter, figureId.replace("[[", "").replace("]]", ""), figureTitle[1:]) else: toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, figureCounter, "", figureId.replace("[[", "").replace("]]", ""), figureTitle[1:]) figureCounter += 1 else: figureId = "" figureTitle = "" if checkIsChapter(chapter, chapterContent): chapterCounter += 1 figureCounter = 1 # Reset figure counter toc += "--\n" with open('./content/{0}/books/{1}/toc-figures.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: tocFile.write(toc) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-parts-creator.py b/documentation/tools/books-toc-parts-creator.py index d36e8a3dde..86ed31fbd1 100644 --- a/documentation/tools/books-toc-parts-creator.py +++ b/documentation/tools/books-toc-parts-creator.py @@ -1,181 +1,181 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will generate the Table of Contents of the Handbook """ #!/usr/bin/env python3 import sys, getopt import re import os.path languages = [] def cleanTocFile(language, tocCounter): path = './content/{0}/books/handbook/toc-{1}.adoc'.format(language, tocCounter) if os.path.exists(path): tocFile = open(path, 'r+', encoding = 'utf-8') tocFile.truncate(0) def appendCommendAndTitle(language, tocCounter, tocContent): - toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + toc = "// Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" toc += "[.toc]\n" toc += "--\n" toc += '[.toc-title]\n' toc += setTOCTitle(language) + '\n\n' toc += tocContent toc += "--\n" tocFile = open('./content/{0}/books/handbook/toc-{1}.adoc'.format(language, tocCounter), 'a+', encoding = 'utf-8') tocFile.write(toc) def checkIsPart(chapter): if "part" in chapter: return True return False def checkIsPreface(chapterContent): if "[preface]" in chapterContent: return True return False def checkIsAppendix(chapterContent): if "[appendix]" in chapterContent: return True return False def setAppendixTitle(language): languages = { 'en': 'Appendix', 'de': 'Anhang', 'el': 'Παράρτημα', 'es': 'Apéndice', 'fr': 'Annexe', 'hu': 'függelék', 'it': 'Appendice', 'ja': '付録', 'mn': 'Хавсралт', 'nl': 'Bijlage', 'pl': 'Dodatek', 'pt-br': 'Apêndice', 'ru': 'Приложение', 'zh-cn': '附录', 'zh-tw': '附錄' } return languages.get(language) def setChapterTitle(language): languages = { 'en': 'Chapter', 'de': 'Kapitel', 'el': 'Κεφάλαιο', 'es': 'Capítulo', 'fr': 'Chapitre', 'hu': 'Fejezet', 'it': 'Capitolo', 'ja': '章', 'mn': 'Бүлэг', 'nl': 'Hoofdstuk', 'pl': 'Rozdział', 'pt-br': 'Capítulo', 'ru': 'Глава', 'zh-cn': '章', 'zh-tw': '章' } return languages.get(language) def setTOCTitle(language): languages = { 'en': 'Table of Contents', 'de': 'Inhaltsverzeichnis', 'el': 'Πίνακας Περιεχομένων', 'es': 'Tabla de contenidos', 'fr': 'Table des matières', 'hu': 'Tartalom', 'it': 'Indice', 'ja': '目次', 'mn': 'Гарчиг', 'nl': 'Inhoudsopgave', 'pl': 'Spis treści', 'pt-br': 'Índice', 'ru': 'Содержание', 'zh-cn': '目录', 'zh-tw': '內容目錄' } return languages.get(language) def main(argv): try: opts, args = getopt.getopt(argv,"hl:",["language="]) except getopt.GetoptError: print('handbook-toc-creator.py -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('handbook-toc-creator.py -l ') sys.exit() elif opt in ("-l", "--language"): languages = arg.split(',') for language in languages: with open('./content/{}/books/handbook/chapters-order.adoc'.format(language), 'r', encoding = 'utf-8') as chaptersFile: chapters = [line.strip() for line in chaptersFile] chapterCounter = 1 subChapterCounter = 1 partCounter = 0 toc = "" for chapter in chapters: with open('./content/{0}/books/handbook/{1}'.format(language, chapter), 'r', encoding = 'utf-8') as chapterFile: chapterContent = chapterFile.read().splitlines() chapterFile.close() chapter = chapter.replace("/_index.adoc", "").replace(".adoc", "") if checkIsPart(chapter): if partCounter > 0: cleanTocFile(language, partCounter) appendCommendAndTitle(language, partCounter, toc) toc = "" # Clean toc content partCounter += 1 elif checkIsPreface(chapterContent): pass elif checkIsAppendix(chapterContent): for lineNumber, chapterLine in enumerate(chapterContent, 1): if (re.match(r"^={1} [^\n]+", chapterLine)): toc += "* link:../{0}[{1} {2}]\n".format(chapter, setAppendixTitle(language), chapterLine.replace("=", "").strip()) elif (re.match(r"^={2} [^\n]+", chapterLine)): toc += "** link:../{0}/#{1}[{2}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterLine.replace("==", "").lstrip()) else: for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^={1} [^\n]+", chapterLine): toc += "* link:../{0}[{1} {2}. {3}]\n".format(chapter, setChapterTitle(language), chapterCounter, chapterLine.replace("=", "").strip()) elif re.match(r"^={2} [^\n]+", chapterLine): toc += "** link:../{0}/#{1}[{2}.{3}. {4}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterCounter, subChapterCounter, chapterLine.replace("==", "").lstrip()) subChapterCounter += 1 chapterCounter += 1 subChapterCounter = 1 # Reset subChapterCounter cleanTocFile(language, partCounter) appendCommendAndTitle(language, partCounter, toc) # For the last part if __name__ == "__main__": main(sys.argv[1:]) diff --git a/documentation/tools/books-toc-tables-creator.py b/documentation/tools/books-toc-tables-creator.py index 7ebd7acdec..592330b7a4 100644 --- a/documentation/tools/books-toc-tables-creator.py +++ b/documentation/tools/books-toc-tables-creator.py @@ -1,121 +1,121 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will generate the Table of Contents of the Handbook """ #!/usr/bin/env python3 import sys, getopt import re languages = [] """ To determine if a chapter is a chapter we are going to check if it is anything else, an appendix, a part, the preface ... and if it is not any of those, it will be a chapter. It may not be the best option, but it works :) """ def checkIsChapter(chapter, chapterContent): if "part" in chapter: return False elif "[preface]" in chapterContent: return False elif "[appendix]" in chapterContent: return False else: return True def setTOCTitle(language): languages = { 'en': 'List of Tables', 'de': 'Tabellenverzeichnis', 'el': 'Κατάλογος Πινάκων', 'es': 'Lista de tablas', 'fr': 'Liste des tableaux', 'hu': 'A táblázatok listája', 'it': 'Lista delle tabelle', 'ja': '表の一覧', 'mn': 'Хүснэгтийн жагсаалт', 'nl': 'Lijst van tabellen', 'pl': 'Spis tabel', 'pt-br': 'Lista de Tabelas', 'ru': 'Список таблиц', 'zh-cn': '表格清单', 'zh-tw': '附表目錄' } return languages.get(language) def main(argv): try: opts, args = getopt.getopt(argv,"hl:",["language="]) except getopt.GetoptError: print('books-toc-tables-creator.py -l ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('books-toc-tables-creator.py -l ') sys.exit() elif opt in ("-l", "--language"): languages = arg.split(',') for language in languages: with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile: books = [line.strip() for line in booksFile] for book in books: with open('./content/{0}/books/{1}/chapters-order.adoc'.format(language, book), 'r', encoding = 'utf-8') as chaptersFile: chapters = [line.strip() for line in chaptersFile] - toc = "// Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + toc = "// Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" toc += "// Please don't change this file manually but run `make` to update it.\n" toc += "// For more information, please read the FreeBSD Documentation Project Primer\n\n" toc += "[.toc]\n" toc += "--\n" toc += '[.toc-title]\n' toc += setTOCTitle(language) + '\n\n' chapterCounter = 1 tableCounter = 1 for chapter in chapters: with open('./content/{0}/books/{1}/{2}'.format(language, book, chapter), 'r', encoding = 'utf-8') as chapterFile: chapterContent = chapterFile.read().splitlines() chapterFile.close() chapter = chapter.replace("/_index.adoc", "").replace(".adoc", "").replace("/chapter.adoc", "") tableId = "" tableTitle = "" for lineNumber, chapterLine in enumerate(chapterContent, 1): if re.match(r"^\|\=\=\=+", chapterLine) and re.match(r"^[.]{1}[^\n]+", chapterContent[lineNumber-3]) and re.match(r"^\[\[[^\n]+\]\]", chapterContent[lineNumber-4]): tableTitle = chapterContent[lineNumber-3] tableId = chapterContent[lineNumber-4] if book == "handbook": toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, tableCounter, chapter, tableId.replace("[[", "").replace("]]", ""), tableTitle[1:]) else: toc += "* {0}.{1} link:{2}#{3}[{4}]\n".format(chapterCounter, tableCounter, "", tableId.replace("[[", "").replace("]]", ""), tableTitle[1:]) tableCounter += 1 else: tableId = "" tableTitle = "" if checkIsChapter(chapter, chapterContent): chapterCounter += 1 tableCounter = 1 # Reset table counter toc += "--\n" with open('./content/{0}/books/{1}/toc-tables.adoc'.format(language, book), 'w', encoding = 'utf-8') as tocFile: tocFile.write(toc) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/website/tools/releases-toml.py b/website/tools/releases-toml.py index 2e0b72b688..2dc96d310f 100644 --- a/website/tools/releases-toml.py +++ b/website/tools/releases-toml.py @@ -1,72 +1,72 @@ # -*- coding: utf-8 -*- """ BSD 2-Clause License Copyright (c) 2020-2021, The FreeBSD Project Copyright (c) 2020-2021, Sergio Carlavilla This script will convert the releases.adoc file to releases.toml in this way we can share the releases variables between AsciiDoctor and Hugo """ #!/usr/bin/env python3 import sys, getopt import re variables = {} def getValueByKey(key): return variables[key.replace("{", "").replace("}", "")].replace("\"", "") def loadVariables(path): with open(path, 'r', encoding = 'utf-8') as releasesFile: line = releasesFile.readline() while line: if (re.match(r"^:{1}[^\n]+", line)): variable = re.sub(':', '', line.strip(), 1) variable = re.sub(': ', '="', variable) variable += "\"" data = variable.split("=") if (len(data) == 2): variables.update( {data[0] : data[1]} ) line = releasesFile.readline() def main(argv): path = '' try: opts, args = getopt.getopt(argv,"hp:",["path="]) except getopt.GetoptError: print('releases-toml.py -p ') sys.exit(2) for opt, arg in opts: if opt == '-h': print('releases-toml.py -p ') sys.exit() elif opt in ("-p", "--path"): path = arg - releasesTOML = "# Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" + releasesTOML = "# Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" releasesTOML += "# Please don't change this file manually but run `make` to update it.\n" releasesTOML += "# For more information, please read the FreeBSD Documentation Project Primer\n" releasesTOML += '\n' loadVariables(path) for key in variables: foundBraces = re.search(r"\{.*?\}", variables[key]) if (foundBraces): braces = foundBraces.group(0) releasesTOML += key + "=" + variables[key].replace(braces, getValueByKey(braces)) + "\n" else: releasesTOML += key + "=" + variables[key] + "\n" with open('./data/releases.toml', 'w', encoding = 'utf-8') as releasesTOMLFile: releasesTOMLFile.write(releasesTOML) if __name__ == "__main__": main(sys.argv[1:])