mirror of
https://github.com/tiyn/beaker-blog.git
synced 2025-04-19 07:17:48 +02:00
Compare commits
No commits in common. "9fd714eef33f14e5bde503cc00d710a6ff08549e" and "9ea9ab3c5355e295b06011d91da425a556937d48" have entirely different histories.
9fd714eef3
...
9ea9ab3c53
18
Dockerfile
18
Dockerfile
@ -2,9 +2,11 @@ FROM python:3
|
|||||||
|
|
||||||
MAINTAINER tiyn tiyn@mail-mk.eu
|
MAINTAINER tiyn tiyn@mail-mk.eu
|
||||||
|
|
||||||
ENV LANG en_US.UTF-8
|
COPY src /blog
|
||||||
ENV LANGUAGE en_US:en
|
|
||||||
ENV LC_ALL en_US.UTF-8
|
WORKDIR /blog
|
||||||
|
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y locales && \
|
apt-get install -y locales && \
|
||||||
@ -12,13 +14,9 @@ RUN apt-get update && \
|
|||||||
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
|
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
|
||||||
dpkg-reconfigure --frontend=noninteractive locales
|
dpkg-reconfigure --frontend=noninteractive locales
|
||||||
|
|
||||||
RUN apt-get install -y espeak
|
ENV LANG en_US.UTF-8
|
||||||
|
ENV LANGUAGE en_US:en
|
||||||
COPY src /blog
|
ENV LC_ALL en_US.UTF-8
|
||||||
|
|
||||||
WORKDIR /blog
|
|
||||||
|
|
||||||
RUN pip3 install -r requirements.txt
|
|
||||||
|
|
||||||
VOLUME /blog/templates/entry
|
VOLUME /blog/templates/entry
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ via plain text files.
|
|||||||
- [x] Links to standalone article
|
- [x] Links to standalone article
|
||||||
- [x] Standalone article page
|
- [x] Standalone article page
|
||||||
- [x] Links to scrolling blog page
|
- [x] Links to scrolling blog page
|
||||||
- [x] TTS Functionality
|
|
||||||
- [x] RSS feed
|
- [x] RSS feed
|
||||||
- [x] Navigation
|
- [x] Navigation
|
||||||
- [x] Header
|
- [x] Header
|
||||||
|
@ -121,10 +121,6 @@ def entry(path):
|
|||||||
def feed_re():
|
def feed_re():
|
||||||
return redirect(url_for("feed"))
|
return redirect(url_for("feed"))
|
||||||
|
|
||||||
@app.route("/robots.txt")
|
|
||||||
def robots():
|
|
||||||
return render_template("robots.txt")
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/feed")
|
@app.route("/feed")
|
||||||
def feed():
|
def feed():
|
||||||
@ -141,5 +137,4 @@ def feed():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
con_gen.prepare_tts()
|
|
||||||
app.run(host="0.0.0.0")
|
app.run(host="0.0.0.0")
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import glob
|
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@ -8,7 +7,6 @@ from os import path
|
|||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from gtts import gTTS, gTTSError
|
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import search
|
import search
|
||||||
@ -146,11 +144,6 @@ def gen_stand_string(path_ex):
|
|||||||
content_string += "<a href=\"" + "/index.html#" + \
|
content_string += "<a href=\"" + "/index.html#" + \
|
||||||
filename_no_end + "\">" + curr_date + "</a>"
|
filename_no_end + "\">" + curr_date + "</a>"
|
||||||
content_string += "<br><br>\n"
|
content_string += "<br><br>\n"
|
||||||
if os.path.isfile("static/tmp/" + filename_no_end + ".mp3"):
|
|
||||||
content_string += "<audio controls>\n"
|
|
||||||
content_string += '<source src="/static/tmp/' + filename_no_end + '.mp3" type="audio/mp3">\n'
|
|
||||||
content_string += "</audio>\n"
|
|
||||||
content_string += "<br><br>\n"
|
|
||||||
if filename.endswith(".html"):
|
if filename.endswith(".html"):
|
||||||
for line in text:
|
for line in text:
|
||||||
content_string += line
|
content_string += line
|
||||||
@ -277,55 +270,3 @@ def create_preview(path, is_markdown):
|
|||||||
preview = "\n<p>" + first_p.text + "</p>\n"
|
preview = "\n<p>" + first_p.text + "</p>\n"
|
||||||
preview += "...<br>"
|
preview += "...<br>"
|
||||||
return preview
|
return preview
|
||||||
|
|
||||||
|
|
||||||
def get_text_only(filename):
|
|
||||||
"""
|
|
||||||
Convert a file to text only to use in tts
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
path (string): path to the article
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
string: unformatted string containing the contents of the file
|
|
||||||
"""
|
|
||||||
# filename = os.path.join(ENTRY_DIR, path)
|
|
||||||
clean_text = ""
|
|
||||||
if path.exists(filename):
|
|
||||||
title = open(filename).readline().rstrip("\n")
|
|
||||||
text = open(filename).readlines()[1:]
|
|
||||||
filename_no_end = filename.split(".", 1)[0]
|
|
||||||
filename_no_end = filename_no_end.split("/")[-1]
|
|
||||||
content_string = ""
|
|
||||||
if filename.endswith(".html"):
|
|
||||||
for line in text:
|
|
||||||
content_string += line
|
|
||||||
if filename.endswith(".md"):
|
|
||||||
content_string += gen_md_content(filename, 1)
|
|
||||||
content_string = absolutize_html(content_string)
|
|
||||||
soup = BeautifulSoup(content_string, "html.parser")
|
|
||||||
tag_to_remove = soup.find("figure")
|
|
||||||
if tag_to_remove:
|
|
||||||
tag_to_remove.decompose()
|
|
||||||
clean_text = soup.get_text(separator=" ")
|
|
||||||
clean_text = title + "\n\n" + clean_text
|
|
||||||
return clean_text
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_tts():
|
|
||||||
files = glob.glob('static/tmp/*')
|
|
||||||
for f in files:
|
|
||||||
os.remove(f)
|
|
||||||
files = glob.glob('templates/entry/*')
|
|
||||||
clean_text = ""
|
|
||||||
for f in files:
|
|
||||||
clean_text = get_text_only(f)
|
|
||||||
_, tail = os.path.split(f)
|
|
||||||
new_filename = "static/tmp/" + os.path.splitext(tail)[0] + ".mp3"
|
|
||||||
try:
|
|
||||||
tts = gTTS(clean_text, lang=LANGUAGE.split("-")[0])
|
|
||||||
tts.save(new_filename)
|
|
||||||
except gTTSError as e:
|
|
||||||
print("Too many request to the google servers. Try it again later.")
|
|
||||||
os.remove(new_filename)
|
|
||||||
return e
|
|
||||||
|
@ -5,4 +5,3 @@ WTForms
|
|||||||
Flask_WTF
|
Flask_WTF
|
||||||
Font-Awesome-Flask
|
Font-Awesome-Flask
|
||||||
BeautifulSoup4
|
BeautifulSoup4
|
||||||
gTTS
|
|
||||||
|
@ -269,12 +269,6 @@ form.search::after {
|
|||||||
.standalone img {
|
.standalone img {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.entry img {
|
.entry img {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio {
|
|
||||||
width: 50%;
|
|
||||||
height: 5vh;
|
|
||||||
}
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
User-agent: *
|
|
||||||
Disallow: /static/
|
|
Loading…
x
Reference in New Issue
Block a user