Improve display of children list
This commit is contained in:
parent
0196f3f86a
commit
60a60ace18
@ -31,15 +31,29 @@ if os.path.exists('index.pickle'):
|
||||
print('Error loading index.pickle')
|
||||
import traceback; traceback.print_exc()
|
||||
|
||||
def get_children(path):
|
||||
def child_name(c):
|
||||
return os.path.splitext(c)[0]
|
||||
|
||||
children = []
|
||||
if os.path.isdir(flask.safe_join('./data/pages', path)):
|
||||
for child in os.listdir(flask.safe_join('./data/pages', path)):
|
||||
child_path = flask.safe_join('./data/pages', path, child)
|
||||
|
||||
if child.startswith('_'):
|
||||
continue
|
||||
|
||||
if os.path.islink(child_path):
|
||||
children.append((child_name(child), child_name(os.path.split(os.path.realpath(child_path))[1])))
|
||||
else:
|
||||
children.append((child_name(child), None))
|
||||
children.sort(key=lambda x: x[0][1:] if x[0].startswith('(') else x[0])
|
||||
|
||||
return children
|
||||
|
||||
@app.route('/')
|
||||
def index_page():
|
||||
children = []
|
||||
for child in os.listdir('./data/pages'):
|
||||
if child.endswith('.md'):
|
||||
children.append(child[:-3])
|
||||
else:
|
||||
children.append(child)
|
||||
children.sort()
|
||||
children = get_children('')
|
||||
|
||||
if not os.path.exists('./data/pages/Home.md'):
|
||||
return flask.render_template('page_404.html', page={
|
||||
@ -67,16 +81,11 @@ def index_page():
|
||||
def page_view(path):
|
||||
fname = flask.safe_join('./data/pages', path) + '.md'
|
||||
|
||||
children = []
|
||||
if os.path.isdir(flask.safe_join('./data/pages', path)):
|
||||
for child in os.listdir(flask.safe_join('./data/pages', path)):
|
||||
if child.startswith('_'):
|
||||
continue
|
||||
if child.endswith('.md'):
|
||||
children.append(child[:-3])
|
||||
else:
|
||||
children.append(child)
|
||||
children.sort()
|
||||
if os.path.islink(fname):
|
||||
redir_page = '/'.join(path.split('/')[:-1]) + '/' + os.path.splitext(os.readlink(fname))[0]
|
||||
return flask.redirect(flask.url_for('page_view', path=redir_page))
|
||||
|
||||
children = get_children(path)
|
||||
|
||||
if not os.path.exists(fname):
|
||||
return flask.render_template('page_404.html', page={
|
||||
|
@ -27,8 +27,12 @@
|
||||
<h2>Children</h2>
|
||||
|
||||
<ul>
|
||||
{% for child in page.children %}
|
||||
<li><a href="{{ url_for('page_view', path=page.path + '/' + child) }}">{{ child }}</a></li>
|
||||
{% for child, link in page.children %}
|
||||
{% if link %}
|
||||
<li><a href="{{ url_for('page_view', path=page.path + '/' + child) }}">{{ child }} <i>(→ {{ link }})</i></a></li>
|
||||
{% else %}
|
||||
<li><a href="{{ url_for('page_view', path=page.path + '/' + child) }}">{{ child }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user