Add permutations; exploit open.

This commit is contained in:
Flancian 2021-01-24 21:04:50 +01:00
parent b5de675e8b
commit 4bc5703aa7
3 changed files with 20 additions and 4 deletions

View File

@ -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(),

View File

@ -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

View File

@ -23,7 +23,8 @@ No node found at [[{{node.uri}}]].
<br /><br />
If you <a href="https://flancia.org/go/agora">contributed a subnode</a> that mapped to '{{node.uri}}' in the Agora, this node would exist :)
<br /><br />
Try listing all <a href="/nodes">nodes</a> or perhaps <a href="/search">search</a>.
Try listing all <a href="/nodes">nodes</a>.<br/><br />
<strong>Any existing permutations</strong> are automatically pulled below.<br/>
</div>
{% endif %}