1
0
mirror of https://github.com/tiyn/beaker-blog.git synced 2025-04-19 07:17:48 +02:00

Compare commits

..

No commits in common. "93767e6c8b6fa5f6c221301a733b0d6eeed94703" and "b2676f6bd982a9eafbfd80f4ac1a6a226c78b595" have entirely different histories.

4 changed files with 72 additions and 72 deletions

View File

@ -1,4 +1,4 @@
from flask import Flask, make_response, render_template, abort from flask import Flask, flash, make_response, render_template, request, redirect, abort
import content as con_gen import content as con_gen
import config import config
@ -25,7 +25,7 @@ def index():
@app.route("/archive") @app.route("/archive")
@app.route("/archive.html") @app.route("/archive.html")
def archive(): def blog_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)

View File

@ -6,7 +6,7 @@ import pathlib
import config import config
ENTRY_DIR = "templates/entry" ENTRY_DIR = 'templates/entry'
def gen_arch_string(): def gen_arch_string():
""" """
@ -20,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
@ -59,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]
@ -67,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
@ -103,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
@ -133,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"]
) )
@ -163,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

View File

View File

@ -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">&#9776;</label> <label for="main-menu-check" class="show-menu">&#9776;</label>
<div class="main-menu"> <div class="main-menu">
<a href="{{ url_for('index') }}">Blog</a> <a href="/">Blog</a>
<a href="{{ url_for('archive') }}">Archive</a> <a href="/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>