1
0
mirror of https://github.com/tiyn/beaker-blog.git synced 2025-04-19 15:27:47 +02:00

Compare commits

..

10 Commits

Author SHA1 Message Date
41ba108e3f fixed tabbing for doc strings 2024-04-21 00:53:28 +02:00
84750323c1 automatically convert to absolute links 2024-04-21 00:51:17 +02:00
e4744ee451 fixed typos 2024-04-21 00:02:04 +02:00
6fb7411156 made tabbing in css uniform 2024-04-20 23:41:39 +02:00
0ff2bffc99 fixed scrolling behaviour 2024-04-20 23:38:16 +02:00
60be3da149 tried to change scrolling behaviour 2024-04-20 20:30:04 +02:00
a862ac0966 make preview use the first paragraph 2024-04-20 20:12:43 +02:00
070be5b0e2 fixed html for basic sites 2024-04-20 20:01:55 +02:00
2a2a5f77b6 fixed rss errors 2024-04-20 18:34:51 +02:00
a4d2290e47 redirect to uniform site links 2024-04-20 17:18:54 +02:00
9 changed files with 341 additions and 282 deletions

View File

@ -1,4 +1,4 @@
from flask import Flask, abort, make_response, render_template, request from flask import (Flask, abort, make_response, redirect, render_template, request, url_for)
from flask_font_awesome import FontAwesome from flask_font_awesome import FontAwesome
import config import config
@ -28,8 +28,12 @@ def page_not_found(e):
language=LANGUAGE), 404 language=LANGUAGE), 404
@app.route("/")
@app.route("/index.html") @app.route("/index.html")
def index_re():
return redirect(url_for("index"))
@app.route("/")
def index(): def index():
content = con_gen.gen_index_string() content = con_gen.gen_index_string()
return render_template("index.html", return render_template("index.html",
@ -40,8 +44,12 @@ def index():
language=LANGUAGE) language=LANGUAGE)
@app.route("/search", methods=["GET", "POST"])
@app.route("/search.html", methods=["GET", "POST"]) @app.route("/search.html", methods=["GET", "POST"])
def search_re():
return redirect(url_for("search"))
@app.route("/search", methods=["GET", "POST"])
def search(): def search():
form = SearchForm() form = SearchForm()
if request.method == "POST": if request.method == "POST":
@ -63,8 +71,12 @@ def search():
language=LANGUAGE), 200 language=LANGUAGE), 200
@app.route("/imprint")
@app.route("/imprint.html") @app.route("/imprint.html")
def imprint_re():
return redirect(url_for("imprint"))
@app.route("/imprint")
def imprint(): def imprint():
return render_template("imprint.html", return render_template("imprint.html",
title=TITLE, title=TITLE,
@ -74,8 +86,12 @@ def imprint():
language=LANGUAGE) language=LANGUAGE)
@app.route("/archive")
@app.route("/archive.html") @app.route("/archive.html")
def archive_re():
return redirect(url_for("archive"))
@app.route("/archive")
def archive(): def archive():
content = con_gen.gen_arch_string() content = con_gen.gen_arch_string()
return render_template("archive.html", return render_template("archive.html",
@ -101,14 +117,21 @@ def entry(path):
@app.route("/feed.xml") @app.route("/feed.xml")
@app.route("/rss.xml") @app.route("/rss.xml")
@app.route("/rss")
def feed_re():
return redirect(url_for("feed"))
@app.route("/feed")
def feed(): def feed():
content = con_gen.get_rss_string() content = con_gen.get_rss_string()
rss_xml = render_template("rss.xml", feed_xml = render_template("feed.xml",
content_string=content, content_string=content,
title=TITLE, title=TITLE,
description=DESCRIPTION, description=DESCRIPTION,
website=WEBSITE) website=WEBSITE,
response = make_response(rss_xml) language=LANGUAGE)
response = make_response(feed_xml)
response.headers["Content-Type"] = "application/rss+xml" response.headers["Content-Type"] = "application/rss+xml"
return response return response

View File

@ -1,14 +1,17 @@
import locale import locale
import os import os
import pathlib import pathlib
import urllib.parse
from datetime import datetime from datetime import datetime
from os import path from os import path
import markdown import markdown
from bs4 import BeautifulSoup
import config import config
import search import search
WEBSITE = config.WEBSITE
ENTRY_DIR = config.ENTRY_DIR ENTRY_DIR = config.ENTRY_DIR
LANGUAGE = config.LANGUAGE LANGUAGE = config.LANGUAGE
LOCAL = "de_DE.UTF-8" if LANGUAGE == "de-de" else "en_US.UTF-8" LOCAL = "de_DE.UTF-8" if LANGUAGE == "de-de" else "en_US.UTF-8"
@ -90,9 +93,32 @@ def gen_index_string():
if file.endswith(".md"): if file.endswith(".md"):
content_string += gen_md_content(file, 2) content_string += gen_md_content(file, 2)
content_string += "</div>" content_string += "</div>"
content_string = absolutize_html(content_string)
return content_string return content_string
def absolutize_html(string):
"""
Creates a html string from another string that only uses absolute links that use the full domain.
Parameters:
string: html-formatted string.
Returns:
string: html-formatted string with absolute linksn
"""
soup = BeautifulSoup(string, "html.parser")
for a_tag in soup.find_all("a"):
href = str(a_tag.get("href"))
if href.startswith("/") or href.startswith("."):
a_tag["href"] = urllib.parse.urljoin(WEBSITE, href)
for img_tag in soup.find_all("img"):
src = str(img_tag.get("src"))
if src.startswith("/") or src.startswith("."):
img_tag["src"] = urllib.parse.urljoin(WEBSITE, src)
return str(soup)
def gen_stand_string(path_ex): def gen_stand_string(path_ex):
""" """
Creates a html-string for a file. Creates a html-string for a file.
@ -122,6 +148,7 @@ def gen_stand_string(path_ex):
content_string += line content_string += line
if filename.endswith(".md"): if filename.endswith(".md"):
content_string += gen_md_content(filename, 1) content_string += gen_md_content(filename, 1)
content_string = absolutize_html(content_string)
return content_string return content_string
@ -138,10 +165,8 @@ def gen_md_content(path_ex, depth):
""" """
content_string = "" content_string = ""
if path.exists(path_ex): if path.exists(path_ex):
filename = path_ex.split(".", 1)
fileend = filename[len(filename) - 1]
header = "#" header = "#"
for i in range(depth): for _ in range(depth):
header += "#" header += "#"
header += " " header += " "
markdown_lines = open(path_ex, "r").readlines()[1:] markdown_lines = open(path_ex, "r").readlines()[1:]
@ -159,6 +184,7 @@ def get_rss_string():
Returns: Returns:
string: rss-string of everything that is in the ENTRY_DIR. string: rss-string of everything that is in the ENTRY_DIR.
""" """
locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
path_ex = ENTRY_DIR path_ex = ENTRY_DIR
content_string = "" content_string = ""
if path.exists(path_ex): if path.exists(path_ex):
@ -174,16 +200,19 @@ def get_rss_string():
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>" + WEBSITE + \
"/index.html#" + filename + "</guid>\n" "/index.html#" + filename + "</guid>\n"
content_string += "<pubDate>" + \ content_string += "<pubDate>" + \
datetime.fromtimestamp(os.path.getmtime(file)).strftime( datetime.fromtimestamp(os.path.getmtime(file)).strftime(
"%Y-%m-%d") + "</pubDate>\n" "%a, %d %b %Y %H:%M:%S") + " +0100</pubDate>\n"
content_string += "<description>" content_string += "<description>\n<![CDATA[<html>\n<head>\n</head>\n<body>\n"
html_string = ""
for line in text: for line in text:
content_string += line html_string += line
content_string += "</description>\n" content_string += absolutize_html(html_string)
content_string += "\n</body></html>\n]]>\n</description>\n"
content_string += "</item>\n" content_string += "</item>\n"
locale.setlocale(locale.LC_TIME, LOCAL)
return content_string return content_string
@ -231,20 +260,12 @@ def create_preview(path, is_markdown):
string: html-formated preview string: html-formated preview
""" """
file = open(path, "r", encoding="utf-8") file = open(path, "r", encoding="utf-8")
first_lines = file.readlines() lines = file.read()
preview = ""
preview_length = 3
for i, line in enumerate(first_lines):
if i == 0:
continue
if i > preview_length:
break
if not line.isspace():
if is_markdown: if is_markdown:
preview += markdown.markdown(line) lines += markdown.markdown(lines)
else: preview = ""
preview += line first_p = BeautifulSoup(lines).find('p')
else: if first_p is not None:
preview_length += 1 preview = "\n<p>" + first_p.text + "</p>\n"
preview += "<br>...<br>" preview += "...<br>"
return preview return preview

View File

@ -4,3 +4,4 @@ Whoosh
WTForms WTForms
Flask_WTF Flask_WTF
Font-Awesome-Flask Font-Awesome-Flask
BeautifulSoup4

View File

@ -14,7 +14,6 @@ ENTRY_DIR = config.ENTRY_DIR
def createSearchableData(root): def createSearchableData(root):
""" """
Schema definition: title(name of file), path(as ID), content(indexed but not stored), textdata (stored text content) Schema definition: title(name of file), path(as ID), content(indexed but not stored), textdata (stored text content)
source: source:
https://appliedmachinelearning.blog/2018/07/31/developing-a-fast-indexing-and-full-text-search-engine-with-whoosh-a-pure-pythhon-library/ https://appliedmachinelearning.blog/2018/07/31/developing-a-fast-indexing-and-full-text-search-engine-with-whoosh-a-pure-pythhon-library/

View File

@ -76,7 +76,6 @@ span {
} }
@media screen and (max-width:800px) { @media screen and (max-width:800px) {
.main-menu { .main-menu {
background: var(--menubg0); background: var(--menubg0);
} }

View File

@ -24,7 +24,6 @@ body {
body, body,
html { html {
font-family: sans-serif; font-family: sans-serif;
height: 100%;
max-width: 100%; max-width: 100%;
overflow-x: hidden; overflow-x: hidden;
} }
@ -80,6 +79,7 @@ footer .center {
.main-menu-dropdown img { .main-menu-dropdown img {
float: left; float: left;
} }
.main-menu-dropdown span, .main-menu-dropdown span,
.main-menu-dropdown a { .main-menu-dropdown a {
float: left; float: left;
@ -147,6 +147,7 @@ footer .center {
transition: var(--transtime); transition: var(--transtime);
width: 100%; width: 100%;
} }
.main-menu a { .main-menu a {
display: block; display: block;
padding: 20px; padding: 20px;
@ -161,8 +162,13 @@ form {
margin-bottom: 40px; margin-bottom: 40px;
} }
.standalone {
max-height: 100%;
}
.entry { .entry {
border-radius: 0 10px 30px 0; max-height: 100%;
/* border-radius: 0 10px 30px 0; */
margin-bottom: 20px; margin-bottom: 20px;
padding-left: 20px; padding-left: 20px;
} }
@ -225,7 +231,7 @@ ol {
} }
code { code {
border-radius: 25px; /* border-radius: 25px; */
padding-left: 20px; padding-left: 20px;
padding-right: 20px; padding-right: 20px;
page-break-inside: avoid; page-break-inside: avoid;
@ -258,3 +264,10 @@ form.search::after {
clear: both; clear: both;
display: table; display: table;
} }
.standalone img {
width: 50%;
}
.entry img {
width: 50%;
}

View File

@ -5,8 +5,8 @@
<title>{{ title }}</title> <title>{{ title }}</title>
<description>{{ description }}</description> <description>{{ description }}</description>
<language>{{ language }}</language> <language>{{ language }}</language>
<link>{{ website }}/feed.xml</link> <link>{{ website }}</link>
<atom:link href="/feed.xml" rel="self" type="application/rss+xml" /> <atom:link href="{{ website }}{{ url_for('feed') }}" rel="self" type="application/rss+xml"/>
{% autoescape off %} {% autoescape off %}
{{ content_string }} {{ content_string }}

View File

@ -1,11 +1,12 @@
<html> <!DOCTYPE html>
<html lang={% if language=="de-de" %}de{% else %}en{% endif %}>
<head> <head>
<title>{{ title }}</title> <title>{{ title }}</title>
<link href="{{ url_for('static', filename='css/' + style + '.css') }}" rel="stylesheet" type="text/css"> <link href="{{ url_for('static', filename='css/' + style + '.css') }}" rel="stylesheet" type="text/css">
<link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='graphics/logo.png')}}"> <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='graphics/logo.png')}}">
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width" initial-scale=1.0> <meta name="viewport" content="width=device-width">
{{ font_awesome.load_js() }} {{ font_awesome.load_js() }}
</head> </head>
@ -13,7 +14,9 @@
<!-- Menu --> <!-- Menu -->
<div class="main-menu-dropdown"> <div class="main-menu-dropdown">
<a href="{{ url_for('index') }}"> <a href="{{ url_for('index') }}">
<img class="logo" src="{{ url_for('static', filename='graphics/logo.png') }}"> <img class="logo" src="{{ url_for('static', filename='graphics/logo.png') }}" alt="Logo von
Mittelerde mit Marten. Zu sehen sind 3 'M's mit Serifen, wobei die beiden Äußeren etwas
kleiner sind">
{{ stitle }} {{ stitle }}
</a> </a>
<input type="checkbox" id="main-menu-check"> <input type="checkbox" id="main-menu-check">