1
0
mirror of https://github.com/tiyn/beaker-blog.git synced 2026-02-22 04:44:48 +01:00

adding dockerfile

This commit is contained in:
TiynGER
2020-05-24 17:51:22 +02:00
parent 8896d477e4
commit bcbf36d7a0
15 changed files with 24 additions and 1 deletions

104
src/content.py Normal file
View 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