use custom font
This commit is contained in:
parent
52eefa98fa
commit
03122a8617
5 changed files with 53 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,3 +4,5 @@ lib64
|
||||||
pyvenv.cfg
|
pyvenv.cfg
|
||||||
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
||||||
|
src/public/fonts/
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
Flask==2.2.2
|
Flask==2.2.2
|
||||||
|
requests==2.28.1
|
||||||
|
|
13
src/app.py
13
src/app.py
|
@ -1,18 +1,15 @@
|
||||||
from routes.index import router as index
|
|
||||||
from flask import Flask, redirect
|
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 = Flask(__name__, static_url_path="/", static_folder="public")
|
||||||
app.register_blueprint(index, url_prefix="/index")
|
app.register_blueprint(index, url_prefix="/index")
|
||||||
|
|
||||||
|
init_font("1.3.0")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
return redirect("index")
|
return redirect("index")
|
||||||
|
|
||||||
|
|
||||||
class AttributeDict(dict):
|
|
||||||
def __getattr__(self, name):
|
|
||||||
if name in self:
|
|
||||||
return self[name]
|
|
||||||
raise AttributeError(name)
|
|
||||||
|
|
37
src/font.py
Normal file
37
src/font.py
Normal file
|
@ -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)
|
|
@ -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 */
|
/* https://www.colorhexa.com/c2b280 */
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
:root {
|
:root {
|
||||||
|
@ -31,9 +38,7 @@
|
||||||
html {
|
html {
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
|
font-family: Rilu;
|
||||||
Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial,
|
|
||||||
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue