Blog WIP
This commit is contained in:
parent
4b685bb51c
commit
80634771ac
|
@ -5,6 +5,7 @@ import importlib
|
|||
|
||||
from flask import Flask
|
||||
from . import conf
|
||||
from .db import db
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = conf.DEBUG
|
||||
|
|
|
@ -1,14 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Blueprint, render_template, request
|
||||
from flask import Blueprint, render_template, request, abort
|
||||
from peewee import CharField, DateTimeField
|
||||
|
||||
from fmartingrcom.db import Model
|
||||
|
||||
|
||||
blog = Blueprint('blog', __name__,)
|
||||
blog = Blueprint('blog', __name__)
|
||||
|
||||
|
||||
# Models
|
||||
class Post(Model):
|
||||
HTML = 'html'
|
||||
MARKDOWN = 'md'
|
||||
TYPE_CHOICES = (
|
||||
(HTML, 'HTML'),
|
||||
(MARKDOWN, 'Markdown'),
|
||||
)
|
||||
|
||||
title = CharField()
|
||||
slug = CharField()
|
||||
date = DateTimeField()
|
||||
type = CharField(choices=TYPE_CHOICES, default=HTML)
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
filename = '{}-{}-{}-{}.{}'.format(self.date.year, self.date.month, self.date.day, self.slug, self.type)
|
||||
content = open('./content/blog/{}'.format(filename), 'r').read()
|
||||
|
||||
if self.type == self.MARKDOWN:
|
||||
import markdown2
|
||||
markdown = markdown2.Markdown()
|
||||
return markdown.convert(content)
|
||||
else:
|
||||
return content
|
||||
|
||||
|
||||
# Views
|
||||
@blog.route('/blog/<int:year>/<int:month>/<int:day>/<slug>/')
|
||||
def blog_post(year, month, day, slug):
|
||||
return render_template('blog/post.html', **locals())
|
||||
try:
|
||||
item = Post.get(Post.slug == slug)
|
||||
context = {
|
||||
'item': item,
|
||||
}
|
||||
return render_template('blog/post.html', **context)
|
||||
except Post.DoesNotExist:
|
||||
return abort(404)
|
||||
|
||||
@blog.route('/blog/')
|
||||
def blog_list():
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
body.blog {
|
||||
&.post {
|
||||
article {
|
||||
h1 {
|
||||
font-size: 1.8em;
|
||||
margin-bottom: 0.3em;
|
||||
}
|
||||
.info {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.content {
|
||||
margin-top: 1em;
|
||||
|
||||
&.md {
|
||||
img { margin: 0 auto; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ a {
|
|||
img { max-width: 100%; }
|
||||
|
||||
header {
|
||||
h1 { margin-bottom: 0; }
|
||||
h1 { margin-bottom: 0; font-size: 1.5em }
|
||||
h2 {
|
||||
font-size: 0.8em;
|
||||
font-weight: normal;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@import "./mixins";
|
||||
@import "./grid";
|
||||
@import "./layout";
|
||||
@import "./blog";
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
{% extends "blog/_base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
Blog post: {{ year }}, {{ month }}, {{ day }}, {{ slug }}
|
||||
<article class="center">
|
||||
<h1>{{ item.title }}</h1>
|
||||
<div class="info">
|
||||
Published on {{ item.date.strftime('%B %d, %Y') }}. // <a href="#">No comments.</a>
|
||||
</div>
|
||||
<div class="content {{ item.type }}">
|
||||
{{ item.content|safe }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block body_class %}blog post{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue