mirror of
https://github.com/flancian/garden.git
synced 2026-08-07 15:06:19 +00:00
Make /canonical-links happen
This commit is contained in:
+94
-89
@@ -27,8 +27,101 @@ from . import util
|
|||||||
bp = Blueprint('agora', __name__)
|
bp = Blueprint('agora', __name__)
|
||||||
G = db.G
|
G = db.G
|
||||||
|
|
||||||
|
# The [[agora]] is a [[distributed knowledge graph]].
|
||||||
|
# Nodes are the heart of the [[agora]].
|
||||||
|
# In the [[agora]] there are no 404s. Everything that can be described with words has a node in the [[agora]].
|
||||||
|
# The [[agora]] is a [[search engine]]: anagora.org/agora-search
|
||||||
|
#
|
||||||
|
# Flask routes work so that the one closest to the function is the canonical one.
|
||||||
|
@bp.route('/wikilink/<node>')
|
||||||
|
@bp.route('/node/<node>/uprank/<user_list>')
|
||||||
|
@bp.route('/node/<node>')
|
||||||
|
@bp.route('/<node>')
|
||||||
|
def node(node,user_list=[]):
|
||||||
|
current_app.logger.debug(f'[[{node}]]: Assembling node.')
|
||||||
|
if user_list:
|
||||||
|
rank = user_list.split(",")
|
||||||
|
else:
|
||||||
|
rank = ['agora', 'flancian']
|
||||||
|
n = G.node(node)
|
||||||
|
if n.subnodes:
|
||||||
|
# earlier in the list means more highly ranked.
|
||||||
|
n.subnodes = util.uprank(n.subnodes, users=rank)
|
||||||
|
permutations = []
|
||||||
|
# if it's a 404, include permutations.
|
||||||
|
else:
|
||||||
|
permutations = G.existing_permutations(node)
|
||||||
|
|
||||||
|
search_subnodes = db.search_subnodes(node)
|
||||||
|
|
||||||
|
current_app.logger.debug(f'[[{node}]]: Assembled node.')
|
||||||
|
return render_template(
|
||||||
|
# yuck
|
||||||
|
'content.html',
|
||||||
|
node=n,
|
||||||
|
backlinks=n.back_links(),
|
||||||
|
pull_nodes=n.pull_nodes() if n.subnodes else permutations,
|
||||||
|
forwardlinks=n.forward_links() if n else [],
|
||||||
|
search=search_subnodes,
|
||||||
|
pulling_nodes=n.pulling_nodes(),
|
||||||
|
pushing_nodes=n.pushing_nodes(),
|
||||||
|
q=n.wikilink.replace('-', '%20'),
|
||||||
|
qstr=n.wikilink.replace('-', ' '),
|
||||||
|
# disabled a bit superstitiously due to [[heisenbug]] after I added this everywhere :).
|
||||||
|
# sorry for the fuzzy thinking but I'm short on time and want to get things done.
|
||||||
|
# (...famous last words).
|
||||||
|
# annotations=n.annotations(),
|
||||||
|
)
|
||||||
|
|
||||||
|
@bp.route('/node/<node>.json')
|
||||||
|
@bp.route('/node/<node>/uprank/<user_list>.json')
|
||||||
|
def node_json(node,user_list=""):
|
||||||
|
default_rank = ['agora', 'flancian']
|
||||||
|
rank = user_list.split(",")
|
||||||
|
if len(rank) == 0:
|
||||||
|
rank = default_rank
|
||||||
|
n = G.node(node)
|
||||||
|
if n.subnodes:
|
||||||
|
# earlier in the list means more highly ranked.
|
||||||
|
print("rank", rank)
|
||||||
|
n.subnodes = util.uprank(n.subnodes, users=rank)
|
||||||
|
permutations = []
|
||||||
|
# if it's a 404, include permutations.
|
||||||
|
else:
|
||||||
|
permutations = G.existing_permutations(node)
|
||||||
|
|
||||||
|
search_subnodes = db.search_subnodes(node)
|
||||||
|
|
||||||
|
return jsons.dump({"node": n, "back_links": n.back_links(), "pull_nodes": n.pull_nodes()})
|
||||||
|
# return render_template(
|
||||||
|
# 'node_rendered.html',
|
||||||
|
# node=n,
|
||||||
|
# backlinks=n.back_links(),
|
||||||
|
# pull_nodes=n.pull_nodes() if n.subnodes else permutations,
|
||||||
|
# forwardlinks=n.forward_links() if n else [],
|
||||||
|
# search=search_subnodes,
|
||||||
|
# pulling_nodes=n.pulling_nodes(),
|
||||||
|
# pushing_nodes=n.pushing_nodes(),
|
||||||
|
# query=n.wikilink.replace('-', '%20')
|
||||||
|
# )
|
||||||
|
|
||||||
|
@bp.route('/node/<node>@<user>')
|
||||||
|
@bp.route('/node/@<user>/<node>')
|
||||||
|
@bp.route('/@<user>/<node>')
|
||||||
|
def subnode(node, user):
|
||||||
|
|
||||||
|
n = G.node(node)
|
||||||
|
|
||||||
|
n.subnodes = util.filter(n.subnodes, user)
|
||||||
|
n.subnodes = util.uprank(n.subnodes, user)
|
||||||
|
search_subnodes = db.search_subnodes_by_user(node, user)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'subnode.html',
|
||||||
|
node=n,
|
||||||
|
)
|
||||||
|
|
||||||
# Special
|
# Special
|
||||||
@bp.route('/index')
|
|
||||||
@bp.route('/')
|
@bp.route('/')
|
||||||
def index():
|
def index():
|
||||||
return redirect(url_for('.node', node='index'))
|
return redirect(url_for('.node', node='index'))
|
||||||
@@ -156,94 +249,6 @@ def search():
|
|||||||
return redirect(url_for('.go', node=slugify(" ".join(tokens[1:]))))
|
return redirect(url_for('.go', node=slugify(" ".join(tokens[1:]))))
|
||||||
return redirect(url_for('.node', node=slugify(q)))
|
return redirect(url_for('.node', node=slugify(q)))
|
||||||
|
|
||||||
# Entities
|
|
||||||
@bp.route('/wikilink/<node>')
|
|
||||||
@bp.route('/node/<node>')
|
|
||||||
@bp.route('/node/<node>/uprank/<user_list>')
|
|
||||||
def node(node,user_list=[]):
|
|
||||||
current_app.logger.debug(f'[[{node}]]: Assembling node.')
|
|
||||||
if user_list:
|
|
||||||
rank = user_list.split(",")
|
|
||||||
else:
|
|
||||||
rank = ['agora', 'flancian']
|
|
||||||
n = G.node(node)
|
|
||||||
if n.subnodes:
|
|
||||||
# earlier in the list means more highly ranked.
|
|
||||||
n.subnodes = util.uprank(n.subnodes, users=rank)
|
|
||||||
permutations = []
|
|
||||||
# if it's a 404, include permutations.
|
|
||||||
else:
|
|
||||||
permutations = G.existing_permutations(node)
|
|
||||||
|
|
||||||
search_subnodes = db.search_subnodes(node)
|
|
||||||
|
|
||||||
current_app.logger.debug(f'[[{node}]]: Assembled node.')
|
|
||||||
return render_template(
|
|
||||||
# yuck
|
|
||||||
'content.html',
|
|
||||||
node=n,
|
|
||||||
backlinks=n.back_links(),
|
|
||||||
pull_nodes=n.pull_nodes() if n.subnodes else permutations,
|
|
||||||
forwardlinks=n.forward_links() if n else [],
|
|
||||||
search=search_subnodes,
|
|
||||||
pulling_nodes=n.pulling_nodes(),
|
|
||||||
pushing_nodes=n.pushing_nodes(),
|
|
||||||
q=n.wikilink.replace('-', '%20'),
|
|
||||||
qstr=n.wikilink.replace('-', ' '),
|
|
||||||
# disabled a bit superstitiously due to [[heisenbug]] after I added this everywhere :).
|
|
||||||
# sorry for the fuzzy thinking but I'm short on time and want to get things done.
|
|
||||||
# (...famous last words).
|
|
||||||
# annotations=n.annotations(),
|
|
||||||
)
|
|
||||||
|
|
||||||
@bp.route('/node/<node>.json')
|
|
||||||
@bp.route('/node/<node>/uprank/<user_list>.json')
|
|
||||||
def node_json(node,user_list=""):
|
|
||||||
default_rank = ['agora', 'flancian']
|
|
||||||
rank = user_list.split(",")
|
|
||||||
if len(rank) == 0:
|
|
||||||
rank = default_rank
|
|
||||||
n = G.node(node)
|
|
||||||
if n.subnodes:
|
|
||||||
# earlier in the list means more highly ranked.
|
|
||||||
print("rank", rank)
|
|
||||||
n.subnodes = util.uprank(n.subnodes, users=rank)
|
|
||||||
permutations = []
|
|
||||||
# if it's a 404, include permutations.
|
|
||||||
else:
|
|
||||||
permutations = G.existing_permutations(node)
|
|
||||||
|
|
||||||
search_subnodes = db.search_subnodes(node)
|
|
||||||
|
|
||||||
return jsons.dump({"node": n, "back_links": n.back_links(), "pull_nodes": n.pull_nodes()})
|
|
||||||
# return render_template(
|
|
||||||
# 'node_rendered.html',
|
|
||||||
# node=n,
|
|
||||||
# backlinks=n.back_links(),
|
|
||||||
# pull_nodes=n.pull_nodes() if n.subnodes else permutations,
|
|
||||||
# forwardlinks=n.forward_links() if n else [],
|
|
||||||
# search=search_subnodes,
|
|
||||||
# pulling_nodes=n.pulling_nodes(),
|
|
||||||
# pushing_nodes=n.pushing_nodes(),
|
|
||||||
# query=n.wikilink.replace('-', '%20')
|
|
||||||
# )
|
|
||||||
|
|
||||||
@bp.route('/node/<node>@<user>')
|
|
||||||
@bp.route('/node/@<user>/<node>')
|
|
||||||
@bp.route('/@<user>/<node>')
|
|
||||||
def subnode(node, user):
|
|
||||||
|
|
||||||
n = G.node(node)
|
|
||||||
|
|
||||||
n.subnodes = util.filter(n.subnodes, user)
|
|
||||||
n.subnodes = util.uprank(n.subnodes, user)
|
|
||||||
search_subnodes = db.search_subnodes_by_user(node, user)
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'subnode.html',
|
|
||||||
node=n,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/subnode/<path:subnode>')
|
@bp.route('/subnode/<path:subnode>')
|
||||||
def old_subnode(subnode):
|
def old_subnode(subnode):
|
||||||
|
|||||||
@@ -56,11 +56,11 @@
|
|||||||
|
|
|
|
||||||
<a href="/today">今</a>
|
<a href="/today">今</a>
|
||||||
|
|
|
|
||||||
<a href="/node/agora-cli">cli</a>
|
<a href="/agora-cli">cli</a>
|
||||||
|
|
|
|
||||||
<a href="#" style="text-decoration: none;" class="theme-toggle">🌙</a>
|
<a href="#" style="text-decoration: none;" class="theme-toggle">🌙</a>
|
||||||
|
|
|
|
||||||
<a href="/node/agora-help" style="text-decoration: none;" class="help-button">❓</a>
|
<a href="/agora-help" style="text-decoration: none;" class="help-button">❓</a>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ This site is very much under construction, but feel free to look around:
|
|||||||
<li><a href="{{search_url}}">{{search}}</a> offers full text search over all subnodes (supports regexes).</li>
|
<li><a href="{{search_url}}">{{search}}</a> offers full text search over all subnodes (supports regexes).</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
The <a href="/node/wikilink">[[wikilink]]</a> is the heart of the Agora. <a href="/node/foo">/node/foo</a> will render every subnode that resolves to wikilink <a href="/node/foo">[[foo]]</a>. For example: <a href="/node/agora">[[Agora]]</a>.
|
The <a href="/wikilink">[[wikilink]]</a> is the heart of the Agora. <a href="/foo">/foo</a> will render every subnode that resolves to wikilink <a href="/foo">[[foo]]</a>. For example: <a href="/agora">[[Agora]]</a>.
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
For more information, please visit the <a href="https://flancia.org/go/agora">Agora repository.</a> If you're interested in knowing what's coming, please refer to <a href="https://anagora.org/node/agora-plan">Agora plan</a>.
|
For more information, please visit the <a href="https://flancia.org/go/agora">Agora repository.</a> If you're interested in knowing what's coming, please refer to <a href="https://anagora.org/agora-plan">Agora plan</a>.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include "node_rendered.html" %}
|
{% include "node_rendered.html" %}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<span class="backlinks-header">← back</span><br />
|
<span class="backlinks-header">← back</span><br />
|
||||||
{% if backlinks %}
|
{% if backlinks %}
|
||||||
{% for link in backlinks %}
|
{% for link in backlinks %}
|
||||||
<a href="/node/{{link}}">{{link}}</a><br />
|
<a href="/{{link}}">{{link}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
(none)
|
(none)
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<span class="pushlinks-header">↑ pushing</span><br />
|
<span class="pushlinks-header">↑ pushing</span><br />
|
||||||
{% if pushing_nodes %}
|
{% if pushing_nodes %}
|
||||||
{% for node in pushing_nodes %}
|
{% for node in pushing_nodes %}
|
||||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
<a href="/{{node.uri}}">{{node.uri}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
(none)
|
(none)
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<div class="pulllinks">
|
<div class="pulllinks">
|
||||||
<span class="pulllinks-header"> ↑pushing</span><br />
|
<span class="pulllinks-header"> ↑pushing</span><br />
|
||||||
{% for node in pull_nodes %}
|
{% for node in pull_nodes %}
|
||||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
<a href="/{{node.uri}}">{{node.uri}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br />
|
<br />
|
||||||
-->
|
-->
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<span class="pulllinks-header">↓ pulling</span><br />
|
<span class="pulllinks-header">↓ pulling</span><br />
|
||||||
{% if pulling_nodes %}
|
{% if pulling_nodes %}
|
||||||
{% for node in pulling_nodes %}
|
{% for node in pulling_nodes %}
|
||||||
<a href="/node/{{node.uri}}">{{node.uri}}</a><br />
|
<a href="/{{node.uri}}">{{node.uri}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
(none)
|
(none)
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
<span class="forwardlinks-header">→ forward</span><br />
|
<span class="forwardlinks-header">→ forward</span><br />
|
||||||
{% if forwardlinks %}
|
{% if forwardlinks %}
|
||||||
{% for link in forwardlinks %}
|
{% for link in forwardlinks %}
|
||||||
<a href="/node/{{link}}">{{link}}</a><br />
|
<a href="/{{link}}">{{link}}</a><br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
(none)
|
(none)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
If you <a href="https://flancia.org/go/agora">contributed content</a> related to '{{qstr}}' to the agora , it would show up here :)
|
If you <a href="https://flancia.org/go/agora">contributed content</a> related to '{{qstr}}' to the agora , it would show up here :)
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
For example a note named <code>{{node}}.md</code> or an image named <code>{{node}}.jpg</code>. <a href="/node/sign-up"
|
For example a note named <code>{{node}}.md</code> or an image named <code>{{node}}.jpg</code>. <a href="/sign-up"
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>Sign up now</strong></a> and start participating!
|
<strong>Sign up now</strong></a> and start participating!
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
{% if node.subnodes %}
|
{% if node.subnodes %}
|
||||||
<div class="node">
|
<div class="node">
|
||||||
<span class="node-header">→ node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a></span>
|
<span class="node-header">→ node <a href="/{{node.uri}}">[[{{node.uri}}]]</a></span>
|
||||||
|
|
||||||
{% for subnode in node.subnodes %}
|
{% for subnode in node.subnodes %}
|
||||||
<div class="subnode">
|
<div class="subnode">
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
<div class="pushed-subnode">
|
<div class="pushed-subnode">
|
||||||
<div class="subnode-header">
|
<div class="subnode-header">
|
||||||
<span class="subnode-id">↳ subnode <a href="/@{{subnode.user}}/{{node.uri}}">[[@{{subnode.user}}/{{node.uri}}]]</a></span><br />
|
<span class="subnode-id">↳ subnode <a href="/@{{subnode.user}}/{{node.uri}}">[[@{{subnode.user}}/{{node.uri}}]]</a></span><br />
|
||||||
<span class="subnode-links">pushed from <a href="/subnode/{{subnode.uri}}">{{subnode.uri}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a></span>
|
<span class="subnode-links">pushed from <a href="/sub{{subnode.uri}}">{{subnode.uri}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a></span>
|
||||||
</div>
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
{{ subnode.render()|linkify|safe }}
|
{{ subnode.render()|linkify|safe }}
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
{% for node in pull_nodes %}
|
{% for node in pull_nodes %}
|
||||||
<div class="node">
|
<div class="node">
|
||||||
<span class="node-header">⥅ pulled node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a></span>
|
<span class="node-header">⥅ pulled node <a href="/{{node.uri}}">[[{{node.uri}}]]</a></span>
|
||||||
|
|
||||||
{% if node.subnodes %}
|
{% if node.subnodes %}
|
||||||
{% for subnode in node.subnodes %}
|
{% for subnode in node.subnodes %}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<div class="not-found">
|
<div class="not-found">
|
||||||
No subnodes matching your query.
|
No subnodes matching your query.
|
||||||
<br /><br />
|
<br /><br />
|
||||||
Try going up to node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a> or perhaps <a href="/search">search</a>.
|
Try going up to node <a href="/{{node.uri}}">[[{{node.uri}}]]</a> or perhaps <a href="/search">search</a>.
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -32,7 +32,7 @@ Try going up to node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a> or perhap
|
|||||||
{% for subnode in node.subnodes %}
|
{% for subnode in node.subnodes %}
|
||||||
<div class="subnode">
|
<div class="subnode">
|
||||||
<div class="subnode-header">
|
<div class="subnode-header">
|
||||||
<span>Subnode <a href="/@{{subnode.user}}/{{node.uri}}">[[@{{subnode.user}}/{{node.uri}}]]</a></span> in node <a href="/node/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a></span><br />
|
<span>Subnode <a href="/@{{subnode.user}}/{{node.uri}}">[[@{{subnode.user}}/{{node.uri}}]]</a></span> in node <a href="/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a></span><br />
|
||||||
<span class="subnode-links">from <a href="/raw/{{subnode.uri}}">{{subnode.uri}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a></span>
|
<span class="subnode-links">from <a href="/raw/{{subnode.uri}}">{{subnode.uri}}</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a></span>
|
||||||
</div>
|
</div>
|
||||||
{{ subnode.render()|linkify|safe }}
|
{{ subnode.render()|linkify|safe }}
|
||||||
@@ -42,7 +42,7 @@ Try going up to node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a> or perhap
|
|||||||
|
|
||||||
<div class="links">
|
<div class="links">
|
||||||
<div class="backlinks">
|
<div class="backlinks">
|
||||||
<span class="backlinks-header">To see links, go up to node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a>.</span>
|
<span class="backlinks-header">To see links, go up to node <a href="/{{node.uri}}">[[{{node.uri}}]]</a>.</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -51,12 +51,12 @@ Try going up to node <a href="/node/{{node.uri}}">[[{{node.uri}}]]</a> or perhap
|
|||||||
<!-- old_subnode uses this -->
|
<!-- old_subnode uses this -->
|
||||||
{% if subnode %}
|
{% if subnode %}
|
||||||
<div class="subnode">
|
<div class="subnode">
|
||||||
<span class="subnode-header">Subnode <a href="/{{subnode.uri}}">[[{{subnode.uri}}]]</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a> in node <a href="/node/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a></span>
|
<span class="subnode-header">Subnode <a href="/{{subnode.uri}}">[[{{subnode.uri}}]]</a> by <a href="/@{{subnode.user}}">@{{subnode.user}}</a> in node <a href="/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a></span>
|
||||||
{{ subnode.render()|linkify|safe }}
|
{{ subnode.render()|linkify|safe }}
|
||||||
</div>
|
</div>
|
||||||
<div class="links">
|
<div class="links">
|
||||||
<div class="backlinks">
|
<div class="backlinks">
|
||||||
<span class="backlinks-header">To see links, go up to node <a href="/node/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a>.</span>
|
<span class="backlinks-header">To see links, go up to node <a href="/{{subnode.wikilink}}">[[{{subnode.wikilink}}]]</a>.</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user