git: cd5051bbed - main - Modify the script used to generate the ToC parts

Sergio Carlavilla Delgado <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.doc
Message-ID <[email protected]>
The branch main has been updated by carlavilla:

URL: https://cgit.FreeBSD.org/doc/commit/?id=cd5051bbedb0a91ba0235e325a15904111f8f670

commit cd5051bbedb0a91ba0235e325a15904111f8f670
Author:     Sergio Carlavilla Delgado <[email protected]>
AuthorDate: 2021-03-31 21:52:38 +0000
Commit:     Sergio Carlavilla Delgado <[email protected]>
CommitDate: 2021-03-31 21:52:38 +0000

    Modify the script used to generate the ToC parts
    
    Modify the script used to generate the different ToC
    for the partN.adoc files
---
 documentation/tools/books-toc-parts-creator.py | 92 ++++++++++++++------------
 1 file changed, 49 insertions(+), 43 deletions(-)

diff --git a/documentation/tools/books-toc-parts-creator.py b/documentation/tools/books-toc-parts-creator.py
index 86ed31fbd1..b05aeb9dc5 100644
--- a/documentation/tools/books-toc-parts-creator.py
+++ b/documentation/tools/books-toc-parts-creator.py
@@ -13,14 +13,14 @@ import os.path
 
 languages = []
 
-def cleanTocFile(language, tocCounter):
-    path = './content/{0}/books/handbook/toc-{1}.adoc'.format(language, tocCounter)
+def cleanTocFile(language, tocCounter, book):
+    path = './content/{0}/books/{1}/toc-{2}.adoc'.format(language, book, 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"
+def appendCommendAndTitle(language, tocCounter, tocContent, book):
+  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"
@@ -30,7 +30,7 @@ def appendCommendAndTitle(language, tocCounter, tocContent):
   toc += tocContent
   toc += "--\n"
 
-  tocFile = open('./content/{0}/books/handbook/toc-{1}.adoc'.format(language, tocCounter), 'a+', encoding = 'utf-8')
+  tocFile = open('./content/{0}/books/{1}/toc-{2}.adoc'.format(language, book, tocCounter), 'a+', encoding = 'utf-8')
   tocFile.write(toc)
 
 def checkIsPart(chapter):
@@ -116,66 +116,72 @@ def main(argv):
   try:
     opts, args = getopt.getopt(argv,"hl:",["language="])
   except getopt.GetoptError:
-    print('handbook-toc-creator.py -l <language>')
+    print('books-toc-creator.py -l <language>')
     sys.exit(2)
   for opt, arg in opts:
     if opt == '-h':
-      print('handbook-toc-creator.py -l <language>')
+      print('books-toc-creator.py -l <language>')
       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 = ""
+    with open('./content/{}/books/books.adoc'.format(language), 'r', encoding = 'utf-8') as booksFile:
+      books = [line.strip() for line in booksFile]
 
-    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", "")
+      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]
 
-        if checkIsPart(chapter):
+        chapterCounter = 1
+        subChapterCounter = 1
+        partCounter = 0
+        toc = ""
 
-          if partCounter > 0:
-            cleanTocFile(language, partCounter)
-            appendCommendAndTitle(language, partCounter, toc)
-            toc = "" # Clean toc content
+        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", "")
 
-          partCounter += 1
+            if checkIsPart(chapter):
 
-        elif checkIsPreface(chapterContent):
-          pass
+              if partCounter > 0:
+                cleanTocFile(language, partCounter, book)
+                appendCommendAndTitle(language, partCounter, toc, book)
+                toc = "" # Clean toc content
 
-        elif checkIsAppendix(chapterContent):
-          for lineNumber, chapterLine in enumerate(chapterContent, 1):
+              partCounter += 1
 
-            if (re.match(r"^={1} [^\n]+", chapterLine)):
-              toc += "* link:../{0}[{1} {2}]\n".format(chapter, setAppendixTitle(language), chapterLine.replace("=", "").strip())
+            elif checkIsPreface(chapterContent):
+              pass
 
-            elif (re.match(r"^={2} [^\n]+", chapterLine)):
-              toc += "** link:../{0}/#{1}[{2}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterLine.replace("==", "").lstrip())
+            elif checkIsAppendix(chapterContent):
+              for lineNumber, chapterLine in enumerate(chapterContent, 1):
 
-        else:
-          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())
 
-            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}]\n".format(chapter, chapterContent[lineNumber-2].replace("[[", "").replace("]]", ""), chapterLine.replace("==", "").lstrip())
 
-            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
+            else:
+              for lineNumber, chapterLine in enumerate(chapterContent, 1):
 
-          chapterCounter += 1
-          subChapterCounter = 1 # Reset subChapterCounter
+                if re.match(r"^={1} [^!<\n]+", chapterLine):
+                  toc += "* link:../{0}[{1} {2}. {3}]\n".format(chapter, setChapterTitle(language), chapterCounter, chapterLine.replace("=", "").strip())
 
-    cleanTocFile(language, partCounter)
-    appendCommendAndTitle(language, partCounter, toc) # For the last part
+                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
+
+        if partCounter > 0:
+          cleanTocFile(language, partCounter, book)
+          appendCommendAndTitle(language, partCounter, toc, book) # For the last part
 
 if __name__ == "__main__":
   main(sys.argv[1:])
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-doc-all
To unsubscribe, send any mail to "[email protected]"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.