diff --git a/.gitignore b/.gitignore index 7c04d35..3ad2029 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ lib64 pyvenv.cfg __pycache__/ + +src/public/fonts/ diff --git a/requirements.txt b/requirements.txt index c9edc1a..85fea28 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Flask==2.2.2 +requests==2.28.1 diff --git a/src/app.py b/src/app.py index cf61dd5..b923f06 100644 --- a/src/app.py +++ b/src/app.py @@ -1,18 +1,15 @@ -from routes.index import router as index from flask import Flask, redirect +from font import init as init_font +from routes.index import router as index + app = Flask(__name__, static_url_path="/", static_folder="public") app.register_blueprint(index, url_prefix="/index") +init_font("1.3.0") + @app.route("/") def root(): return redirect("index") - - -class AttributeDict(dict): - def __getattr__(self, name): - if name in self: - return self[name] - raise AttributeError(name) diff --git a/src/font.py b/src/font.py new file mode 100644 index 0000000..968045a --- /dev/null +++ b/src/font.py @@ -0,0 +1,37 @@ +from os import mkdir + +from requests import get + + +def exist(path): + """Check if file or directory exists""" + try: + open(path, "r") + except FileNotFoundError: + return False # Doesn't exist + except IsADirectoryError: + return True # Directory exists + else: + return True # File exists + + +def init(version): + """ Download font """ + path = "./src/public/fonts" + filename = "RiluRegular.ttf" + # If there is filename changes, you should change + # the name in the css file too (./src/public/styles/style.css) + + # Check if fonts directory exists + if not exist(path): + mkdir(path) + + # Download the font file if needed + if not exist(f"{path}/{filename}"): + # Download the font file + file_url = f"https://github.com/alisinisterra/rilu/releases/download/v{version}/{filename}" + data = get(file_url).content + + # Save the file + with open(f"{path}/{filename}", "wb") as file: + file.write(data) diff --git a/src/public/styles/style.css b/src/public/styles/style.css index e5a43c4..30273c8 100644 --- a/src/public/styles/style.css +++ b/src/public/styles/style.css @@ -1,3 +1,10 @@ +@font-face { + font-family: Rilu; + font-style: normal; + font-weight: normal; + src: url(../fonts/RiluRegular.ttf); +} + /* https://www.colorhexa.com/c2b280 */ @media (prefers-color-scheme: light) { :root { @@ -31,9 +38,7 @@ html { background-color: var(--bg-color); color: var(--text-color); - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, - Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, - sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + font-family: Rilu; font-size: 17px; scroll-behavior: smooth; }