From a92de4b93a03ee61d1bd659325a01816d54052c3 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Mon, 5 Jun 2017 23:28:33 -0400 Subject: [PATCH] Updated chain for Freezing Flask! --- README.md | 7 +++++++ run_site.py | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 131ce20..271df80 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,10 @@ source env/bin/activate export FLASK_APP=run_site.py export FLASK_DEBUG=1 flask run --host=0.0.0.0 +` + +## Building the static site +` +source env/bin/activate +python run_site.py +` diff --git a/run_site.py b/run_site.py index 525ae80..067aedf 100644 --- a/run_site.py +++ b/run_site.py @@ -5,8 +5,11 @@ import os app = Flask(__name__) freezer = Freezer(app) +app.config['FREEZER_RELATIVE_URLS'] = True +app.config['FREEZER_IGNORE_MIMETYPE_WARNINGS'] = True + @app.route('/') -@app.route('/index') +@app.route('/index.html') def index(): categories = os.listdir('projects/') projects = [] @@ -22,17 +25,32 @@ def show_projects(): categories=os.listdir('projects/') return render_template('project_category.html', categories=categories) -@app.route('/projects/') +@freezer.register_generator +def category_url_generator(): + for category in os.listdir(os.getcwd() + '/projects/'): + if os.path.isdir(os.getcwd() + '/projects/' + category): + yield 'show_project_category', {'category':category} + +@app.route('/projects/.html') def show_project_category(category): categories=os.listdir('projects/') projects = os.listdir('projects/' + category) - print projects + #print projects if category in categories: return render_template('project_category.html', category=category, projects=projects) else: return "Error, category not found!" -@app.route('/projects//') +@freezer.register_generator +def project_url_generator(): + for category in os.listdir(os.getcwd() + '/projects/'): + if os.path.isdir(os.getcwd() + '/projects/' + category): + for i in os.listdir(os.getcwd() + '/projects/' + category): + if os.path.isdir(os.getcwd() + '/projects/' + category + '/' + i): + #yield ('show_project', {'category': category, 'project_name': i}) + yield ('show_project', {'category':category, 'project_name':i}) + +@app.route('/projects//.html') def show_project(category, project_name): categories=os.listdir('projects') projects = os.listdir('projects/' + category) @@ -43,11 +61,24 @@ def show_project(category, project_name): else: return "Error, project not found!" +@freezer.register_generator +def photo_url_generator(): + projects_dir = os.getcwd() + '/projects/' + for category in os.listdir(projects_dir): + category_dir = projects_dir + category + if os.path.isdir(category_dir): + for i in os.listdir(category_dir): + project_dir = category_dir + '/' + i + if os.path.isdir(project_dir): + for photo in os.listdir(project_dir): + yield ('show_project_file', {'category':category, 'project_name':i, 'filename':photo}) + + @app.route('/projects///') def show_project_file(category, project_name, filename): return send_from_directory('projects/' + category + '/'+ project_name + '/', filename) -@app.route('/about') +@app.route('/about.html') def about(): return render_template('aboutus.html', title="About Us - JPs Contracting")