You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB
Python

2 years ago
from . import db
import bottle
from urllib.parse import unquote, quote
import os
import pathlib
static_dir = os.path.join(os.path.expanduser('~'), 'lazy_wiki')
bottle.TEMPLATE_PATH = [os.path.join(os.path.dirname(__file__), 'views')]
app = bottle.Bottle()
# Serve CSS
@app.get('/static/css/<filename:path>')
def serve_css(filename):
return bottle.static_file(filename, root=pathlib.Path(__file__).parent / 'static/css')
@app.get('/favicon.ico', method='GET')
def get_favicon():
return bottle.static_file('favicon.ico', root=pathlib.Path(__file__).parent / 'static/img')
# Error Page
@app.error(404)
def error404(error):
return "unfortunately, a 404 error. the page you're searching for doesn't exist. (or is it just in hiding?) try another page! <a href=https://www.blessfrey.me/>-return to blessfrey-</a> • <a href=https://wiki.blessfrey.me/view/Main_Page> "
@app.error(500)
def error500(error):
return "unfortunately, a 500 error. something is wrong with the page you're trying to find, if it exists at all. try another page! <a href=https://www.blessfrey.me/>-return to blessfrey-</a> • <a href=https://wiki.blessfrey.me/view/Main_Page>"
@app.error(502)
def error502(error):
return "unfortunately, a 502 error. this was likely due to website maintenance. usually it'll be back up before you finish reading this, but otherwise, I'll notice something's wrong soon! <a href=https://www.blessfrey.me/>-return to blessfrey-</a> • <a href=https://wiki.blessfrey.me/view/Main_Page></a>"
@app.get('/')
def home():
return get_article(Main_Page)
@app.get('/Home')
def home1():
return get_article(Main_Page)
@app.get('/Index')
def home2():
return get_article(Main_Page)
@app.get('/Main')
def home3():
return get_article(Main_Page)
@app.get('/Main_Page')
def home4():
return get_article(Main_Page)
@app.get('/view/<keyword>')
def get_article(keyword):
'''
Get an article.
'''
article = db.select_formatted_article(unquote(keyword))
return bottle.template('view', article = article)