From 909bdb1fa441f76d54b1195b99c248ec1046892f Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 10 Jul 2021 18:46:33 -0700 Subject: [PATCH] Tweak web page include structure Renamed from "*-incl.html" to "incl-*.html" so they sort together. Moved
for all but incl-head inside include file. Overall this shouldn't do anything but move the magic comments around inside the HTML files. --- docs/block-repl.py | 42 ++++++++++++++++--- docs/{footer-incl.html => incl-footer.html} | 2 + docs/{head-incl.html => incl-head.html} | 0 ...{masthead-incl.html => incl-masthead.html} | 2 + docs/{topnav-incl.html => incl-topnav.html} | 2 + docs/index.html | 16 +++---- docs/sgtutorial/about-disasm.html | 20 ++++----- docs/sgtutorial/address-tables.html | 20 ++++----- docs/sgtutorial/advanced-topics.html | 20 ++++----- docs/sgtutorial/digging-deeper.html | 20 ++++----- docs/sgtutorial/editing-data.html | 20 ++++----- docs/sgtutorial/extension-scripts.html | 20 ++++----- docs/sgtutorial/generating-code.html | 20 ++++----- .../{sidenav-incl.html => incl-sidenav.html} | 2 + docs/sgtutorial/index.html | 20 ++++----- docs/sgtutorial/inline-data.html | 20 ++++----- docs/sgtutorial/labels-symbols.html | 20 ++++----- docs/sgtutorial/local-variables.html | 20 ++++----- docs/sgtutorial/moving-around.html | 20 ++++----- docs/sgtutorial/odds-ends.html | 20 ++++----- docs/sgtutorial/simple-edits.html | 20 ++++----- docs/sgtutorial/string-formatting.html | 20 ++++----- docs/sgtutorial/using-sourcegen.html | 20 ++++----- docs/sgtutorial/visualizations.html | 20 ++++----- 24 files changed, 223 insertions(+), 183 deletions(-) rename docs/{footer-incl.html => incl-footer.html} (92%) rename docs/{head-incl.html => incl-head.html} (100%) rename docs/{masthead-incl.html => incl-masthead.html} (86%) rename docs/{topnav-incl.html => incl-topnav.html} (96%) rename docs/sgtutorial/{sidenav-incl.html => incl-sidenav.html} (98%) diff --git a/docs/block-repl.py b/docs/block-repl.py index 48d8341..4d05be8 100755 --- a/docs/block-repl.py +++ b/docs/block-repl.py @@ -24,6 +24,8 @@ # # (Tested with Python v3.8.5) # +# Copyright 2021 Andy McFadden. +# import filecmp import os.path @@ -104,34 +106,64 @@ def editFile(inFileName, outFileName): def copyFromIncl(inFileName, tag, activeId, outFile): - """ Copy incl file, substituting active ID if appropriate. """ + """ + Copy include file in, substituting active ID and path variables when + appropriate. + inFileName: relative path to file we're working on + tag: name of file to include (absolute or relative to inFileName) + activeID: ID to mark as active + outFile: file object to write data to + """ + inFileDir = os.path.dirname(inFileName) if tag[0] == '/': # file is in top-level (current) directory inclFileName = tag[1:] else: # file is in same directory as input file - inclFileName = os.path.join(os.path.dirname(inFileName), tag) + inclFileName = os.path.join(inFileDir, tag) print("== replacing section with " + inclFileName) try: - with open(inclFileName, "r") as inFile: + # Use utf-8-sig to skip over Byte Order Marks (BOM). + with open(inclFileName, "r", encoding="utf-8-sig") as inFile: fileData = inFile.read() except IOError as err: raise LocalError(err) # Create a relative path for ${ROOT}, which is defined as the directory - # in which we're running. + # in which we're running. The path gets us from the input file's + # directory back to the root. # TODO: make this work correctly for absolute paths? if inFileName[0] == '/': raise LocalError("Not a relative path: " + inFileName) tmpPair = os.path.split(inFileName) rootRel = "" while tmpPair[0]: - rootRel += "../" + if tmpPair[0] != ".": + # ignore leading "./", which you get from find+xargs + rootRel += "../" tmpPair = os.path.split(tmpPair[0]) + # TODO: consider having a ${LOCAL} ... + # Create a relative path for ${LOCAL}, which is defined as the directory + # from which the input file was loaded. The path gets us from the input + # file's directory back to the included file's directory + # + # Suppose we're working on foo/bar/index.html, which includes + # ../incl-sidenav.html (i.e. foo/incl-sidenav.html). We want references + # to map ${LOCAL}/bar/glob.html to "glob.html", and + # ${LOCAL}/splat/index.html to "../splat/index.html". For now, we always + # use a local offset, so it's actually "../bar/glob.html". This is a step + # up from ${ROOT}, which would be "../../foo/bar/glob.html", but not as + # clever as we could be. + # + # What we really want to do is extract the string that follows ${ROOT} + # from the input file and compute the minimal path, but that requires + # more effort than a simple variable substitution. ${LOCAL} would be a + # half-step, and probably not worth the effort. + if activeId: # Given an HTML block like
  • , insert # a class assignment: class="active". The ID to modify is diff --git a/docs/footer-incl.html b/docs/incl-footer.html similarity index 92% rename from docs/footer-incl.html rename to docs/incl-footer.html index 150d015..afcb076 100644 --- a/docs/footer-incl.html +++ b/docs/incl-footer.html @@ -1,3 +1,4 @@ + diff --git a/docs/head-incl.html b/docs/incl-head.html similarity index 100% rename from docs/head-incl.html rename to docs/incl-head.html diff --git a/docs/masthead-incl.html b/docs/incl-masthead.html similarity index 86% rename from docs/masthead-incl.html rename to docs/incl-masthead.html index bd65054..9a6e069 100644 --- a/docs/masthead-incl.html +++ b/docs/incl-masthead.html @@ -1,4 +1,6 @@ +
    6502bench
    +
    diff --git a/docs/topnav-incl.html b/docs/incl-topnav.html similarity index 96% rename from docs/topnav-incl.html rename to docs/incl-topnav.html index c6650c6..d2fd99b 100644 --- a/docs/topnav-incl.html +++ b/docs/incl-topnav.html @@ -1,3 +1,4 @@ +
    diff --git a/docs/index.html b/docs/index.html index aa7a541..6fc5a92 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,7 +1,7 @@ - + @@ -10,7 +10,7 @@ integrity="sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK" crossorigin="anonymous"> - +