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

View File

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

View File

@@ -4,7 +4,7 @@ async function addChessEmbed(username) {
user = await fetch(`https://api.chess.com/pub/player/${username}`);
stats = await fetch(`https://api.chess.com/pub/player/${username}/stats`);
} catch (e) {
setChess({cName:"Chess.com request failed"});
setChess({ cName: "Chess.com request failed" });
return;
}
if (user.status === 200) {
@@ -15,26 +15,34 @@ async function addChessEmbed(username) {
blitz: stats.chess_blitz.last.rating,
bullet: stats.chess_bullet.last.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) {
chessSet({cName:"Chess.com request failed"});
setChess({ cName: "Chess.com request failed" });
} else {
chessSet({cName:"User Not Found"});
setChess({ cName: "User Not Found" });
}
}
function setChess({cName = null, pic = null, ratings = null}) {
if (cName) {
document.querySelector(".chessName").textContent = cName;
}
if (pic) {
document.querySelector(".chessImage").src = pic;
}
if (ratings) {
document.querySelector(".chessRapid .chessStat").textContent = ratings.rapid;
document.querySelector(".chessBlitz .chessStat").textContent = ratings.blitz;
document.querySelector(".chessBullet .chessStat").textContent = ratings.bullet;
document.querySelector(".chessPuzzles .chessStat").textContent = ratings.tactics;
function setChess({ cName = null, pic = null, ratings = null }) {
try {
if (cName) {
document.querySelector(".chessName").textContent = cName;
}
if (pic) {
document.querySelector(".chessImage").src = pic;
}
if (ratings) {
document.querySelector(".chessRapid .chessStat").textContent =
ratings.rapid;
document.querySelector(".chessBlitz .chessStat").textContent =
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 = 'http://127.0.0.1:5000'
async function goto(location) {
async function goto(location, push=true) {
let a = await fetch(loc + "/api/goto/" + location, {
credentials: "include",
method: "GET",
@@ -105,5 +106,12 @@ async function goto(location) {
eval(x.innerHTML);
});
document.querySelector("title").textContent = metadata['title'];
history.pushState(null, null, metadata['canonical']);
if(push){
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>
</head>
<body>
<body onpopstate="backButton()">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div class="App">
<div class="header">