mirror of
https://github.com/tiyn/beaker-blog.git
synced 2025-10-10 09:51:17 +02:00
adding dockerfile
This commit is contained in:
39
src/app.py
Normal file
39
src/app.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from flask import Flask, flash, make_response, render_template, request, redirect
|
||||
|
||||
import content as con_gen
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('error.html', title='Error 404', errorcode='404'), 404
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/index.html')
|
||||
def index():
|
||||
content = con_gen.gen_index_string()
|
||||
return render_template('index.html', title='Blog', content_string=content)
|
||||
|
||||
|
||||
@app.route('/archive')
|
||||
@app.route('/archive.html')
|
||||
def blog_archive():
|
||||
content = con_gen.gen_arch_string()
|
||||
return render_template('archive.html', title='Blog Archive', content_string=content)
|
||||
|
||||
|
||||
@app.route('/feed.xml')
|
||||
@app.route('/rss.xml')
|
||||
def feed():
|
||||
content = con_gen.get_rss_string()
|
||||
rss_xml = render_template('rss.xml', content_string=content)
|
||||
response = make_response(rss_xml)
|
||||
response.headers['Content-Type'] = 'application/rss+xml'
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
104
src/content.py
Normal file
104
src/content.py
Normal file
@@ -0,0 +1,104 @@
|
||||
import datetime
|
||||
from datetime import datetime
|
||||
import markdown
|
||||
import os
|
||||
from os import path
|
||||
import pathlib
|
||||
|
||||
WEBSITE = 'localhost:5000'
|
||||
|
||||
ENTRY_DIR = 'templates/entry'
|
||||
|
||||
|
||||
def gen_arch_string():
|
||||
path_ex = ENTRY_DIR
|
||||
if path.exists(path_ex):
|
||||
name_list = os.listdir(path_ex)
|
||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||
contents = sorted(full_list, key=os.path.getctime)
|
||||
content_string = ''
|
||||
for file in reversed(contents):
|
||||
filename = pathlib.PurePath(file)
|
||||
title = open(filename).readline().rstrip('\n')
|
||||
filename = filename.name
|
||||
if filename[0] != '.':
|
||||
filename = filename.split('.', 1)[0]
|
||||
content_string += '<a href="' + '/index.html#' + \
|
||||
filename + '">' + title + '</a><br>\n'
|
||||
return content_string
|
||||
|
||||
|
||||
def gen_index_string():
|
||||
path_ex = ENTRY_DIR
|
||||
content_string = ''
|
||||
if path.exists(path_ex):
|
||||
name_list = os.listdir(path_ex)
|
||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||
contents = sorted(full_list, key=os.path.getctime)
|
||||
for file in reversed(contents):
|
||||
filename = pathlib.PurePath(file)
|
||||
purefile = filename
|
||||
title = open(filename).readline().rstrip('\n')
|
||||
text = open(filename).readlines()[1:]
|
||||
filename = filename.name
|
||||
if filename[0] != '.':
|
||||
filename = filename.split('.', 1)[0]
|
||||
content_string += '<div class=\'entry\'>\n'
|
||||
content_string += '<h2 id=\'' + filename + '\'>' + title + '</h2>\n'
|
||||
if file.endswith('.html'):
|
||||
for line in text:
|
||||
content_string += line
|
||||
content_string += '<br>'
|
||||
if file.endswith('.md'):
|
||||
content_string += gen_md_content(file)
|
||||
content_string += '<small>' + \
|
||||
datetime.fromtimestamp(os.path.getctime(
|
||||
file)).strftime('%Y-%m-%d') + '</small>'
|
||||
content_string += '</div>'
|
||||
return content_string
|
||||
|
||||
|
||||
def gen_md_content(path_ex):
|
||||
content_string = ''
|
||||
if path.exists(path_ex):
|
||||
filename = path_ex.split('.', 1)
|
||||
fileend = filename[len(filename) - 1]
|
||||
markdown_file = open(path_ex, "r")
|
||||
depth = 2
|
||||
header = '#'
|
||||
for i in range(depth):
|
||||
header += '#'
|
||||
header += ' '
|
||||
markdown_text = markdown_file.read().replace('# ', header)
|
||||
content_string = markdown.markdown(
|
||||
markdown_text, extensions=["fenced_code", "tables"]
|
||||
)
|
||||
return content_string
|
||||
|
||||
|
||||
def get_rss_string():
|
||||
path_ex = ENTRY_DIR
|
||||
if path.exists(path_ex):
|
||||
name_list = os.listdir(path_ex)
|
||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||
contents = sorted(full_list, key=os.path.getctime)
|
||||
content_string = ''
|
||||
for file in reversed(contents):
|
||||
filename = pathlib.PurePath(file)
|
||||
title = open(filename).readline().rstrip('\n')
|
||||
text = open(filename).readlines()[1:]
|
||||
filename = filename.name
|
||||
if filename[0] != '.':
|
||||
filename = filename.split('.', 1)[0]
|
||||
content_string += '<item>\n'
|
||||
content_string += '<title>' + title + '</title>\n'
|
||||
content_string += '<guid>' + '/index.html#' + filename + '</guid>\n'
|
||||
content_string += '<pubDate>' + \
|
||||
datetime.fromtimestamp(os.path.getctime(file)).strftime(
|
||||
'%Y-%m-%d') + '</pubDate>\n'
|
||||
content_string += '<description>'
|
||||
for line in text:
|
||||
content_string += line
|
||||
content_string += '</description>\n'
|
||||
content_string += '</item>\n'
|
||||
return content_string
|
2
src/requirements.txt
Normal file
2
src/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Flask==1.1.2
|
||||
Markdown==3.1.1
|
76
src/static/css/blog.css
Normal file
76
src/static/css/blog.css
Normal file
@@ -0,0 +1,76 @@
|
||||
:root {
|
||||
--bg0: rgb(29,32,33);
|
||||
--color0: rgb(0,0,0);
|
||||
--error: rgb(255,0,0);
|
||||
--footerbg0: rgb(29,32,33);
|
||||
--link0: rgb(220, 120, 0);
|
||||
--link1: rgb(255,255,255);
|
||||
--menulink0: rgb(220, 120, 0);
|
||||
--menulink1: rgb(255,255,255);
|
||||
--menubg0: rgb(29,32,33);
|
||||
--text0: rgb(235,219,178);
|
||||
--text1: rgb(220, 120, 0);
|
||||
--transtime: 0.7s;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--link0);
|
||||
text-decoration: none;
|
||||
transition: var(--transtime);
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--link1);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg0);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body,
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
span {
|
||||
color: var(--text1);
|
||||
}
|
||||
|
||||
.container {
|
||||
color: var(--text0);
|
||||
min-height: 100%;
|
||||
padding-bottom: 50px;
|
||||
padding-left: 10%;
|
||||
padding-right: 10%;
|
||||
padding-top: 5%;
|
||||
}
|
||||
|
||||
.container h1,
|
||||
.container h2 {
|
||||
color: var(--text1);
|
||||
}
|
||||
|
||||
.entry {
|
||||
background: var(--blogbg0);
|
||||
border-left: 10px solid var(--blogclr0);
|
||||
border-radius: 0 10px 30px 0;
|
||||
color: var(--text0);
|
||||
margin-bottom: 20px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.entry h1,
|
||||
.entry h2 {
|
||||
color: var(--text1);
|
||||
margin: 5px auto 2px auto;
|
||||
}
|
1
src/static/css/style.css
Normal file
1
src/static/css/style.css
Normal file
@@ -0,0 +1 @@
|
||||
@import "blog.css";
|
11
src/templates/archive.html
Normal file
11
src/templates/archive.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{% extends 'template.html' %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="blogarchive">
|
||||
<h1>Blog-Archive</h1><br>
|
||||
{% autoescape off %}
|
||||
{{ content_string }}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
2
src/templates/entry/test-entry1.html
Normal file
2
src/templates/entry/test-entry1.html
Normal file
@@ -0,0 +1,2 @@
|
||||
Test Entry Title 1
|
||||
This is an example blog entry.
|
2
src/templates/entry/test-entry2.html
Normal file
2
src/templates/entry/test-entry2.html
Normal file
@@ -0,0 +1,2 @@
|
||||
Test Entry Title 2
|
||||
This is another example blog entry.
|
10
src/templates/entry/test-entry3.md
Normal file
10
src/templates/entry/test-entry3.md
Normal file
@@ -0,0 +1,10 @@
|
||||
Test Entry Title 3
|
||||
This is a markdown file
|
||||
|
||||
- list entry
|
||||
- list entry
|
||||
- list entry
|
||||
|
||||
# md-header
|
||||
|
||||
more content
|
9
src/templates/error.html
Normal file
9
src/templates/error.html
Normal file
@@ -0,0 +1,9 @@
|
||||
{% extends "template.html" %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="important">
|
||||
Error<br>
|
||||
<span>{{ errorcode }}</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
15
src/templates/index.html
Normal file
15
src/templates/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends "template.html" %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="blog">
|
||||
<h1>Blog-Index</h1><br>
|
||||
<p>
|
||||
<a href="archive">Archive</a><br>
|
||||
<a href="feed.xml">RSS</a>
|
||||
</p>
|
||||
{% autoescape off %}
|
||||
{{ content_string }}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
16
src/templates/rss.xml
Normal file
16
src/templates/rss.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
|
||||
<channel>
|
||||
<title>Blog Title</title>
|
||||
<description>A short description of the blog.</description>
|
||||
<language>en-us</language>
|
||||
<link>localhost:5000/feed.xml</link>
|
||||
<atom:link href="/feed.xml" rel="self" type="application/rss+xml" />
|
||||
|
||||
{% autoescape off %}
|
||||
{{ content_string }}
|
||||
{% endautoescape %}
|
||||
|
||||
</channel>
|
||||
</rss>
|
14
src/templates/template.html
Normal file
14
src/templates/template.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ title }}</title>
|
||||
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width", initial-scale=1.0>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Content -->
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
<!-- Content -->
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user