obliterate

This commit is contained in:
bingus_violet 2024-07-06 22:26:22 -05:00
parent 8fff995bd0
commit 277aa94527
13 changed files with 83 additions and 259 deletions

5
api.js Normal file
View file

@ -0,0 +1,5 @@
const app = require("./exposer.js").app
app.get("/*", (req, res) => {
res.send("<h1>Sorry! Blog is undergoing large changes. Check back later!</h1><p>Like... alot later.")
})

52
exposer.js Normal file
View file

@ -0,0 +1,52 @@
const express = require("express"),
paths = require("./fileManager.js")
path = require("path"),
fs = require("fs"),
WebSocket = require("ws")
const PORT = process.env.PORT || 8080
var app = express()
app.use(express.static(paths.data))
app.listen(PORT, () => {
console.log("Violet's Limbo is now listening on port: " + PORT)
})
var sockets = []
wsServer = WebSocket.Server;
let server = require('http').createServer()
wsServer = new wsServer({
server: server,
perMessageDeflate: false
})
server.on('request', app)
wsServer.on("connection", function connection(socket) {
socket.on('message', function message(data) {
data = JSON.parse(data)
if (data.type == "ping") {
for (let index = 0; index < sockets.length; index++) {
const socketData = sockets[index];
if (socketData.socket == socket) {
sockets[index].lastPing = Date.now()
}
}
socket.send(`{"op": 3}`)
} else {
console.log(data)
}
})
sockets.push({ socket, lastPing: Date.now() })
})
module.exports = {
app: app
}
require("./api.js")

View file

@ -1,23 +0,0 @@
const express = require("express"),
paths = require("./fileManager.js"),
pageUpdater = require("./pageUpdater.js"),
path = require("path"),
fs = require("fs")
const PORT = process.env.PORT || 8080
var app = express()
app.use(express.static(paths.static))
app.get("/", (req, res) => {
res.send(pageUpdater.root())
})
app.get('/post/:post*', (req, res) => {
res.send(pageUpdater.blogPost(req))
})
app.listen(PORT, () => {
console.log("Violet's Limbo is now listening on port: " + PORT)
})

View file

@ -2,7 +2,7 @@ const express = require("express"),
fs = require("fs"), fs = require("fs"),
path = require("path") path = require("path")
require("./expressHandler.js") require("./exposer.js")
process.on('uncaughtException', (err, origin) => { process.on('uncaughtException', (err, origin) => {
fs.writeSync( fs.writeSync(

24
package-lock.json generated
View file

@ -11,7 +11,8 @@
"dependencies": { "dependencies": {
"chokidar": "^3.5.3", "chokidar": "^3.5.3",
"express": "^4.18.2", "express": "^4.18.2",
"showdown": "^2.1.0" "showdown": "^2.1.0",
"ws": "^8.18.0"
} }
}, },
"node_modules/accepts": { "node_modules/accepts": {
@ -848,6 +849,27 @@
"engines": { "engines": {
"node": ">= 0.8" "node": ">= 0.8"
} }
},
"node_modules/ws": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
} }
} }
} }

View file

@ -15,6 +15,7 @@
"dependencies": { "dependencies": {
"chokidar": "^3.5.3", "chokidar": "^3.5.3",
"express": "^4.18.2", "express": "^4.18.2",
"showdown": "^2.1.0" "showdown": "^2.1.0",
"ws": "^8.18.0"
} }
} }

View file

