Skip to content

Commit

Permalink
more refactor of link reference tags
Browse files Browse the repository at this point in the history
  • Loading branch information
yjmantilla committed Jun 14, 2024
1 parent b3e5590 commit 0ccca64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions gen-static-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
with open('gencfg.yml', 'r') as f:
CFG = yaml.load(f, Loader=yaml.FullLoader)


BEGIN=CFG['BEGIN']
END=CFG['END']
GRAPHS_URL_RULE=CFG['GRAPHS_URL_RULE']
SUBDIRS_URL_RULE=CFG['SUBDIRS_URL_RULE']
def has_front_matter(lines):
Expand Down Expand Up @@ -186,8 +187,8 @@ def generate_link_reference_definitions(mypath,graph,extension='.md',only_clean=
assert len(filenames)==len(set(filenames))
sources = []
targets = []
begin = '\n[//begin]: # "Autogenerated link references for markdown compatibility"\n' # the two linebreaks are really important for github pages to grab these as references
end = '\n[//end]: # "Autogenerated link references"'
begin = BEGIN
end = END
for (this_file,this_fullpath,this_subdir) in zip(filenames,onlyfiles,onlysubdirs):
print(this_file)
# Get references of this file (all links with this file as the source)
Expand All @@ -202,17 +203,27 @@ def generate_link_reference_definitions(mypath,graph,extension='.md',only_clean=
# Assume these tags appear only ONCE
a, b = data.find(begin), data.find(end)+len(end)
newdata = data[:a] #+ data[b:] # assume there is nothing after the end tag
# strip newlines at the beginning and end
newdata = newdata.rstrip()
newdata = newdata.lstrip()
newdata = newdata
elif begin in data and end not in data:
assert False, 'Begin tag found but not end tag'
elif begin not in data and end in data:
assert False, 'End tag found but not begin tag'
else:
newdata = data
newdata = data.lstrip().rstrip()+'\n'
refs = []
for l in current_links:
tg=l['target']
url = [x for x in graph['nodes'] if x['id']==tg][0]['url']
refs.append(f'[{tg}]: {url} "{tg}"')
newtext = '\n'.join(refs)
newtext = begin+newtext+end
newtext = '\n\n'+begin+'\n'+newtext+'\n'+end+'\n'
if not only_clean:
newdata = newdata+newtext
else:
newdata = newdata+'\n'
# Make references
#print(data)
#title = data[0].replace('# ','').replace('\n','')
Expand Down
2 changes: 2 additions & 0 deletions gencfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SUBDIRS_URL_RULE:
- './../'

out_extension : ''
BEGIN : '[//begin]: # "Autogenerated link references for markdown compatibility"' # the two linebreaks are really important for github pages to grab these as references
END : '[//end]: # "Autogenerated link references"'

ignore_in : ['_site','_includes','.github','.vscode','docs','packages','README','poems']
ignore_eq : ['.','README','bubbles']
Expand Down

0 comments on commit 0ccca64

Please sign in to comment.