]> Shamusworld >> Repos - ardour-manual/blob - build.py
Updated the Grid & Snap page.
[ardour-manual] / build.py
1 #!/usr/bin/python3
2 #
3 # Script to take the master document and ancillary files and create the
4 # finished manual/website.
5 #
6 # by James Hammons
7 # (C) 2020 Underground Software
8 #
9 # Contributors: Ed Ward
10 #
11
12 # Remnants (could go into the master document as the first header)
13
14 import os
15 import re
16 import shutil
17 import argparse
18 import datetime
19
20 # Global vars
21 global_bootstrap_path = '/bootstrap-3.3.7'
22 global_page_title = 'The Ardour Manual'
23 global_site_dir = './website/'
24 global_manual_url = 'http://manual.ardour.org'
25 global_githuburl = 'https://github.com/Ardour/manual/edit/master/include/'
26 global_screen_template = 'page-template.html'
27 global_onepage_template = 'onepage-template.html'
28 global_pdf_template = 'pdf-template.html'
29 global_master_doc = 'master-doc.txt'
30 global_pdflink = '<button class="btn btn-default" type="button" onclick="window.location.href=\'/manual.pdf\'"><span class="glyphicon glyphicon-book" aria-hidden="true"></span></button>'
31 from datetime import datetime
32 global_today = datetime.today().strftime('%Y-%m-%d')
33
34 # This matches all *non* letter/number, ' ', '.', '-', and '_' chars
35 cleanString = re.compile(r'[^a-zA-Z0-9 \._-]+')
36 # This matches new 'unbreakable' links, up to the closing quote or anchor
37 findLinks = re.compile(r'"@@[^#"]*[#"]')
38
39 #
40 # Create an all lowercase filename without special characters and with spaces
41 # replaced with dashes.
42 #
43 def MakeFilename(s):
44         global cleanString
45         # Clean up the file name, removing all non letter/number or " .-_" chars.
46         # Also, convert to lower case and replace all spaces with dashes.
47         fn = cleanString.sub('', s).lower().replace(' ', '-')
48         # Double dashes can creep in from the above replacement, so we check for
49         # that here.
50         fn = fn.replace('--', '-')
51
52         return fn
53
54
55 #
56 # Parse headers into a dictionary
57 #
58 def ParseHeader(fileObj):
59         header = {}
60
61         while (True):
62                 hdrLine = fileObj.readline().rstrip('\r\n')
63
64                 # Break out of the loop if we hit the end of header marker
65                 if hdrLine.startswith('---'):
66                         break
67
68                 # Check to see that we have a well-formed header construct
69                 match = re.findall(': ', hdrLine)
70
71                 if match:
72                         # Parse out foo: bar pairs & put into header dictionary
73                         a = re.split(': ', hdrLine, 1)
74                         header[a[0]] = a[1]
75
76         return header
77
78
79 #
80 # Turn a "part" name into an int
81 #
82 def PartToLevel(s):
83         lvl = {'part': 0, 'chapter': 1, 'subchapter': 2, 'section': 3, 'subsection': 4 }
84
85         if s in lvl:
86                 return lvl[s]
87
88         return -1
89
90
91 #
92 # Converts a integer to a Roman numeral
93 #
94 def num2roman(num):
95         num_map = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')]
96         roman = ''
97
98         while num > 0:
99                 for i, r in num_map:
100                         while num >= i:
101                                 roman += r
102                                 num -= i
103
104         return roman
105
106 #
107 # Capture the master document's structure (and content, if any) in a list
108 #
109 def GetFileStructure():
110         fs = []
111         fnames = [None] * 6
112         content = ''
113         grab = False
114         mf = open(global_master_doc)
115
116         for ln in mf:
117                 if ln.startswith('---'):
118                         # First, stuff any content that we may have read into the current
119                         # header's dictionary
120                         if grab:
121                                 fs[-1]['content'] = content
122                                 grab = False
123                                 content = ''
124
125                         # Then, get the new header and do things to it
126                         hdr = ParseHeader(mf)
127                         level = PartToLevel(hdr['part'])
128                         hdr['level'] = level
129                         fnames[level] = MakeFilename(hdr['title'])
130
131                         # Ickyness--user specified URIs
132                         if 'uri' in hdr:
133                                 hdr['filename'] = hdr['uri']
134                         else:
135                                 fullName = ''
136
137                                 for i in range(level + 1):
138                                         fullName = fullName + fnames[i] + '/'
139
140                                 # Strip trailing '/' on filename
141                                 hdr['filename'] = fullName[:-1]
142
143                         fs.append(hdr)
144
145                         if ('include' not in hdr) and (level > 0):
146                                 grab = True
147                 else:
148                         if grab:
149                                 content = content + ln
150
151         # Catch the last file, since it would be missed above
152         if grab:
153                 fs[-1]['content'] = content
154
155         mf.close()
156         return fs
157
158
159 #
160 # Determine if a particular node has child nodes
161 #
162 def HaveChildren(fs, pos):
163         # If we're at the end of the list, there can be no children
164         if pos == len(fs) - 1:
165                 return False
166
167         # If the next node is at a lower level than the current node, we have
168         # children.
169         if fs[pos]['level'] < fs[pos + 1]['level']:
170                 return True
171
172         # Otherwise, no children at this node.
173         return False
174
175
176 #
177 # Get the children at this level, and return them in a list
178 #
179 def GetChildren(fs, pos):
180         children = []
181         pos = pos + 1
182         childLevel =  fs[pos]['level']
183
184         while fs[pos]['level'] >= childLevel:
185                 if fs[pos]['level'] == childLevel:
186                         children.append(pos)
187
188                 pos = pos + 1
189
190                 # Sanity check
191                 if pos == len(fs):
192                         break
193
194         return children
195
196
197 #
198 # Get the parent at this level
199 #
200 def GetParent(fs, pos):
201         thisLevel =  fs[pos]['level']
202         pos = pos - 1
203
204         while pos >= 0 and fs[pos]['level'] >= thisLevel:
205                 pos = pos - 1
206
207         return pos
208
209
210 #
211 # Change the hierarchy of titles : h1->hn, h2->hn+1, etc... n being delta-1
212 #
213 def reheader(txt, delta):
214         for i in range(6, 0, -1):
215                 txt = txt.replace('<h' + str(i), '<h' + str(i + delta))
216                 txt = txt.replace('</h' + str(i), '</h' + str(i + delta))
217
218         return txt
219
220
221 #
222 # Creates the BreadCrumbs
223 #
224 def GetBreadCrumbs(fs, pos):
225         breadcrumbs = '<li class="active">'+ fs[pos]['title'] + '</li>'
226
227         while pos >= 0:
228                 pos = GetParent(fs, pos)
229
230                 if pos >= 0:
231                         breadcrumbs='<li><a href="/' + fs[pos]['filename'] + '/">'+ fs[pos]['title'] + '</a></li>'+ breadcrumbs
232
233         breadcrumbs = '<ul class="breadcrumb"><li><a href="/toc/index.html">Home</a></li>' + breadcrumbs + '</ul>'
234         return breadcrumbs
235
236
237 #
238 # Make an array of children attached to each node in the file structure
239 # (It's a quasi-tree structure, and can be traversed as such.)
240 #
241 def FindChildren(fs):
242         childArray = []
243
244         for i in range(len(fs)):
245                 if HaveChildren(fs, i):
246                         childArray.append(GetChildren(fs, i))
247                 else:
248                         childArray.append([])
249
250         return childArray
251
252
253 #
254 # Make an array of the top level nodes in the file structure
255 #
256 def FindTopLevelNodes(fs):
257         level0 = []
258
259         for i in range(len(fs)):
260                 if fs[i]['level'] == 0:
261                         level0.append(i)
262
263         return level0
264
265
266 #
267 # Find all header links and create a dictionary out of them
268 #
269 def FindInternalLinks(fs):
270         linkDict = {}
271
272         for hdr in fs:
273                 if 'link' in hdr:
274                         linkDict['"@@' + hdr['link'] + '"'] = '"/' + hdr['filename'] + '/"'
275                         linkDict['"@@' + hdr['link'] + '#'] = '"/' + hdr['filename'] + '/index.html#'
276
277         return linkDict
278
279
280 #
281 # Same as above, but create anchors (for the one-page version)
282 #
283 def FindInternalAnchors(fs):
284         linkDict = {}
285
286         for hdr in fs:
287                 if 'link' in hdr:
288                         linkDict['"@@' + hdr['link'] + '"'] = '"#' + hdr['link'] + '"'
289                         linkDict['"@@' + hdr['link'] + '#'] = '"#' + hdr['link'] + '"'
290
291         return linkDict
292
293
294 #
295 # Internal links are of the form '@@link-name', which are references to the
296 # 'link:' field in the part header. We have to find all occurrences and replace
297 # them with the appropriate link.
298 #
299 def FixInternalLinks(links, content, title):
300         global findLinks
301         match = findLinks.findall(content)
302         missing = []
303
304         if len(match) > 0:
305                 for s in match:
306                         if s in links:
307                                 content = content.replace(s, links[s])
308                         else:
309                                 missing.append(s)
310
311         # Report missing link targets to the user (if any)
312         if len(missing) > 0:
313                 print('\nMissing link target' + ('s' if len(missing) > 1 else '') + ' in "' + title + '":')
314
315                 for s in missing:
316                         print('  ' + s)
317
318                 print()
319
320         return content
321
322
323 #
324 # Recursively build a list of links based on the location of the page we're
325 # looking at currently
326 #
327 def BuildList(lst, fs, pagePos, cList):
328         content = '<ul>\n'
329
330         for i in range(len(lst)):
331                 curPos = lst[i]
332                 nextPos = lst[i + 1] if i + 1 < len(lst) else len(fs)
333
334                 active = ' class=active' if curPos == pagePos else ''
335                 menuTitle = fs[curPos]['menu_title'] if 'menu_title' in fs[curPos] else fs[curPos]['title']
336                 content = content + '\t<li' + active + '><a href="/' + fs[curPos]['filename'] + '/">' + menuTitle + '</a></li>\n'
337
338                 # If the current page is our page, and it has children, enumerate them
339                 if curPos == pagePos:
340                         if len(cList[curPos]) > 0:
341                                 content = content + BuildList(cList[curPos], fs, -1, cList)
342
343                 # Otherwise, if our page lies between the current one and the next,
344                 # build a list of links from those nodes one level down.
345                 elif (pagePos > curPos) and (pagePos < nextPos):
346                         content = content + BuildList(cList[curPos], fs, pagePos, cList)
347
348         content = content + '</ul>\n'
349
350         return content
351
352
353 #
354 # Builds the sidebar for the one-page version
355 #
356 def BuildOnePageSidebar(fs):
357
358         content = '\n\n<ul class="toc">\n'
359         lvl = 0
360         levelNums = [0] * 5
361
362         for i in range(len(fs)):
363                 # Handle Part/Chapter/subchapter/section/subsection numbering
364                 level = fs[i]['level']
365
366                 if level < 2:
367                         levelNums[2] = 0
368
369                 levelNums[level] = levelNums[level] + 1;
370                 j = level
371                 txtlevel = ''
372
373                 while j > 0:  #level 0 is the part number which is not shown
374                         txtlevel = str(levelNums[j]) + '.' + txtlevel
375                         j = j - 1
376
377                 if len(txtlevel) > 0:
378                         txtlevel = txtlevel[:-1] + ' - '
379
380                 if 'link' in fs[i]:
381                         anchor = fs[i]['link']
382                 else:
383                         anchor = fs[i]['filename']
384
385                 while lvl < level:
386                         content = content + '<ul class="toc">\n'
387                         lvl = lvl + 1
388
389                 while lvl > level:
390                         content = content + '</ul>\n'
391                         lvl = lvl - 1
392
393                 content = content + '<li><a href="#' + anchor + '">' + txtlevel + fs[i]['title'] + '</a></li>\n'
394
395         content = content + '</ul>\n'
396
397         return content
398
399
400 #
401 # Create link sidebar given a position in the list.
402 #
403 def CreateLinkSidebar(fs, pos, childList):
404
405         # Build the list recursively from the top level nodes
406         content = BuildList(FindTopLevelNodes(fs), fs, pos, childList)
407         # Shove the TOC link and one file link at the top...
408         active = ' class=active' if pos < 0 else ''
409         content = content.replace('<ul>', '<ul><li' + active + '><a href="/toc/">Table of Contents</a></li>\n', 1)
410
411         return content
412
413
414 # Preliminaries
415
416 # We have command line arguments now, so deal with them
417 parser = argparse.ArgumentParser(description='A build script for the Ardour Manual')
418 parser.add_argument('-v', '--verbose', action='store_true', help='Display the high-level structure of the manual')
419 parser.add_argument('-q', '--quiet', action='store_true', help='Suppress all output (overrides -v)')
420 parser.add_argument('-d', '--devmode', action='store_true', help='Add content to pages to help developers debug them')
421 parser.add_argument('-p', '--pdf', action='store_true', help='Automatically generate PDF from content')
422 args = parser.parse_args()
423 verbose = args.verbose
424 noisy = not args.quiet
425 devmode = args.devmode
426 pdf = args.pdf
427
428 # --quiet overrides --verbose, so tell it to shut up if user did both
429 if not noisy:
430         verbose = False
431
432 level = 0
433 fileCount = 0
434 levelNums = [0] * 5
435 lastFile = ''
436 page = ''
437 onepage = ''
438 pdfpage = ''
439 toc = ''
440 pageNumber = 0
441
442 if noisy and devmode:
443         print('Devmode active: scribbling extra junk to the manual...')
444
445 if os.access(global_site_dir, os.F_OK):
446         if noisy:
447                 print('Removing stale HTML data...')
448
449         shutil.rmtree(global_site_dir)
450
451 shutil.copytree('./source', global_site_dir)
452
453 # Read the template, and fix the stuff that's fixed for all pages
454 temp = open(global_screen_template)
455 template = temp.read()
456 temp.close()
457 template = template.replace('{{page.bootstrap_path}}', global_bootstrap_path)
458 template = template.replace('{{page.page_title}}', global_page_title)
459 if pdf:
460         template = template.replace('{{page.page_pdflink}}', global_pdflink)
461 else:
462         template = template.replace('{{page.page_pdflink}}', '')
463
464
465 # Same as above, but for the "One-Page" version
466 temp = open(global_onepage_template)
467 onepage = temp.read()
468 temp.close()
469 onepage = onepage.replace('{{page.bootstrap_path}}', global_bootstrap_path)
470 onepage = onepage.replace('{{page.page_title}}', global_page_title)
471
472 if pdf:
473         # Same as above, but for the PDF version
474         temp = open(global_pdf_template)
475         pdfpage = temp.read()
476         temp.close()
477         pdfpage = pdfpage.replace('{{page.page_title}}', global_page_title)
478
479 # Parse out the master document's structure into a dictionary list
480 fileStruct = GetFileStructure()
481
482 # Build a quasi-tree structure listing children at level + 1 for each node
483 nodeChildren = FindChildren(fileStruct)
484
485 # Create a dictionary for translation of internal links to real links
486 links = FindInternalLinks(fileStruct)
487 oplinks = FindInternalAnchors(fileStruct)
488
489 if noisy:
490         print('Found ' + str(len(links)) + ' internal link target', end='')
491         print('.') if len(links) == 1 else print('s.')
492
493 if noisy:
494         master = open(global_master_doc)
495         firstLine = master.readline().rstrip('\r\n')
496         master.close()
497
498         if firstLine == '<!-- exploded -->':
499                 print('Parsing exploded file...')
500         elif firstLine == '<!-- imploded -->':
501                 print('Parsing imploded file...')
502         else:
503                 print('Parsing unknown type...')
504
505 # Here we go!
506
507 for header in fileStruct:
508         fileCount = fileCount + 1
509         content = ''
510         more = ''
511
512         lastLevel = level
513         level = header['level']
514
515         # Handle Part/Chapter/subchapter/section/subsection numbering
516         if level < 2:
517                 levelNums[2] = 0
518
519         levelNums[level] = levelNums[level] + 1;
520
521         # This is totally unnecessary, but nice; besides which, you can capture
522         # the output to a file to look at later if you like :-)
523         if verbose:
524                 for i in range(level):
525                         print('\t', end='')
526
527                 if (level == 0):
528                         print('\nPart ' + num2roman(levelNums[0]) + ': ', end='')
529                 elif (level == 1):
530                         print('\n\tChapter ' + str(levelNums[1]) + ': ', end='')
531
532                 print(header['title'])
533
534         # Handle TOC scriblings...
535         if level == 0:
536                 toc = toc + '<h2>Part ' + num2roman(levelNums[level]) + ': ' + header['title'] + '</h2>\n';
537         elif level == 1:
538                 toc = toc + '\t<p class="chapter">Ch. ' + str(levelNums[level]) + ':&nbsp;&nbsp;<a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
539         elif level == 2:
540                 toc = toc + '\t\t<p class="subchapter"><a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
541         elif level == 3:
542                 toc = toc + '<p class="section"><a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
543         elif level == 4:
544                 toc = toc + '<p class="subsection"><a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
545
546         # Make the 'this thing contains...' stuff
547         if HaveChildren(fileStruct, pageNumber):
548                 pages = GetChildren(fileStruct, pageNumber)
549
550                 for pg in pages:
551                         more = more + '<li>' + '<a href="/' + fileStruct[pg]['filename'] + '/">' + fileStruct[pg]['title'] + '</a>' + '</li>\n'
552
553                 more = '<div id=subtopics>\n' + '<h2>This section contains the following topics:</h2>\n' + '<ul>\n' + more + '</ul>\n' + '</div>\n'
554
555         parent = GetParent(fileStruct, pageNumber)
556
557         # Make the 'Previous', 'Up' & 'Next' content
558         nLink = ''
559         pLink = ''
560         uLink = ''
561
562         if pageNumber > 0:
563                 pLink = '<li class="previous"><a title="' + fileStruct[pageNumber - 1]['title'] + '" href="/' + fileStruct[pageNumber - 1]['filename'] + '/" class="previous"> &larr; Previous </a></li>'
564
565         if pageNumber < len(fileStruct) - 1:
566                 nLink = '<li class="next"><a title="' + fileStruct[pageNumber + 1]['title'] + '" href="/' + fileStruct[pageNumber + 1]['filename'] + '/" class="next"> Next &rarr; </a></li>'
567
568         if level > 0:
569                 uLink = '<li><a title="' + fileStruct[parent]['title'] + '" href="/' + fileStruct[parent]['filename'] + '/" class="active"> &uarr; Up </a></li>'
570         else:
571                 uLink = '<li><a title="Ardour Table of Contents" href="/toc/index.html" class="active"> &uarr; Up </a></li>'
572
573         prevnext = '<ul class="pager">' + pLink + uLink + nLink + '</ul>'
574
575         # Make the BreadCrumbs
576         breadcrumbs = GetBreadCrumbs(fileStruct, pageNumber)
577
578         # Create the link sidebar
579         sidebar = CreateLinkSidebar(fileStruct, pageNumber, nodeChildren)
580
581         # Parts DO NOT have any content, they are ONLY an organizing construct!
582         # Chapters, subchapters, sections & subsections can all have content,
583         # but the basic fundamental organizing unit WRT content is still the
584         # chapter.
585         githubedit = ''
586
587         if level > 0:
588                 if 'include' in header:
589                         srcFile = open('include/' + header['include'])
590                         githubedit = '<span style="float:right;"><a title="Edit in GitHub" href="' + global_githuburl + header['include'] + '"><img src="/images/github.png" alt="Edit in GitHub"/></a></span>'
591                         content = srcFile.read()
592                         srcFile.close()
593
594                         # Get rid of any extant header in the include file
595                         # (once this is accepted, we can nuke this bit, as content files
596                         # will not have any headers or footers in them)
597                         content = re.sub('---.*\n(.*\n)*---.*\n', '', content)
598                         content = content.replace('{% children %}', '')
599
600                 else:
601                         if 'content' in header:
602                                 content = header['content']
603                         else:
604                                 content = '[something went wrong]'
605
606         # Add header information to the page if in dev mode
607         if devmode:
608                 devnote ='<aside style="background-color:indigo; color:white;">'
609
610                 if 'filename' in header:
611                         devnote = devnote + 'filename: ' + header['filename'] + '<br>'
612
613                 if 'include' in header:
614                         devnote = devnote + 'include: ' + header['include'] + '<br>'
615
616                 if 'link' in header:
617                         devnote = devnote + 'link: ' + header['link'] + '<br>'
618
619                 content = devnote + '</aside>' + content
620
621         # ----- One page and PDF version -----
622
623         # Fix up any internal links
624         opcontent = FixInternalLinks(oplinks, content, header['title'])
625         opcontent = reheader(opcontent, 2)
626
627         # Create "one page" header
628         oph = '<h' + str(level+1) + ' class="clear" id="' + header[('link' if 'link' in header else 'filename')] +'">' + header['title'] + '</h' + str(level+1) + '>\n';
629
630         # Set up the actual page from the template
631         onepage = onepage.replace('{{ content }}', oph + '\n' + opcontent + '\n{{ content }}')
632
633         if pdf:
634                 if not 'pdf-exclude' in header:
635                         pdfpage = pdfpage.replace('{{ content }}', oph + '\n' + opcontent + '\n{{ content }}')
636                 else:
637                         pdfpage = pdfpage.replace('{{ content }}', oph + '\n' + 'Please refer to the <a href="' + global_manual_url + '/' + header['filename'] + '/">online manual</a>.\n{{ content }}')
638
639         # ----- Normal version -----
640
641         # Fix up any internal links
642         content = FixInternalLinks(links, content, header['title'])
643
644         # Set up the actual page from the template
645         if 'style' not in header:
646                 page = re.sub("{% if page.style %}.*\n.*\n{% endif %}.*\n", "", template)
647         else:
648                 page = template.replace('{{page.style}}', header['style'])
649                 page = page.replace('{% if page.style %}', '')
650                 page = page.replace('{% endif %}', '')
651
652         page = page.replace('{{ page.title }}', header['title'])
653         page = page.replace('{% tree %}', sidebar)
654         page = page.replace('{% prevnext %}', prevnext)
655         page = page.replace('{% githubedit %}', githubedit)
656         page = page.replace('{% breadcrumbs %}', breadcrumbs)
657         page = page.replace('{{ content }}', content + more)
658
659         # Create the directory for the index.html file to go into (we use makedirs,
660         # because we have to in order to accomodate the 'uri' keyword)
661         os.makedirs(global_site_dir + header['filename'], 0o775, exist_ok=True)
662
663         # Finally, write the file!
664         destFile = open(global_site_dir + header['filename'] + '/index.html', 'w')
665         destFile.write(page)
666         destFile.close()
667
668         # Save filename for next header...
669         lastFile = header['filename']
670         pageNumber = pageNumber + 1
671
672 # Finally, create the TOC
673 sidebar = CreateLinkSidebar(fileStruct, -1, nodeChildren)
674
675 page = re.sub("{% if page.style %}.*\n.*\n{% endif %}.*\n", "", template)
676 page = page.replace('{{ page.title }}', 'Ardour Table of Contents')
677 page = page.replace('{% tree %}', sidebar)
678 page = page.replace('{{ content }}', toc)
679 page = page.replace('{% prevnext %}', '')
680 page = page.replace('{% githubedit %}', '')
681 page = page.replace('{% breadcrumbs %}', '')
682
683 os.mkdir(global_site_dir + 'toc', 0o775)
684 tocFile = open(global_site_dir + 'toc/index.html', 'w')
685 tocFile.write(page)
686 tocFile.close()
687
688 # Create the one-page version of the documentation
689 onepageFile = open(global_site_dir + 'ardourmanual.html', 'w')
690 opsidebar = BuildOnePageSidebar(fileStruct) # create the link sidebar
691 onepage = onepage.replace('{% tree %}', opsidebar)
692 onepage = onepage.replace('{{ content }}', '') # cleans up the last spaceholder
693 onepageFile.write(onepage)
694 onepageFile.close()
695
696 if pdf:
697         if noisy:
698                 print('Generating the PDF...')
699                 import logging
700                 logger = logging.getLogger('weasyprint')
701                 logger.addHandler(logging.StreamHandler())
702
703         # Create the PDF version of the documentation
704         pdfpage = pdfpage.replace('{% tree %}', opsidebar) # create the TOC
705         pdfpage = pdfpage.replace('{{ content }}', '') # cleans up the last spaceholder
706         pdfpage = pdfpage.replace('{{ today }}', global_today)
707         pdfpage = pdfpage.replace('src="/images/', 'src="images/') # makes images links relative
708         pdfpage = pdfpage.replace('url(\'/images/', 'url(\'images/') # CSS images links relative
709         # Write it to disk (optional, can be removed)
710         pdfpageFile = open(global_site_dir + 'pdf.html', 'w')
711         pdfpageFile.write(pdfpage)
712         pdfpageFile.close()
713
714         # Generating the actual PDF with weasyprint (https://weasyprint.org/)
715         from weasyprint import HTML
716         from weasyprint.fonts import FontConfiguration
717         
718         html_font_config = FontConfiguration()
719         doc = HTML(string = pdfpage, base_url = global_site_dir)
720         doc.write_pdf(global_site_dir + 'manual.pdf', font_config = html_font_config)
721
722 if noisy:
723         print('Processed ' + str(fileCount) + ' files.')
724