Clean up links section so that it only refers to nodes.
This commit is contained in:
parent
13853488e3
commit
2bb02f797e
3 changed files with 14 additions and 13 deletions
|
@ -112,7 +112,8 @@ def wikilink(node):
|
||||||
'node_rendered.html',
|
'node_rendered.html',
|
||||||
wikilink=node,
|
wikilink=node,
|
||||||
subnodes=db.subnodes_by_wikilink(node),
|
subnodes=db.subnodes_by_wikilink(node),
|
||||||
backlinks=db.subnodes_by_outlink(node),
|
# backlinks=db.nodes_by_outlink(node),
|
||||||
|
backlinks=[x.wikilink for x in db.nodes_by_outlink(node)],
|
||||||
pushlinks=n.push_links() if n else [],
|
pushlinks=n.push_links() if n else [],
|
||||||
pulllinks=n.pull_links() if n else [],
|
pulllinks=n.pull_links() if n else [],
|
||||||
forwardlinks=n.forward_links() if n else [],
|
forwardlinks=n.forward_links() if n else [],
|
||||||
|
|
20
app/db.py
20
app/db.py
|
@ -36,7 +36,7 @@ class Graph:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# [[wikilink]] -> Node
|
# [[wikilink]] -> Node
|
||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
# node -> [n0, ..., nn] such that node has outlinks to the target list.
|
# node -> [n0, ..., nn] such that node has forward_links to the target list.
|
||||||
self.edges = {}
|
self.edges = {}
|
||||||
def addsubnode(self, subnode):
|
def addsubnode(self, subnode):
|
||||||
if subnode.wikilink in self.nodes:
|
if subnode.wikilink in self.nodes:
|
||||||
|
@ -78,7 +78,7 @@ class Node:
|
||||||
def forward_links(self):
|
def forward_links(self):
|
||||||
links = []
|
links = []
|
||||||
for subnode in self.subnodes:
|
for subnode in self.subnodes:
|
||||||
links.extend(subnode.outlinks)
|
links.extend(subnode.forward_links)
|
||||||
return sorted(set(links))
|
return sorted(set(links))
|
||||||
|
|
||||||
def pull_links(self):
|
def pull_links(self):
|
||||||
|
@ -109,7 +109,7 @@ class Subnode:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
self.content = f.read()
|
self.content = f.read()
|
||||||
self.mtime = os.path.getmtime(path)
|
self.mtime = os.path.getmtime(path)
|
||||||
self.outlinks = content_to_outlinks(self.content)
|
self.forward_links = content_to_forward_links(self.content)
|
||||||
self.node = self.wikilink
|
self.node = self.wikilink
|
||||||
# Initiate node for wikilink if this is the first subnode, append otherwise.
|
# Initiate node for wikilink if this is the first subnode, append otherwise.
|
||||||
G.addsubnode(self)
|
G.addsubnode(self)
|
||||||
|
@ -156,7 +156,7 @@ class Subnode:
|
||||||
|
|
||||||
# TODO: test.
|
# TODO: test.
|
||||||
pull_links = subnode_to_actions(self, 'pull')
|
pull_links = subnode_to_actions(self, 'pull')
|
||||||
entities = content_to_outlinks("\n".join(pull_links))
|
entities = content_to_forward_links("\n".join(pull_links))
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
def push_links(self):
|
def push_links(self):
|
||||||
|
@ -170,7 +170,7 @@ class Subnode:
|
||||||
|
|
||||||
# TODO: test.
|
# TODO: test.
|
||||||
push_links = subnode_to_actions(self, 'push')
|
push_links = subnode_to_actions(self, 'push')
|
||||||
entities = content_to_outlinks("\n".join(push_links))
|
entities = content_to_forward_links("\n".join(push_links))
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ def path_to_user(path):
|
||||||
def path_to_wikilink(path):
|
def path_to_wikilink(path):
|
||||||
return os.path.splitext(os.path.basename(path))[0]
|
return os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|
||||||
def content_to_outlinks(content):
|
def content_to_forward_links(content):
|
||||||
# hack hack.
|
# hack hack.
|
||||||
match = RE_WIKILINKS.findall(content)
|
match = RE_WIKILINKS.findall(content)
|
||||||
if match:
|
if match:
|
||||||
|
@ -295,11 +295,11 @@ def subnode_by_uri(uri):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def nodes_by_outlink(wikilink):
|
def nodes_by_outlink(wikilink):
|
||||||
nodes = [node for node in all_nodes() if wikilink in node.outlinks]
|
nodes = [node for node in all_nodes() if wikilink in node.forward_links()]
|
||||||
return nodes
|
return sorted(nodes, key=attrgetter('wikilink'))
|
||||||
|
|
||||||
def subnodes_by_outlink(wikilink):
|
def subnodes_by_outlink(wikilink):
|
||||||
# This doesn't work. It matches too much/too little for some reason. Debug someday?
|
# This doesn't work. It matches too much/too little for some reason. Debug someday?
|
||||||
# subnodes = [subnode for subnode in all_subnodes() if [wikilink for wikilink in subnode.outlinks if fuzz.ratio(subnode.wikilink, wikilink) > FUZZ_FACTOR]]
|
# subnodes = [subnode for subnode in all_subnodes() if [wikilink for wikilink in subnode.forward_links if fuzz.ratio(subnode.wikilink, wikilink) > FUZZ_FACTOR]]
|
||||||
subnodes = [subnode for subnode in all_subnodes() if util.canonical_wikilink(wikilink) in subnode.outlinks]
|
subnodes = [subnode for subnode in all_subnodes() if util.canonical_wikilink(wikilink) in subnode.forward_links]
|
||||||
return subnodes
|
return subnodes
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
<div class="links">
|
<div class="links">
|
||||||
<div class="backlinks">
|
<div class="backlinks">
|
||||||
<span class="backlinks-header">← back</span><br />
|
<span class="backlinks-header">← back</span><br />
|
||||||
{% for subnode in backlinks %}
|
{% for link in backlinks %}
|
||||||
<a href="{{subnode.url}}">{{subnode.wikilink}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a><br />
|
<a href="/node/{{link}}">{{link}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue