Some hacks to do push/pull, but enable only back/forward.

This commit is contained in:
Flancian 2020-12-22 01:08:47 +01:00
parent 38c35a8220
commit 13853488e3
4 changed files with 70 additions and 35 deletions

View file

@ -96,14 +96,26 @@ def pull(node):
@bp.route('/node/<node>') @bp.route('/node/<node>')
@bp.route('/wikilink/<node>') # alias for now @bp.route('/wikilink/<node>') # alias for now
def wikilink(node): def wikilink(node):
try:
n = db.nodes_by_wikilink(node)
except KeyError:
# We'll handle 404 in the template, as we want to show backlinks to non-existent nodes.
pass
try:
n = n[0]
except IndexError:
pass
return render_template( return render_template(
'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.subnodes_by_outlink(node),
# pushlinks=db.subnodes_by_pushlink(node), pushlinks=n.push_links() if n else [],
# pulllinks=db.subnodes_by_pulllink(node), pulllinks=n.pull_links() if n else [],
# forwardlinks=db.subnodes_by_outlink(node) forwardlinks=n.forward_links() if n else [],
) )
@bp.route('/subnode/<path:subnode>') @bp.route('/subnode/<path:subnode>')

View file

@ -70,11 +70,29 @@ class Node:
def go(self): def go(self):
# There's surely a much better way to do this. Alas :) # There's surely a much better way to do this. Alas :)
go = [] links = []
for subnode in self.subnodes: for subnode in self.subnodes:
go.extend(subnode.go()) links.extend(subnode.go())
return go return go
def forward_links(self):
links = []
for subnode in self.subnodes:
links.extend(subnode.outlinks)
return sorted(set(links))
def pull_links(self):
links = []
for subnode in self.subnodes:
links.extend(subnode.pull_links())
return sorted(set(links))
def push_links(self):
links = []
for subnode in self.subnodes:
links.extend(subnode.push_links())
return sorted(set(links))
class Subnode: class Subnode:
"""A subnode is a note or media resource volunteered by a user of the Agora. """A subnode is a note or media resource volunteered by a user of the Agora.
@ -129,7 +147,7 @@ class Subnode:
sanitized_golinks.append('https://' + golink) sanitized_golinks.append('https://' + golink)
return sanitized_golinks return sanitized_golinks
def pull(self): def pull_links(self):
""" """
returns a set of pull links contained in this subnode returns a set of pull links contained in this subnode
pull links are blocks of the form: pull links are blocks of the form:
@ -138,9 +156,24 @@ class Subnode:
# TODO: test. # TODO: test.
pull_links = subnode_to_actions(self, 'pull') pull_links = subnode_to_actions(self, 'pull')
entities = content_to_outlinks(pull_links) entities = content_to_outlinks("\n".join(pull_links))
return entities return entities
def push_links(self):
"""
returns a set of push links contained in this subnode
push links are blocks of the form:
- [[push]] [[node]]
TODO: refactor with the above.
"""
# TODO: test.
push_links = subnode_to_actions(self, 'push')
entities = content_to_outlinks("\n".join(push_links))
return entities
def subnode_to_actions(subnode, action): def subnode_to_actions(subnode, action):
# hack hack. # hack hack.

View file

@ -92,29 +92,25 @@ h2 { font-size: 1.2em; }
} }
.backlinks { .backlinks {
/*background: #1f1f2f; */
float: left; float: left;
width: 50%; width: 50%;
} }
.pushlinks { .pushlinks {
/*background: #1f1f2f; */
width: 20%; width: 20%;
background: #161616; background: #161616;
color: #cfcfcf; color: #cfcfcf;
padding: 0.5em;
margin-bottom: 10px;
border-radius: 10px;
} }
.pulllinks, .forwardlinks { .pulllinks {
/*background: #1f1f2f; */
background: #161616;
width: 20%; width: 20%;
background: #161616;
color: #cfcfcf; color: #cfcfcf;
padding: 0.5em; }
margin-bottom: 10px;
border-radius: 10px; .forwardlinks {
background: #161616;
width: 50%;
} }
.backlinks-header, .pushlinks-header, .pulllinks-header, .forwardlinks-header { .backlinks-header, .pushlinks-header, .pulllinks-header, .forwardlinks-header {

View file

@ -16,7 +16,6 @@
<span class="links-header">Links</span><br /> <span class="links-header">Links</span><br />
<div class="links"> <div class="links">
{% if backlinks %}
<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 subnode in backlinks %}
@ -24,35 +23,30 @@
{% endfor %} {% endfor %}
<br /> <br />
</div> </div>
{% endif %}
{% if pushlinks %} <!--
<div class="pushlinks"> <div class="pushlinks">
<span class="pushlinks-header">push</span><br /> <span class="pushlinks-header">push</span><br />
{% for subnode in pushlinks %} {% for link in pushlinks %}
<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>
{% endif %}
{% if pulllinks %}
<div class="pulllinks"> <div class="pulllinks">
<span class="pulllinks-header">pull</span><br /> <span class="pulllinks-header">pull</span><br />
{% for subnode in pulllinks %} {% for link in pulllinks %}
<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>
{% endif %} -->
{% if forwardlinks %}
<div class="forwardlinks"> <div class="forwardlinks">
<span class="forwardlinks-header">→ forward</span><br /> <span class="forwardlinks-header">→ forward</span><br />
{% for subnode in forwardlinks %} {% for link in forwardlinks %}
<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>
{% endif %}
</div> </div>