Plugin update - more comments and more contexton exceptions
diff --git a/theme/plugins/asfdata.py b/theme/plugins/asfdata.py
index 8d14ee5..1c4087f 100644
--- a/theme/plugins/asfdata.py
+++ b/theme/plugins/asfdata.py
@@ -293,7 +293,7 @@
metadata[seq] = reference
-def process_load(metadata, value, _key, load, debug):
+def process_load(metadata, value, load, debug):
for seq in value:
if seq not in ('url', 'file'):
# sequence
@@ -434,27 +434,28 @@
print(f"Processing {asf_data['data']}")
config_data = read_config(asf_data['data'])
for key in config_data:
+ # first check for data that is a singleton with special handling
if key == 'eccn':
# process eccn data
fname = config_data[key]['file']
- v = process_eccn(fname)
+ metadata[key] = v = process_eccn(fname)
print('ECCN V:', v)
- metadata[key] = v
continue
if key == 'twitter':
- # process twitter data
+ # process twitter data (if we decide to have multiple twitter feeds available then move next to blog'
handle = config_data[key]['handle']
count = config_data[key]['count']
- v = process_twitter(handle, count)
+ metadata[key] = v = process_twitter(handle, count)
print('TWITTER V:', v)
- metadata[key] = v
continue
value = config_data[key]
if isinstance(value, dict):
+ # dictionaries are complex data sources
print(f"{key} is a dict")
print(value)
+ # special cases that are multiple are processed first
if 'blog' in value:
# process blog feed
feed = config_data[key]['blog']
@@ -465,16 +466,20 @@
continue
elif 'url' in value:
+ # process a url based data source
load = url_data(value['url'])
- process_load(metadata, value, key, load, asf_data['debug'])
+ process_load(metadata, value, load, asf_data['debug'])
elif 'file' in value:
+ # process a file from within the site tree
load = file_data(value['file'])
- process_load(metadata, value, key, load, asf_data['debug'])
+ process_load(metadata, value, load, asf_data['debug'])
else:
+ # should probably be an error.
metadata[key] = value
else:
+ # simple metadata values
print(f"{key} = {value}")
metadata[key] = value
diff --git a/theme/plugins/asfgenid.py b/theme/plugins/asfgenid.py
index 6b6a385..bf951e8 100644
--- a/theme/plugins/asfgenid.py
+++ b/theme/plugins/asfgenid.py
@@ -157,7 +157,7 @@
mod_element.append(new_tag)
-# fixup cmark content
+# fixup cmark content - note that this may be too hungry. It may need to occur later and skipped in codeblock and pre tags.
def fixup_content(content):
text = content._content
modified = False
@@ -183,6 +183,7 @@
format_string = '{{{0}}}'.format(this_data)
parts = this_data.split('.')
try:
+ # should refactor this to be more general
if isinstance(metadata[parts[0]], dict):
ref = metadata
for part in parts:
@@ -214,8 +215,10 @@
if tagnav.name not in ['[document]', 'code', 'pre']:
m = ELEMENTID_RE.search(tag.string)
if m:
+ # this replacement could be better it truncates and likely drops additional annotations
tag.string.replace_with(this_string[:m.start()])
if m.group('type') == '#':
+ # id attribute annotation
tagnav['id'] = unique(m.group('id'), ids)
if permalinks:
permalink(soup, tagnav)
@@ -223,6 +226,7 @@
if debug:
print(f"# insertion {tagnav}")
else:
+ # class attribute annotation (regex only recognizes the two types)
tagnav['class'] = m.group('id')
if debug:
print(f"Class {tag.name} : {tagnav['class']}")
@@ -250,23 +254,30 @@
def generate_toc(content, tags, title, toc_headers):
settoc = False
tree = node = HtmlTreeNode(None, title, 'h0', '')
+ # find the last [TOC]
taglast = tags[0]
for tag in tags:
taglast = tag
+ # find all headings after the final [TOC]
heading_re = re.compile(toc_headers)
for header in taglast.findAllNext(heading_re):
+ # we have heading content for the ToC
settoc = True
+ # add the heading.
node, _new_header = node.add(header)
+ # convert the ToC to Beautiful Soup
tree_soup = ""
if settoc:
print(" ToC")
- # convert the HtmlTreeNode into Beautiful soup
+ # convert the HtmlTreeNode into Beautiful Soup
tree_string = '{}'.format(tree)
tree_soup = BeautifulSoup(tree_string, 'html.parser')
- # not sure if we need to put the ToC here.
+ # Make the ToC availble to the theme's template
content.toc = tree_soup.decode(formatter='html')
+ # replace the first [TOC] with the generated table of contents
for tag in tags:
tag.replaceWith(tree_soup)
+ # replace additional [TOC] with nothing
tree_soup = ""
@@ -375,6 +386,7 @@
try:
generate_id(pel_ob)
except:
+ print('FATAL: %s' % (pel_ob.relative_source_path), file=sys.stderr)
traceback.print_exc()
"if we have errors in this module then we want to quit to avoid erasing the site"
sys.exit(4)
diff --git a/theme/plugins/asfreader.py b/theme/plugins/asfreader.py
index 965368a..ed8e273 100644
--- a/theme/plugins/asfreader.py
+++ b/theme/plugins/asfreader.py
@@ -84,6 +84,7 @@
content = super().render(fp.getvalue().encode('utf-8')).decode('utf-8')
assert content
except:
+ print('ERROR: %s' % (source_path), file=sys.stderr)
traceback.print_exc()
raise