33 lines
825 B
Python
Executable File
33 lines
825 B
Python
Executable File
#!/usr/bin/env python
|
|
"""
|
|
Generates an index of the connections between items in the zettel.
|
|
"""
|
|
import os
|
|
import re
|
|
|
|
base = "/home/nico/vimwiki/zettel/"
|
|
|
|
edges = [] # an 'edge' is a tuple of a point and a destination.
|
|
|
|
link_regex = re.compile(r'\[\[(.*?)\]\]')
|
|
|
|
# search is a function that is called recursively to build the list of reachable files
|
|
def search(f):
|
|
if os.path.exists(f) and f.split(".")[1] == "md":
|
|
fp = open(f,"r")
|
|
r = fp.read()
|
|
links = link_regex.findall(r)
|
|
for l in links: # all files mentioned as links in this one
|
|
edge = (f, l) # tuple of (src, dest)
|
|
if not (edge in edges):
|
|
edges.append(edge)
|
|
search(os.path.join(base, l))
|
|
|
|
search(os.path.join(base,"index.md"))
|
|
|
|
with open(os.path.join(base,"index"),"w+") as i:
|
|
for e in edges:
|
|
i.write(f"{os.path.basename(e[0])} {e[1]}\n")
|
|
|
|
|