mirror of
https://github.com/asimonson1125/asimonson1125.github.io.git
synced 2026-02-25 05:09:49 -06:00
quality of life improvements (both user and dev)
This commit is contained in:
14
src/app.py
14
src/app.py
@@ -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)
|
||||
@@ -34,6 +34,7 @@ body {
|
||||
background-attachment: fixed;
|
||||
background-size: 100% auto;
|
||||
background-clip: border-box;
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
* {
|
||||
|
||||
@@ -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,16 +15,17 @@ 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}) {
|
||||
function setChess({ cName = null, pic = null, ratings = null }) {
|
||||
try {
|
||||
if (cName) {
|
||||
document.querySelector(".chessName").textContent = cName;
|
||||
}
|
||||
@@ -32,9 +33,16 @@ function setChess({cName = null, pic = null, ratings = null}) {
|
||||
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;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
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
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user