diff --git a/app/agora.py b/app/agora.py index 23646e3..9b0d7fa 100644 --- a/app/agora.py +++ b/app/agora.py @@ -145,8 +145,13 @@ def jump(): def node(node): n = G.node(node) - # earlier in the list means more highly ranked. - n.subnodes = util.uprank(n.subnodes, users=['agora', 'flancian']) + if n.subnodes: + # earlier in the list means more highly ranked. + n.subnodes = util.uprank(n.subnodes, users=['agora', 'flancian']) + permutations = [] + # if it's a 404, include permutations. + else: + permutations = G.existing_permutations(node) search_subnodes = db.search_subnodes(node) @@ -154,7 +159,7 @@ def node(node): 'node_rendered.html', node=n, backlinks=n.back_links(), - pull_nodes=n.pull_nodes() if n else [], + 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(), diff --git a/app/db.py b/app/db.py index ef6eac2..b121753 100644 --- a/app/db.py +++ b/app/db.py @@ -14,6 +14,7 @@ import cachetools.func import glob +import itertools import re import os from . import config @@ -64,6 +65,15 @@ class Graph: # Return an empty. return Node(uri) + def existing_permutations(self, uri): + # looks up nodes matching a permutation of the tokenized uri. + # + # example use: if [[server-agora]] does not exist, serve [[agora-server]] + permutations = itertools.permutations(uri.split('-')) + permutations = ['-'.join(permutation) for permutation in permutations] + nodes = [node for node in G.nodes() if node.wikilink in permutations and node.subnodes] + return nodes + @cachetools.func.ttl_cache(maxsize=2, ttl=20) def nodes(self, include_journals=True): # returns a list of all nodes diff --git a/app/templates/node_rendered.html b/app/templates/node_rendered.html index 96eed69..999f6ce 100644 --- a/app/templates/node_rendered.html +++ b/app/templates/node_rendered.html @@ -23,7 +23,8 @@ No node found at [[{{node.uri}}]].

If you contributed a subnode that mapped to '{{node.uri}}' in the Agora, this node would exist :)

-Try listing all nodes or perhaps search. +Try listing all nodes.

+Any existing permutations are automatically pulled below.
{% endif %}