From 13e4c4ff6674e94819e7b22bac56e91645a9b389 Mon Sep 17 00:00:00 2001 From: Flancian <0@flancia.org> Date: Sat, 13 Mar 2021 17:20:11 +0100 Subject: [PATCH] Make /canonical-links happen --- app/agora.py | 183 +++++++++++++++++++------------------ app/templates/base.html | 4 +- app/templates/index.html | 4 +- app/templates/links.html | 10 +- app/templates/node.html | 8 +- app/templates/subnode.html | 10 +- 6 files changed, 112 insertions(+), 107 deletions(-) diff --git a/app/agora.py b/app/agora.py index 94c0f4c99..f89b12558 100644 --- a/app/agora.py +++ b/app/agora.py @@ -27,8 +27,101 @@ from . import util bp = Blueprint('agora', __name__) 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/') +@bp.route('/node//uprank/') +@bp.route('/node/') +@bp.route('/') +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/.json') +@bp.route('/node//uprank/.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/@') +@bp.route('/node/@/') +@bp.route('/@/') +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 -@bp.route('/index') @bp.route('/') def 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('.node', node=slugify(q))) -# Entities -@bp.route('/wikilink/') -@bp.route('/node/') -@bp.route('/node//uprank/') -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/.json') -@bp.route('/node//uprank/.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/@') -@bp.route('/node/@/') -@bp.route('/@/') -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/') def old_subnode(subnode): diff --git a/app/templates/base.html b/app/templates/base.html index e11674b72..9ca97b257 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -56,11 +56,11 @@ | 今 | - cli + cli | πŸŒ™ | - ❓ + ❓
diff --git a/app/templates/index.html b/app/templates/index.html index 7689db334..f6894cae5 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -32,10 +32,10 @@ This site is very much under construction, but feel free to look around:
  • {{search}} offers full text search over all subnodes (supports regexes).
  • -The [[wikilink]] is the heart of the Agora. /node/foo will render every subnode that resolves to wikilink [[foo]]. For example: [[Agora]]. +The [[wikilink]] is the heart of the Agora. /foo will render every subnode that resolves to wikilink [[foo]]. For example: [[Agora]].

    -For more information, please visit the Agora repository. If you're interested in knowing what's coming, please refer to Agora plan. +For more information, please visit the Agora repository. If you're interested in knowing what's coming, please refer to Agora plan. {% include "node_rendered.html" %} diff --git a/app/templates/links.html b/app/templates/links.html index 35c5c2085..3acb97847 100644 --- a/app/templates/links.html +++ b/app/templates/links.html @@ -21,7 +21,7 @@ ← back
    {% if backlinks %} {% for link in backlinks %} - {{link}}
    + {{link}}
    {% endfor %} {% else %} (none) @@ -33,7 +33,7 @@ ↑ pushing
    {% if pushing_nodes %} {% for node in pushing_nodes %} - {{node.uri}}
    + {{node.uri}}
    {% endfor %} {% else %} (none) @@ -45,7 +45,7 @@