mirror of
https://github.com/asimonson1125/asimonson1125.github.io.git
synced 2026-02-25 05:09:49 -06:00
replace sockets with api
This commit is contained in:
13
src/app.py
13
src/app.py
@@ -10,21 +10,21 @@ pages = {
|
|||||||
"template": "home.html",
|
"template": "home.html",
|
||||||
"title": "Andrew Simonson - Portfolio Home",
|
"title": "Andrew Simonson - Portfolio Home",
|
||||||
"description": "Andrew Simonson's Digital Portfolio home",
|
"description": "Andrew Simonson's Digital Portfolio home",
|
||||||
"canonical": "",
|
"canonical": "/",
|
||||||
},
|
},
|
||||||
"projects": {
|
"projects": {
|
||||||
"template": "projects.html",
|
"template": "projects.html",
|
||||||
"projects": proj,
|
"projects": proj,
|
||||||
"title": "Andrew Simonson - Projects",
|
"title": "Andrew Simonson - Projects",
|
||||||
"description": "Recent projects by Andrew Simonson on his lovely portfolio website :)",
|
"description": "Recent projects by Andrew Simonson on his lovely portfolio website :)",
|
||||||
"canonical": "projects",
|
"canonical": "/projects",
|
||||||
},
|
},
|
||||||
"about": {
|
"about": {
|
||||||
"template": "about.html",
|
"template": "about.html",
|
||||||
"timeline": timeline,
|
"timeline": timeline,
|
||||||
"title": "Andrew Simonson - About Me",
|
"title": "Andrew Simonson - About Me",
|
||||||
"description": "About Andrew Simonson",
|
"description": "About Andrew Simonson",
|
||||||
"canonical": "about",
|
"canonical": "/about",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,13 +33,10 @@ Minify(app=app, html=True, js=True, cssless=True)
|
|||||||
socketio = SocketIO(app)
|
socketio = SocketIO(app)
|
||||||
|
|
||||||
|
|
||||||
@socketio.on("goto")
|
@app.route('/api/goto/<location>')
|
||||||
def goto(location):
|
def goto(location):
|
||||||
sid = flask.request.sid
|
|
||||||
pagevars = pages[location]
|
pagevars = pages[location]
|
||||||
output = [location, flask.render_template(pagevars["template"], var=pagevars), pagevars['title']]
|
return [pagevars, flask.render_template(pagevars["template"], var=pagevars)]
|
||||||
socketio.emit("goto", output, to=sid)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
|
|||||||
@@ -88,25 +88,22 @@ function toggleMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let socket = io();
|
const loc = "https://asimonson.com"
|
||||||
|
|
||||||
function emit(event) {
|
async function goto(location) {
|
||||||
socket.emit(event);
|
let a = await fetch(loc + "/api/goto/" + location, {
|
||||||
}
|
credentials: "include",
|
||||||
|
method: "GET",
|
||||||
function emitData(event, data) {
|
mode: "cors",
|
||||||
socket.emit(event, data)
|
});
|
||||||
}
|
const response = await a.json();
|
||||||
|
const metadata = response[0];
|
||||||
socket.on('goto', (page) => {
|
const content = response[1];
|
||||||
pagename = page[0];
|
let root = document.getElementById("root");
|
||||||
content = page[1];
|
|
||||||
let root = document.getElementById('root');
|
|
||||||
root.innerHTML = content;
|
root.innerHTML = content;
|
||||||
root.querySelectorAll("script").forEach(x => {
|
root.querySelectorAll("script").forEach((x) => {
|
||||||
eval(x.innerHTML);
|
eval(x.innerHTML);
|
||||||
});
|
});
|
||||||
document.querySelector('title').textContent = page[2];
|
document.querySelector("title").textContent = metadata['title'];
|
||||||
if (pagename == 'home') pagename = '/';
|
history.pushState(null, null, metadata['canonical']);
|
||||||
history.pushState(null, null, pagename);
|
}
|
||||||
});
|
|
||||||
|
|||||||
@@ -52,9 +52,8 @@
|
|||||||
href="{{ url_for('static', filename='css/head.css') }}"
|
href="{{ url_for('static', filename='css/head.css') }}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<link rel="canonical" href="https://asimonson.com/{{ var['canonical'] }}" />
|
<link rel="canonical" href="https://asimonson.com{{ var['canonical'] }}" />
|
||||||
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js" integrity="sha512-eVL5Lb9al9FzgR63gDs1MxcDS2wFu3loYAgjIH0+Hg38tCS8Ag62dwKyH+wzDb+QauDpEZjXbMn11blw8cbTJQ==" crossorigin="anonymous"></script>
|
|
||||||
<script src="{{ url_for('static', filename='js/idler.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/idler.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/checkbox.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/checkbox.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/responsive.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/responsive.js') }}"></script>
|
||||||
@@ -67,7 +66,7 @@
|
|||||||
<div class="App">
|
<div class="App">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
|
||||||
<div id="name-container" onclick="emitData('goto', 'home')">
|
<div id="name-container" onclick="goto('home')">
|
||||||
<div class="glitch">
|
<div class="glitch">
|
||||||
{% for i in range(9) %}
|
{% for i in range(9) %}
|
||||||
<div class="line name">
|
<div class="line name">
|
||||||
@@ -86,17 +85,17 @@
|
|||||||
<div class="navControl">
|
<div class="navControl">
|
||||||
<div class="navBar">
|
<div class="navBar">
|
||||||
<div class="navElement">
|
<div class="navElement">
|
||||||
<p onclick="emitData('goto', 'home')">Home</p>
|
<p onclick="goto('home')">Home</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="navElement">
|
<div class="navElement">
|
||||||
<a href="Resume.pdf" target="_blank"> Resume </a>
|
<a href="Resume.pdf" target="_blank"> Resume </a>
|
||||||
</div>
|
</div>
|
||||||
<div class="navElement">
|
<div class="navElement">
|
||||||
<p onclick="emitData('goto', 'projects')">Projects</p>
|
<p onclick="goto('projects')">Projects</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- <a href="/activities">Activities</a> -->
|
<!-- <a href="/activities">Activities</a> -->
|
||||||
<div class="navElement">
|
<div class="navElement">
|
||||||
<p onclick="emitData('goto', 'about')">About Me</p>
|
<p onclick="goto('about')">About Me</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user