quality of life improvements (both user and dev)

This commit is contained in:
2023-02-01 21:15:33 -06:00
parent b04dc0504f
commit 3474891c2c
5 changed files with 44 additions and 27 deletions

View File

@@ -1,6 +1,5 @@
import flask import flask
from flask_minify import Minify from flask_minify import Minify
from flask_socketio import SocketIO
import json import json
proj = json.load(open("./static/json/projects.json", "r")) proj = json.load(open("./static/json/projects.json", "r"))
@@ -29,12 +28,11 @@ pages = {
} }
app = flask.Flask(__name__) app = flask.Flask(__name__)
Minify(app=app, html=True, js=True, cssless=True)
socketio = SocketIO(app)
@app.route('/api/goto/')
@app.route('/api/goto/<location>') @app.route('/api/goto/<location>')
def goto(location): def goto(location='home'):
pagevars = pages[location] pagevars = pages[location]
return [pagevars, flask.render_template(pagevars["template"], var=pagevars)] return [pagevars, flask.render_template(pagevars["template"], var=pagevars)]
@@ -94,7 +92,9 @@ def static_from_root():
if __name__ == "__main__": if __name__ == "__main__":
import sass # import sass
sass.compile(dirname=("static/scss", "static/css"), output_style="compressed") # sass.compile(dirname=("static/scss", "static/css"), output_style="compressed")
socketio.run(app) app.run()
else:
Minify(app=app, html=True, js=True, cssless=True)

View File

@@ -34,6 +34,7 @@ body {
background-attachment: fixed; background-attachment: fixed;
background-size: 100% auto; background-size: 100% auto;
background-clip: border-box; background-clip: border-box;
background-color: #1a1a1a;
} }
* { * {

View File

@@ -15,16 +15,17 @@ async function addChessEmbed(username) {
blitz: stats.chess_blitz.last.rating, blitz: stats.chess_blitz.last.rating,
bullet: stats.chess_bullet.last.rating, bullet: stats.chess_bullet.last.rating,
tactics: stats.tactics.highest.rating, tactics: stats.tactics.highest.rating,
} };
setChess({ cName: user["username"], pic: user.avatar, ratings: ratings }); setChess({ cName: user["username"], pic: user.avatar, ratings: ratings });
} else if (user === null || user.status === 403 || user.status === null) { } else if (user === null || user.status === 403 || user.status === null) {
chessSet({cName:"Chess.com request failed"}); setChess({ cName: "Chess.com request failed" });
} else { } else {
chessSet({cName:"User Not Found"}); setChess({ cName: "User Not Found" });
} }
} }
function setChess({ cName = null, pic = null, ratings = null }) { function setChess({ cName = null, pic = null, ratings = null }) {
try {
if (cName) { if (cName) {
document.querySelector(".chessName").textContent = cName; document.querySelector(".chessName").textContent = cName;
} }
@@ -32,9 +33,16 @@ function setChess({cName = null, pic = null, ratings = null}) {
document.querySelector(".chessImage").src = pic; document.querySelector(".chessImage").src = pic;
} }
if (ratings) { if (ratings) {
document.querySelector(".chessRapid .chessStat").textContent = ratings.rapid; document.querySelector(".chessRapid .chessStat").textContent =
document.querySelector(".chessBlitz .chessStat").textContent = ratings.blitz; ratings.rapid;
document.querySelector(".chessBullet .chessStat").textContent = ratings.bullet; document.querySelector(".chessBlitz .chessStat").textContent =
document.querySelector(".chessPuzzles .chessStat").textContent = ratings.tactics; ratings.blitz;
document.querySelector(".chessBullet .chessStat").textContent =
ratings.bullet;
document.querySelector(".chessPuzzles .chessStat").textContent =
ratings.tactics;
}
} catch {
console.log("fucker clicking so fast the internet can't even keep up");
} }
} }

View File

@@ -89,8 +89,9 @@ function toggleMenu() {
} }
const loc = "https://asimonson.com" const loc = "https://asimonson.com"
// const loc = 'http://127.0.0.1:5000'
async function goto(location) { async function goto(location, push=true) {
let a = await fetch(loc + "/api/goto/" + location, { let a = await fetch(loc + "/api/goto/" + location, {
credentials: "include", credentials: "include",
method: "GET", method: "GET",
@@ -105,5 +106,12 @@ async function goto(location) {
eval(x.innerHTML); eval(x.innerHTML);
}); });
document.querySelector("title").textContent = metadata['title']; document.querySelector("title").textContent = metadata['title'];
if(push){
history.pushState(null, null, metadata['canonical']); history.pushState(null, null, metadata['canonical']);
} }
}
function backButton() {
const location = window.location.pathname;
goto(location.substring(1), push=false); // remove slash, goto already does that
}

View File

@@ -61,7 +61,7 @@
<title>{{ var['title'] }}</title> <title>{{ var['title'] }}</title>
</head> </head>
<body> <body onpopstate="backButton()">
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div class="App"> <div class="App">
<div class="header"> <div class="header">