Skip to content

Commit

Permalink
Update server so permanent links aren't broken when ran locally (#69)
Browse files Browse the repository at this point in the history
When rendered to an output the site generator provides redirects and directories for the scopes. The flask server version did NOT support this and cause all permalinks to be broken when running locally in a flask server.  This should remedy this and provide 404s instead of key errors in the flask app when a page doesn't exist.
  • Loading branch information
monkey-jeff authored Oct 12, 2022
1 parent 667f0d9 commit 101ce4c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions aip_site/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ def search():

@app.route('/<page>')
@app.route('/<collection>/<page>')
def page(page: str, collection: str = 'general'):
def page(page: str, collection: str = "general"):
"""Display a static page or listing of AIPs in a given scope."""
site = flask.g.site
if page in site.scopes:
return site.scopes[page].render()
return site.collections[collection].pages[page].render()
if (
collection in site.collections and
page in site.collections[collection].pages
):
return site.collections[collection].pages[page].render()
if collection in site.scopes and int(page) in site.scopes[collection].aips:
return site.scopes[collection].aips[int(page)].render()
flask.abort(404)


@app.route('/assets/css/<path:css_file>')
Expand Down

0 comments on commit 101ce4c

Please sign in to comment.