Skip to content

Commit

Permalink
refactor: More minor cleanup, including comments
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Dec 26, 2024
1 parent 64c70f2 commit 98075ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/randomization.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pkg from './routes.mjs';
import { existsSync, readFileSync } from 'fs';
import { fileURLToPath } from 'node:url';
export { config, paintSource, randomizeGlobal, preloaded404, tryReadFile };
const {
cookingInserts,
Expand Down Expand Up @@ -82,7 +81,7 @@ const config = Object.freeze(
preloaded404 = paintSource(text404),
// Grab the text content of a file. Ensure the file is a string.
tryReadFile = (file, baseUrl) => {
file = fileURLToPath(new URL(file, baseUrl));
file = new URL(file, baseUrl);
return existsSync(file + '')
? readFileSync(
file + '',
Expand Down
28 changes: 12 additions & 16 deletions src/routes.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import { readFileSync } from 'fs';
import path from 'path';
import { readFile } from 'fs/promises';

const insert = JSON.parse(
await readFile(new URL('./data.json', import.meta.url))
);

const __dirname = path.resolve();

const text404 = readFileSync(
path.normalize(__dirname + '/views/error.html'),
'utf8'
);

const pages = {
/* If you are trying to add pages or assets in the root folder and
NOT entire folders check src/routes.mjs and add it manually. */

// If you are trying to add pages or assets in the root folder and
// NOT entire folders, check the routes below and add it manually.
index: 'index.html',
'manifest.json': 'manifest.json',

// This route for the error page is also used to define text404 down below.
'test-404': 'error.html',
/* Main */
documentation: 'docs.html',
Expand Down Expand Up @@ -70,6 +58,14 @@ const externalPages = {
'rammerhead-discord': 'https://discord.gg/VNT4E7gN5Y',
};

const insert = JSON.parse(
readFileSync(new URL('./data.json', import.meta.url))
),
text404 = readFileSync(
new URL('../views/' + pages['test-404'], import.meta.url),
'utf8'
);

const cookingInserts = insert.content,
vegetables = insert.keywords,
charRandom = insert.chars,
Expand Down
14 changes: 5 additions & 9 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
import fastifyHelmet from '@fastify/helmet';
import fastifyStatic from '@fastify/static';
import pageRoutes from './routes.mjs';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import {
config,
paintSource,
Expand Down Expand Up @@ -165,7 +163,7 @@ app.register(fastifyStatic, {
decorateReply: false,
});

// NEVER commit roms due to piracy concerns
// You should NEVER commit roms, due to piracy concerns.
app.register(fastifyStatic, {
root: fileURLToPath(
new URL('../views/archive/gfiles/rarch/roms', import.meta.url)
Expand Down Expand Up @@ -215,8 +213,6 @@ app.register(fastifyStatic, {
decorateReply: false,
});

// This combines scripts from the official scramjet repository with local scramjet scripts into
// one directory path. Local versions of files override the official versions.
app.register(fastifyStatic, {
root: fileURLToPath(
new URL(
Expand Down Expand Up @@ -254,10 +250,10 @@ app.register(fastifyStatic, {
decorateReply: false,
});

/* If you are trying to add pages or assets in the root folder and
NOT entire folders check src/routes.mjs and add it manually. */

/* All website files are stored in the /views directory.
/* If you are trying to add pages or assets in the root folder and
* NOT entire folders, check ./src/routes.mjs and add it manually.
*
* All website files are stored in the /views directory.
* This takes one of those files and displays it for a site visitor.
* Paths like /browsing are converted into paths like /views/pages/surf.html
* back here. Which path converts to what is defined in routes.mjs.
Expand Down
2 changes: 1 addition & 1 deletion views/assets/js/common-1735118314.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ addEventListener('DOMContentLoaded', async () => {
if (prUrl)
prUrl.addEventListener('keydown', async (e) => {
if (e.code === 'Enter') goProxMethod(searchMode)();
// This is exclusively used for the validator script.
// This is exclusively used for the validator script.
else if (e.code === 'Validator Test') {
e.target.value = await goProx[type](e.target.value);
e.target.dispatchEvent(new Event('change'));
Expand Down

0 comments on commit 98075ba

Please sign in to comment.