@ -1,66 +0,0 @@
const fs = require("fs"),
path = require("path"),
showdown = require("showdown"),
paths = require("./fileManager.js"),
mkthtml = new showdown.Converter()
mkthtml.setFlavor("github")
module.exports = {
root: () => {
var data = JSON.parse(fs.readFileSync(path.join(paths.data, 'data.json')))
var postsArray = data.posts
var html = ""
for (var i = 0; i < postsArray.length; i++) {
var addedHTML = ""
var post = postsArray[i]
addedHTML +=
`<div class="post">
<a style="text-decoration: none;" href="./post/${post.path}">
<h2>${post.name}</h2>
<p style="color: white; font-size: 1rem;">${post.desc}</p>
<p style="color: darkgray; font-size: 1rem;">Path: <code>/post/${post.path}</code></p>
</a>
</div>`
html += addedHTML
}
html = fs.readFileSync(path.join(__dirname, 'resources/mainPage.html')).toString().replace('{POSTS}', html)
return html
},
blogPost: (req) => {
var postName = req.params.post
var data = JSON.parse(fs.readFileSync(path.join(paths.data, 'data.json')))
var postsArray = data.posts
for (let index = 0; index < postsArray.length; index++) {
const post = postsArray[index];
if (post.path == postName) {
postContent = mkthtml.makeHtml(fs.readFileSync(path.join(paths.posts, post.path)).toString())
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
html = html.replace('{POST}', postContent)
html = html.replace('{POST_TITLE}', post.name)
// res.send(html)
return html
}
}
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
html = html.replace("{POST_TITLE}", "Not found!")
html = html.replace("{POST}", "<p>Couldn't find this post... Maybe try clearing your cache? Violet's Limbo is currently going through alot of backend changes, so expect things to break!</p>")
// res.send(html)
return html
}
}

View file

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Violet's Limbo</title>
<link rel="stylesheet" href="./style.css">
<style>
* {
text-align: center;
}
</style>
</head>
<body>
<h2><a href="https://violets-purgatory.dev">Home</a></h2>
<h1>Violet's Limbo</h1>
<main>
<p>Violet's Limbo is... my blog! I talk about game design, development, and whatever else comes to mind!</p>
<p>Enjoy my bad opinions!<hr></p>
<h2>Posts:</h2>
{POSTS}
</main>
</body>
</html>

View file

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Violet's Limbo</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<h2 style="text-align: center;"><a href="/">Home</a></h2>
<h1 class="title">{POST_TITLE}</h1>
<main>
<hr>
{POST}
</main>
</body>
</html>

View file

@ -1,124 +0,0 @@
@font-face {
font-display: swap;
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
src: url('../fonts/source-code-pro-v23-latin-regular.woff2') format('woff2');
}
@font-face {
font-display: swap;
font-family: 'Rubik';
font-style: normal;
font-weight: 400;
src: url('../fonts/rubik-v28-latin-regular.woff2') format('woff2');
}
@font-face {
font-display: swap;
font-family: 'Encode Sans Expanded';
font-style: normal;
font-weight: 400;
src: url('../fonts/encode-sans-expanded-v11-latin-regular.woff2') format('woff2');
}
* {
font-family: "Encode Sans Expanded", "Rubik", Verdana, Geneva, Tahoma, sans-serif;
padding: 0;
/* text-align: center; */
}
h1 {
color: rgb(0, 255, 0);
font-size: 2.5rem;
text-align: center;
}
h2 {
color: rgb(0, 255, 0);
}
li,
h3, h4, h5, h6 {
color: white;
}
h3 {
font-size: 1.5rem;
}
body,
html {
margin: auto;
background-color: rgb(10, 10, 10);
margin: 0;
padding: 0;
}
body {
padding: 2.5%;
}
main {
margin: auto;
max-width: 1000px;
}
a {
color: rgb(175, 225, 255);
display: inline-block;
transition: 1.5s all cubic-bezier(0.075, 0.82, 0.165, 1);
}
.textBlock {
color: rgb(255, 255, 255);
white-space: pre-wrap;
background-color: rgb(20, 20, 20);
border: 2px lightgray solid;
padding: 0 10px;
font-style: italic;
font-family: 'Source Code Pro', sans-serif;
text-align: center;
}
.post {
color: rgb(240, 240, 240);
background-color: rgb(5, 5, 5);
border: 2px gray solid;
padding: 10px;
padding-top: 0;
margin: 25px 10px;
text-align: center;
}
a:hover {
color: white;
transition: 0.5s all cubic-bezier(0.075, 0.82, 0.165, 1);
}
p, li {
color: white;
font-size: 1.2rem;
padding: 0;
margin: 10px;
line-height: 2rem;
}
img {
width: 100%;
max-width: 135px;
transition: all 2s cubic-bezier(0.075, 0.82, 0.165, 1);
}
hr {
color: white;
opacity: 0.25;
border-width: 2px;
margin: 15px 10%;
}
ol, ul {
display: block;
width: 80%;
margin: auto;
}