Alex Niderberg | @AlexNiderbergTechnical Product Owner / Master Software Engineer @ Capital One Labs
mkdir sample_project && cd $_ virtualenv venv source venv/bin/activate pip install Flask Frozen-Flask Flask-FlatPages touch sitebuilder.py # add content python sitebuilder.py # visit localhost:8000 mkdir pages touch pages/hello-world.md # add page content mkdir templates touch templates/base.html # add content touch templates/page.html # add content touch templates/index.html # add content
git clone https://github.com/aln787/frozenFlask.git cd frozenFlask virtualenv venv source venv/bin/activate pip install -r requirements.txt subl .
subl sitebuilder.py #or more sitebuilder.py
import sys
from flask import Flask, render_template
from flask_flatpages import FlatPages
from flask_frozen import Freezer
DEBUG = True
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
app = Flask(__name__)
app.config.from_object(__name__)
pages = FlatPages(app)
freezer = Freezer(app)
@app.route("/")
def index():
return render_template('index.html', pages=pages)
@app.route('/<path:path>/')
def page(path):
page = pages.get_or_404(path)
return render_template('page.html', page=page)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "build":
freezer.freeze()
else:
app.run(port=8002)
python sitebuilder.py #(todo) determine why this is not locating flask on the plane # visit http://127.0.0.1:8002/
open build/index.html #if you have http-server installed cd build && http-server -p 8083 && cd .. # visit http://0.0.0.0:8083
vi templates/base.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><!-- **Add your html site title here --></title>
</head>
<body>
<h1><a href="{{ url_for("index") }}"><!-- **Add your html site title here --></a></h1>
{% block content %}
<p>Default content to be displayed</p>
{% endblock content %}
</body>
</html>
subl pages/frozen-flask.md subl pages/hello-world.md
title: Frozen Flask date: 2016-01-27 tags: [programming, static-sites] # Experimentation Using Frozen Flask Site creation following the [this blog post](https://nicolas.perriault.net/code/2012/dead-easy-yet-powerful-static-website-generator-with-flask/).
subl pages/frozen-flask.md
title: Frozen Flask date: 2016-01-27 tags: [programming, static-sites] # <replace with your content> - <and your content details>
python sitebuilder.py #(todo) determine why this is not locating flask on the plane # visit localhost:8002
python sitebuilder.py build open build/index.html #if you have http-server installed cd build && http-server -p 8083 && cd ..
- Time time to put your static site up on S3.
pwd # <your path>/frozenFlask cd build/ ls -lah #drwxr-xr-x 3 <user> <group> 102B Jan 27 01:23 frozen-flask #drwxr-xr-x 3 <user> <group> 102B Jan 27 01:23 hello-world #-rw-r--r-- 1 <user> <group> 428B Jan 27 01:23 index.html
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::frozen-flask-bucket2/*"
}
]
}
python --version #Looking for above 2.6.5+ or 3.3+ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" unzip awscli-bundle.zip ./awscli-bundle/install -b ~/bin/aws echo $PATH | grep ~/bin #See if $PATH contains ~/bin (output will be empty if it doesn't) export PATH=~/bin:$PATH #Add ~/bin to $PATH if necessary #Confirm the install worked correctly aws help
aws configure #AWS Access Key ID [None]: <Your Key> #AWS Secret Access Key [None]: <Your Secret> #Default region name [None]: us-east-1 #Default output format [None]: json
#aws s3 rb s3://frozen-flask-cli --force #Remove existing folder with this name aws s3 mb s3://frozen-flask-cli pwd #<your path>/frozenFlask aws s3 sync build/ s3://frozen-flask-cli --exclude '.DS_Store' aws s3api put-bucket-policy --bucket frozen-flask-cli --policy file://bucketPolicy.json aws s3api put-bucket-website --bucket frozen-flask-cli --website-configuration file://enableWebHosting.json #aws s3api put-bucket-website help