Make path handling less horrific.
This commit is contained in:
parent
61375d8ba7
commit
39453d8b07
3 changed files with 16 additions and 4 deletions
|
@ -16,8 +16,10 @@ import datetime
|
|||
from flask import Blueprint, url_for, render_template, current_app, Response, redirect
|
||||
from markupsafe import escape
|
||||
from . import db
|
||||
from . import config
|
||||
bp = Blueprint('agora', __name__)
|
||||
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return render_template('index.html', help=url_for('agora.help'), nodes=url_for('agora.nodes'), journals=url_for('agora.journals'))
|
||||
|
@ -30,6 +32,7 @@ def help():
|
|||
@bp.route('/notes') # alias for now
|
||||
@bp.route('/nodes')
|
||||
def nodes():
|
||||
current_app.logger.warning('Config: %s' % config.AGORA_PATH)
|
||||
return render_template('nodes.html', nodes=db.all_nodes())
|
||||
|
||||
@bp.route('/journals')
|
||||
|
@ -57,6 +60,12 @@ def garden(garden):
|
|||
def wikilink(node):
|
||||
return render_template('nodes_rendered.html', wikilink=node, nodes=db.nodes_by_wikilink(node), backlinks=db.nodes_by_outlink(node))
|
||||
|
||||
@bp.route('/asset/<user>/<asset>')
|
||||
def asset(user, asset):
|
||||
# An asset is a binary in someone's garden/<user>/assets directory.
|
||||
path = '/'.join(["garden", user, 'assets', asset])
|
||||
return current_app.send_static_file(path)
|
||||
|
||||
@bp.route('/raw/<node>')
|
||||
def raw(node):
|
||||
# hack hack
|
||||
|
|
3
app/config.py
Normal file
3
app/config.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
import os
|
||||
import getpass
|
||||
AGORA_PATH = os.path.join('/home', getpass.getuser(), 'agora')
|
|
@ -15,9 +15,9 @@
|
|||
import glob
|
||||
import re
|
||||
import os
|
||||
from . import config
|
||||
from operator import attrgetter
|
||||
|
||||
BASE = '../../agora/'
|
||||
RE_WIKILINKS = re.compile('\[\[(.*?)\]\]')
|
||||
|
||||
class Node:
|
||||
|
@ -30,7 +30,7 @@ class Node:
|
|||
self.outlinks = content_to_outlinks(self.content)
|
||||
|
||||
def path_to_url(path):
|
||||
return os.path.split(path)[0].replace(BASE, '')
|
||||
return path.replace(config.AGORA_PATH + '/', '')
|
||||
|
||||
def path_to_wikilink(path):
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
@ -44,12 +44,12 @@ def content_to_outlinks(content):
|
|||
return []
|
||||
|
||||
def all_nodes():
|
||||
l = sorted([f for f in glob.glob(BASE + '**/*.md', recursive=True)])
|
||||
l = sorted([f for f in glob.glob(os.path.join(config.AGORA_PATH, '**/*.md'), recursive=True)])
|
||||
return [Node(f) for f in l]
|
||||
|
||||
def all_journals():
|
||||
# hack hack.
|
||||
l = sorted([f for f in glob.glob(BASE + '**/????-??-??.md', recursive=True)])
|
||||
l = sorted([f for f in glob.glob(os.path.join(config.AGORA_PATH, '**/????-??-??.md'), recursive=True)])
|
||||
return sorted([Node(f) for f in l], key=attrgetter('wikilink'), reverse=True)
|
||||
|
||||
def nodes_by_wikilink(wikilink):
|
||||
|
|
Loading…
Reference in a new issue