From 2cdcc75ad3ce38023b307a2aa3bcd9c0a1013c2a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 8 Sep 2022 17:30:05 +0200 Subject: Adapt each QUIP's self-link to use the right URL Originally QUIPs were to be simply numbered. At some point we realized we could include some mention of the subject matter in the rst-file name. However, the quip2html script was still assuming quip-0012.html (for example) would be the URL of QUIP 12, without its subject matter suffix. Amend the script, and the template's token used to build the URL, to include the full filename stem (without .rst suffix) in the URL (with a .html suffix). Change-Id: I04d09c3ae80620d13f62a2f8cd2b3dcce3d159b8 Reviewed-by: Cristian Maureira-Fredes --- scripts/quip2html.py | 12 +++++++----- scripts/template.diff | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/quip2html.py b/scripts/quip2html.py index 8d83a13..47f1449 100755 --- a/scripts/quip2html.py +++ b/scripts/quip2html.py @@ -164,6 +164,11 @@ class QuipReader(standalone.Reader): standalone.Reader.__init__(self, parser, '') class QuipWriter(html4css1.Writer): + def __init__(self, stem): + # For gen-quip-0000 we want quip-0000; otherwise, use the stem as is: + self.__stem = stem[4:] if stem.startswith('gen-') else stem + super().__init__() + # Assumed to be run from the build directory cwd_file = os.path.join(os.getcwd(), 'dummy') script_dir = os.path.dirname(__file__) @@ -202,10 +207,7 @@ class QuipWriter(html4css1.Writer): header = self.document[index] self.quipnum = header[0][1].astext() subs['quip'] = self.quipnum - try: - subs['quipnum'] = '%04i' % int(self.quipnum) - except ValueError: - subs['quipnum'] = self.quipnum + subs['urlstem'] = self.__stem self.title = header[1][1].astext() subs['title'] = 'QUIP %s | %s' % (self.quipnum, self.title) subs['body'] = ''.join(self.body_pre_docinfo + self.docinfo + self.body) @@ -244,7 +246,7 @@ def main(filename, source, output, stderr): reader=QuipReader(), parser_name='restructuredtext', writer_name='html4css1', - writer=QuipWriter(), + writer=QuipWriter(os.path.splitext(git.base)[0]), # Allow Docutils traceback if there's an exception: settings_overrides={'traceback': True, 'halt_level': 2, # output.write needs a string: diff --git a/scripts/template.diff b/scripts/template.diff index ff508c1..34ef265 100644 --- a/scripts/template.diff +++ b/scripts/template.diff @@ -50,7 +50,7 @@ +

%(title)s

+ +
+%(body)s -- cgit v1.2.3