mirror of
https://github.com/tiyn/beaker-blog.git
synced 2025-10-26 16:41:15 +01:00
Compare commits
6 Commits
3bd8877b5d
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fa7c9339c | ||
| 93767e6c8b | |||
| 6f5c5a98af | |||
| b2676f6bd9 | |||
| 8e2badcea7 | |||
| 8f7ae7a075 |
@@ -43,7 +43,7 @@ You have to specify the filetype by extension.
|
|||||||
### PIP/Python
|
### PIP/Python
|
||||||
|
|
||||||
- `git clone https://github.com/tiyn/beaker-blog`
|
- `git clone https://github.com/tiyn/beaker-blog`
|
||||||
- `cd tiyny-blog/src`
|
- `cd beaker-blog/src`
|
||||||
- edit the `config.py` file according to your needs
|
- edit the `config.py` file according to your needs
|
||||||
- `pip3install -r requirements.txt` - install depenencies
|
- `pip3install -r requirements.txt` - install depenencies
|
||||||
- run `python app.py`
|
- run `python app.py`
|
||||||
|
|||||||
36
src/app.py
36
src/app.py
@@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, flash, make_response, render_template, request, redirect, abort
|
from flask import Flask, make_response, render_template, abort
|
||||||
|
|
||||||
import content as con_gen
|
import content as con_gen
|
||||||
import config
|
import config
|
||||||
@@ -13,41 +13,41 @@ WEBSITE = config.WEBSITE
|
|||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
return render_template('error.html', title=TITLE, errorcode='404', style=STYLE), 404
|
return render_template("error.html", title=TITLE, errorcode="404", style=STYLE), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route("/")
|
||||||
@app.route('/index.html')
|
@app.route("/index.html")
|
||||||
def index():
|
def index():
|
||||||
content = con_gen.gen_index_string()
|
content = con_gen.gen_index_string()
|
||||||
return render_template('index.html', title=TITLE, content_string=content, style=STYLE)
|
return render_template("index.html", title=TITLE, content_string=content, style=STYLE)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/archive')
|
@app.route("/archive")
|
||||||
@app.route('/archive.html')
|
@app.route("/archive.html")
|
||||||
def blog_archive():
|
def archive():
|
||||||
content = con_gen.gen_arch_string()
|
content = con_gen.gen_arch_string()
|
||||||
return render_template('archive.html', title=TITLE, content_string=content, style=STYLE)
|
return render_template("archive.html", title=TITLE, content_string=content, style=STYLE)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entry/<path>')
|
@app.route("/entry/<path>")
|
||||||
def entry(path):
|
def entry(path):
|
||||||
content = con_gen.gen_stand_string(path)
|
content = con_gen.gen_stand_string(path)
|
||||||
if content != '':
|
if content != "":
|
||||||
return render_template('standalone.html', title=TITLE, content_string=content, style=STYLE)
|
return render_template("standalone.html", title=TITLE, content_string=content, style=STYLE)
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/feed.xml')
|
@app.route("/feed.xml")
|
||||||
@app.route('/rss.xml')
|
@app.route("/rss.xml")
|
||||||
def feed():
|
def feed():
|
||||||
content = con_gen.get_rss_string()
|
content = con_gen.get_rss_string()
|
||||||
rss_xml = render_template('rss.xml', content_string=content, title=TITLE,
|
rss_xml = render_template("rss.xml", content_string=content, title=TITLE,
|
||||||
description=DESCRIPTION, website=WEBSITE)
|
description=DESCRIPTION, website=WEBSITE)
|
||||||
response = make_response(rss_xml)
|
response = make_response(rss_xml)
|
||||||
response.headers['Content-Type'] = 'application/rss+xml'
|
response.headers["Content-Type"] = "application/rss+xml"
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0')
|
app.run(host="0.0.0.0")
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
# Name/title of your blog
|
# Name/title of your blog
|
||||||
TITLE = 'Beaker Blog'
|
TITLE = "Beaker Blog"
|
||||||
|
|
||||||
# Description for RSS of your blog
|
# Description for RSS of your blog
|
||||||
DESCRIPTION = 'This is your personal Beaker Blog.'
|
DESCRIPTION = "This is your personal Beaker Blog."
|
||||||
|
|
||||||
# URL for your website: e.g. https://domain.tld
|
# URL for your website: e.g. https://domain.tld
|
||||||
WEBSITE = 'localhost:5000'
|
WEBSITE = "localhost:5000"
|
||||||
|
|
||||||
# Theme for the blog: dark, light
|
# Theme for the blog: dark, light
|
||||||
STYLE = 'dark'
|
STYLE = "dark"
|
||||||
|
|||||||
138
src/content.py
138
src/content.py
@@ -1,4 +1,3 @@
|
|||||||
import datetime
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import markdown
|
import markdown
|
||||||
import os
|
import os
|
||||||
@@ -7,8 +6,7 @@ import pathlib
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
ENTRY_DIR = 'templates/entry'
|
ENTRY_DIR = "templates/entry"
|
||||||
|
|
||||||
|
|
||||||
def gen_arch_string():
|
def gen_arch_string():
|
||||||
"""
|
"""
|
||||||
@@ -22,34 +20,34 @@ def gen_arch_string():
|
|||||||
name_list = os.listdir(path_ex)
|
name_list = os.listdir(path_ex)
|
||||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||||
contents = sorted(full_list, key=os.path.getctime)
|
contents = sorted(full_list, key=os.path.getctime)
|
||||||
content_string = ''
|
content_string = ""
|
||||||
last_month = ''
|
last_month = ""
|
||||||
for file in reversed(contents):
|
for file in reversed(contents):
|
||||||
curr_date = datetime.fromtimestamp(
|
curr_date = datetime.fromtimestamp(
|
||||||
os.path.getctime(file)).strftime('%Y-%m-%d')
|
os.path.getctime(file)).strftime("%Y-%m-%d")
|
||||||
curr_month = datetime.fromtimestamp(
|
curr_month = datetime.fromtimestamp(
|
||||||
os.path.getctime(file)).strftime('%b %Y')
|
os.path.getctime(file)).strftime("%b %Y")
|
||||||
if curr_month != last_month:
|
if curr_month != last_month:
|
||||||
if last_month != '':
|
if last_month != "":
|
||||||
content_string += '</ul>\n'
|
content_string += "</ul>\n"
|
||||||
content_string += '<h2>' + curr_month + '</h2>\n'
|
content_string += "<h2>" + curr_month + "</h2>\n"
|
||||||
content_string += '<ul>\n'
|
content_string += "<ul>\n"
|
||||||
last_month = curr_month
|
last_month = curr_month
|
||||||
filename = pathlib.PurePath(file)
|
filename = pathlib.PurePath(file)
|
||||||
title = open(filename).readline().rstrip('\n')
|
title = open(filename).readline().rstrip("\n")
|
||||||
filename = filename.name
|
filename = filename.name
|
||||||
if filename[0] != '.':
|
if filename[0] != ".":
|
||||||
filename = filename.split('.', 1)[0]
|
filename = filename.split(".", 1)[0]
|
||||||
content_string += '<li>'
|
content_string += "<li>"
|
||||||
content_string += curr_date + ' - '
|
content_string += curr_date + " - "
|
||||||
content_string += title + ' ['
|
content_string += title + " ["
|
||||||
content_string += '<a href="' + '/index.html#' + \
|
content_string += "<a href=\"" + "/index.html#" + \
|
||||||
filename + '">' + 'link' + '</a> - '
|
filename + "\">" + "link" + "</a> - "
|
||||||
content_string += '<a href="' + '/entry/' + \
|
content_string += "<a href=\"" + "/entry/" + \
|
||||||
pathlib.PurePath(file).name + '">' + 'standalone' + '</a>'
|
pathlib.PurePath(file).name + "\">" + "standalone" + "</a>"
|
||||||
content_string += '] <br>'
|
content_string += "] <br>"
|
||||||
content_string += '</li>\n'
|
content_string += "</li>\n"
|
||||||
content_string += '</ul>\n'
|
content_string += "</ul>\n"
|
||||||
return content_string
|
return content_string
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ def gen_index_string():
|
|||||||
string: html-formatted index string
|
string: html-formatted index string
|
||||||
"""
|
"""
|
||||||
path_ex = ENTRY_DIR
|
path_ex = ENTRY_DIR
|
||||||
content_string = ''
|
content_string = ""
|
||||||
if path.exists(path_ex):
|
if path.exists(path_ex):
|
||||||
name_list = os.listdir(path_ex)
|
name_list = os.listdir(path_ex)
|
||||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||||
@@ -69,26 +67,26 @@ def gen_index_string():
|
|||||||
for file in reversed(contents):
|
for file in reversed(contents):
|
||||||
filename = pathlib.PurePath(file)
|
filename = pathlib.PurePath(file)
|
||||||
purefile = filename
|
purefile = filename
|
||||||
title = open(filename).readline().rstrip('\n')
|
title = open(filename).readline().rstrip("\n")
|
||||||
text = open(filename).readlines()[1:]
|
text = open(filename).readlines()[1:]
|
||||||
filename = filename.name
|
filename = filename.name
|
||||||
if filename[0] != '.':
|
if filename[0] != ".":
|
||||||
filename = filename.split('.', 1)[0]
|
filename = filename.split(".", 1)[0]
|
||||||
content_string += '<div class=\'entry\'>\n'
|
content_string += "<div class=\"entry\">\n"
|
||||||
content_string += '<h2 id=\'' + filename + '\'>' + title + '</h2>\n'
|
content_string += "<h2 id=\"" + filename + "\">" + title + "</h2>\n"
|
||||||
content_string += '[<a href="' + '/entry/' + \
|
content_string += "[<a href=\"" + "/entry/" + \
|
||||||
pathlib.PurePath(file).name + '">' + \
|
pathlib.PurePath(file).name + "\">" + \
|
||||||
'standalone' + '</a>]<br>\n'
|
"standalone" + "</a>]<br>\n"
|
||||||
if file.endswith('.html'):
|
if file.endswith(".html"):
|
||||||
for line in text:
|
for line in text:
|
||||||
content_string += line
|
content_string += line
|
||||||
content_string += '<br>'
|
content_string += "<br>"
|
||||||
if file.endswith('.md'):
|
if file.endswith(".md"):
|
||||||
content_string += gen_md_content(file, 2)
|
content_string += gen_md_content(file, 2)
|
||||||
content_string += '<small>' + \
|
content_string += "<small>" + \
|
||||||
datetime.fromtimestamp(os.path.getctime(
|
datetime.fromtimestamp(os.path.getctime(
|
||||||
file)).strftime('%Y-%m-%d') + '</small>'
|
file)).strftime("%Y-%m-%d") + "</small>"
|
||||||
content_string += '</div>'
|
content_string += "</div>"
|
||||||
return content_string
|
return content_string
|
||||||
|
|
||||||
|
|
||||||
@@ -105,21 +103,21 @@ def gen_stand_string(path_ex):
|
|||||||
string: html-formatted string string equivalent to the file
|
string: html-formatted string string equivalent to the file
|
||||||
"""
|
"""
|
||||||
filename = os.path.join(ENTRY_DIR, path_ex)
|
filename = os.path.join(ENTRY_DIR, path_ex)
|
||||||
content_string = ''
|
content_string = ""
|
||||||
if path.exists(filename):
|
if path.exists(filename):
|
||||||
title = open(filename).readline().rstrip('\n')
|
title = open(filename).readline().rstrip("\n")
|
||||||
text = open(filename).readlines()[1:]
|
text = open(filename).readlines()[1:]
|
||||||
filename_no_end = filename.split('.', 1)[0]
|
filename_no_end = filename.split(".", 1)[0]
|
||||||
content_string += '<h1>' + title + '</h1>\n'
|
content_string += "<h1>" + title + "</h1>\n"
|
||||||
content_string += '['
|
content_string += "["
|
||||||
content_string += '<a href="' + '/index.html#' + \
|
content_string += "<a href=\"" + "/index.html#" + \
|
||||||
filename_no_end + '">' + 'link' + '</a>'
|
filename_no_end + "\">" + "link" + "</a>"
|
||||||
content_string += ']<br>\n'
|
content_string += "]<br>\n"
|
||||||
if filename.endswith('.html'):
|
if filename.endswith(".html"):
|
||||||
for line in text:
|
for line in text:
|
||||||
content_string += line
|
content_string += line
|
||||||
content_string += '<br>'
|
content_string += "<br>"
|
||||||
if filename.endswith('.md'):
|
if filename.endswith(".md"):
|
||||||
content_string += gen_md_content(filename, 1)
|
content_string += gen_md_content(filename, 1)
|
||||||
return content_string
|
return content_string
|
||||||
|
|
||||||
@@ -135,18 +133,18 @@ def gen_md_content(path_ex, depth):
|
|||||||
Returns:
|
Returns:
|
||||||
string: html-formatted string string equivalent to the markdown file
|
string: html-formatted string string equivalent to the markdown file
|
||||||
"""
|
"""
|
||||||
content_string = ''
|
content_string = ""
|
||||||
if path.exists(path_ex):
|
if path.exists(path_ex):
|
||||||
filename = path_ex.split('.', 1)
|
filename = path_ex.split(".", 1)
|
||||||
fileend = filename[len(filename) - 1]
|
fileend = filename[len(filename) - 1]
|
||||||
header = '#'
|
header = "#"
|
||||||
for i in range(depth):
|
for i in range(depth):
|
||||||
header += '#'
|
header += "#"
|
||||||
header += ' '
|
header += " "
|
||||||
markdown_lines = open(path_ex, "r").readlines()[1:]
|
markdown_lines = open(path_ex, "r").readlines()[1:]
|
||||||
markdown_text = ''
|
markdown_text = ""
|
||||||
for line in markdown_lines:
|
for line in markdown_lines:
|
||||||
markdown_text += line.replace('# ', header)
|
markdown_text += line.replace("# ", header)
|
||||||
content_string = markdown.markdown(
|
content_string = markdown.markdown(
|
||||||
markdown_text, extensions=["fenced_code", "tables"]
|
markdown_text, extensions=["fenced_code", "tables"]
|
||||||
)
|
)
|
||||||
@@ -165,24 +163,24 @@ def get_rss_string():
|
|||||||
name_list = os.listdir(path_ex)
|
name_list = os.listdir(path_ex)
|
||||||
full_list = [os.path.join(path_ex, i) for i in name_list]
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
||||||
contents = sorted(full_list, key=os.path.getctime)
|
contents = sorted(full_list, key=os.path.getctime)
|
||||||
content_string = ''
|
content_string = ""
|
||||||
for file in reversed(contents):
|
for file in reversed(contents):
|
||||||
filename = pathlib.PurePath(file)
|
filename = pathlib.PurePath(file)
|
||||||
title = open(filename).readline().rstrip('\n')
|
title = open(filename).readline().rstrip("\n")
|
||||||
text = open(filename).readlines()[1:]
|
text = open(filename).readlines()[1:]
|
||||||
filename = filename.name
|
filename = filename.name
|
||||||
if filename[0] != '.':
|
if filename[0] != ".":
|
||||||
filename = filename.split('.', 1)[0]
|
filename = filename.split(".", 1)[0]
|
||||||
content_string += '<item>\n'
|
content_string += "<item>\n"
|
||||||
content_string += '<title>' + title + '</title>\n'
|
content_string += "<title>" + title + "</title>\n"
|
||||||
content_string += '<guid>' + config.WEBSITE + \
|
content_string += "<guid>" + config.WEBSITE + \
|
||||||
'/index.html#' + filename + '</guid>\n'
|
"/index.html#" + filename + "</guid>\n"
|
||||||
content_string += '<pubDate>' + \
|
content_string += "<pubDate>" + \
|
||||||
datetime.fromtimestamp(os.path.getctime(file)).strftime(
|
datetime.fromtimestamp(os.path.getctime(file)).strftime(
|
||||||
'%Y-%m-%d') + '</pubDate>\n'
|
"%Y-%m-%d") + "</pubDate>\n"
|
||||||
content_string += '<description>'
|
content_string += "<description>"
|
||||||
for line in text:
|
for line in text:
|
||||||
content_string += line
|
content_string += line
|
||||||
content_string += '</description>\n'
|
content_string += "</description>\n"
|
||||||
content_string += '</item>\n'
|
content_string += "</item>\n"
|
||||||
return content_string
|
return content_string
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
Flask==1.1.2
|
Flask==2.3.2
|
||||||
Markdown==3.1.1
|
Markdown==3.1.1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'template.html' %}
|
{% extends "template.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="blogarchive">
|
<div class="blogarchive">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'template.html' %}
|
{% extends "template.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="standalone">
|
<div class="standalone">
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
<input type="checkbox" id="main-menu-check">
|
<input type="checkbox" id="main-menu-check">
|
||||||
<label for="main-menu-check" class="show-menu">☰</label>
|
<label for="main-menu-check" class="show-menu">☰</label>
|
||||||
<div class="main-menu">
|
<div class="main-menu">
|
||||||
<a href="/">Blog</a>
|
<a href="{{ url_for('index') }}">Blog</a>
|
||||||
<a href="/archive">Archive</a>
|
<a href="{{ url_for('archive') }}">Archive</a>
|
||||||
<label for="main-menu-check" class="hide-menu">X</label>
|
<label for="main-menu-check" class="hide-menu">X</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user