-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f5a0e8
commit 018930d
Showing
17 changed files
with
121 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ dist/ | |
build/ | ||
*.egg-info/ | ||
node_modules/ | ||
tests/dist/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +0,0 @@ | ||
import os | ||
from flask import Flask, g, render_template, url_for | ||
from werkzeug.exceptions import HTTPException | ||
|
||
def create_app(test_config=None): | ||
app = Flask(__name__) | ||
if test_config is None: | ||
app.config.from_pyfile('config.py') | ||
else: | ||
app.config.from_mapping(test_config) | ||
|
||
try: | ||
os.makedirs(app.instance_path) | ||
except OSError: | ||
pass | ||
|
||
@app.before_request | ||
def load_version(): | ||
# pylint: disable=assigning-non-slot | ||
g.version = app.config['VERSION'] | ||
|
||
from . import blog | ||
app.register_blueprint(blog.bp) | ||
app.add_url_rule('/', endpoint='index') | ||
|
||
@app.errorhandler(Exception) | ||
def handle_exception(err): | ||
if isinstance(err, HTTPException): | ||
return err | ||
|
||
return render_template('500.html', err=err), 500 | ||
|
||
@app.errorhandler(404) | ||
def page_not_found(err): | ||
return render_template('404.html', err=err), 404 | ||
|
||
return app | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from os import environ | ||
|
||
SECRET_KEY = environ.get('SECRET_KEY', default='dev') | ||
ARTICLES_DIR = environ.get('ARTICLES_DIR', default='articles/') | ||
DIST_DIR = environ.get('DIST_DIR', default='dist/') | ||
VERSION = 'v0.22.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import shutil | ||
import sys | ||
from jinja2 import Environment, PackageLoader, select_autoescape | ||
from .articles import * | ||
from .config import * | ||
|
||
env = Environment( | ||
loader=PackageLoader('blog'), | ||
autoescape=select_autoescape() | ||
) | ||
|
||
def render_template(file, **kwargs): | ||
template = env.get_template(file) | ||
return template.render(**kwargs, version=VERSION) | ||
|
||
def generate(articles_dir=ARTICLES_DIR, dist_dir=DIST_DIR): | ||
|
||
# Create/clear dist folder | ||
if os.path.isdir(dist_dir): | ||
print('[INFO] Clearing existing output dir...') | ||
shutil.rmtree(dist_dir) | ||
print('[INFO] Creating output dir...') | ||
os.mkdir(dist_dir) | ||
|
||
# Get all articles and generate a page for each one | ||
print('[INFO] Loading articles...') | ||
items = get_all_articles(articles_dir) | ||
print('[INFO] Loaded {} articles...'.format(len(items))) | ||
for item in items: | ||
print('[INFO] Rendering and writing {}...'.format(item.get_name())) | ||
rendered = render_template('view.html', article=item) | ||
with open(dist_dir + item.get_name() + '.html', 'w') as output_file: | ||
output_file.write(rendered) | ||
|
||
# Generate sitemap | ||
print('[INFO] Rendering and writing sitemap...') | ||
rendered = render_template('sitemap.xml', articles=items) | ||
with open(dist_dir + 'sitemap.xml', 'w') as output_file: | ||
output_file.write(rendered) | ||
|
||
# Generate static pages (inc error pages) | ||
for static_page in ['404', '500', 'now']: | ||
print('[INFO] Rendering and writing {}...'.format(static_page)) | ||
rendered = render_template(static_page + '.html') | ||
with open(dist_dir + static_page + '.html', 'w') as output_file: | ||
output_file.write(rendered) | ||
|
||
# Generate home page and paginated elements | ||
pages = get_pages(articles_dir) | ||
print('[INFO] Found {} pages of articles...'.format(pages)) | ||
for p in range(1, pages + 1): | ||
print('[INFO] Rendering and writing index page {}...'.format(p)) | ||
paged_items = get_paginated_articles(articles_dir, p) | ||
rendered = render_template( | ||
'index.html', | ||
articles=paged_items, | ||
current_page=p, | ||
pages=[None] * pages | ||
) | ||
with open(dist_dir + 'index.html' if p == 1 else dist_dir + 'index-{}.html'.format(p), 'w') as output_file: | ||
output_file.write(rendered) | ||
|
||
# Copy static assets | ||
print('[INFO] Copying static assets...') | ||
shutil.copytree('blog/static', dist_dir + 'static') | ||
|
||
print('Blog {} generated and output to {}'.format(VERSION, dist_dir)) | ||
|
||
if __name__ == '__main__': | ||
sys.exit(generate()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
include_package_data=True, | ||
zip_safe=False, | ||
install_requires=[ | ||
'flask', | ||
'jinja2', | ||
'markdown', | ||
], | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.