From f2f244eb9dec074bcea06c8353639af75231aebd Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 13 Jul 2025 00:21:53 +0100 Subject: [PATCH] better first time xp --- app.js | 64 ++++++++++++++++++++++++---- config.js | 6 ++- example-config.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++ hitcount.txt | 2 +- 4 files changed, 168 insertions(+), 9 deletions(-) create mode 100755 example-config.js diff --git a/app.js b/app.js index bab5527..dc4b8dc 100755 --- a/app.js +++ b/app.js @@ -1,23 +1,73 @@ +const fs = require('fs'); +if (process.argv[0] == "--first-time") { + initialise() +} + const express = require('express'); const showdown = require('showdown') const crypto = require('crypto'); // For encrypting passwords const { fromUnixTime, format, getUnixTime } = require("date-fns") -const fs = require('fs'); -const users = require('./users.js'); -const posts = require('./posts.js'); -const comments = require('./comments.js'); -const config = require('./config.js'); -let converter = new showdown.Converter({simpleLineBreaks: true, tables: true, strikethrough: true, tasklists: true, encodeEmails: true}) +let users +let posts +let comments +let config + +try { + users = require('./users.js'); + posts = require('./posts.js'); + comments = require('./comments.js'); + config = require('./config.js'); +} +catch (error) { + console.log("A file is missing!") + console.log("Run with --first-time to initialise the program") + console.log("Error output:\n", error) + process.exit(1) +} +let converter = new showdown.Converter({ + simpleLineBreaks: true, + tables: true, + strikethrough: true, + tasklists: true, + encodeEmails: true +}) const app = express(); + let footer_div = config.site_wide_footer footer_div = replace_format_indicators(footer_div) - app.use(express.urlencoded({ extended: true })); app.use(express.json()); app.use(express.static(config.root_path)); +function initialise() { + try { + const users = require("./users.js"); + } + catch (error) { + fs.writeFileSync(`${__dirname}/users.js`, `export const users = []`) + } + try { + const posts = require("./posts.js"); + } + catch (error) { + fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = []`) + } + try { + const users = require("./comments.js"); + } + catch (error) { + fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = []\nexport const counter = 0`) + } + try { + const users = require("./config.js"); + } + catch (error) { + fs.copyFile('example-config.js', 'config.js') + } +} + function get_userID(username) { for (let i = 0; i < users.users.length; i++) { if (users.users[i]['username'] == username) { diff --git a/config.js b/config.js index 71e2f6d..35531ba 100755 --- a/config.js +++ b/config.js @@ -43,9 +43,9 @@ export const time_zone = "+0000" // %S - post seperator as defined by post_seperator // %T - Title // %U - URL the the user (poster) +// %W - Site Description as defined by site_description // %X - Comment submission box // %Y - Site Name as defined by site_name -// %W - Site Description as defined by site_description // %Z - Attribution (to me) and source code link and license export const timeline_header = `

%Y

@@ -63,6 +63,8 @@ export const user_post_format = `

%T

%C

%B
Permalink
+%X +%M %S` export const post_page_format = `

%T

%C

@@ -79,6 +81,8 @@ export const timeline_post_format = `

%T

%C

Permalink
By %N +%X +%M %S` export const tag_post_format = `

%T

%C

diff --git a/example-config.js b/example-config.js new file mode 100755 index 0000000..d385c33 --- /dev/null +++ b/example-config.js @@ -0,0 +1,105 @@ +export const seperator = "
" +export const site_name = "My Blog" +export const site_url = "https://example.com" +export const port = 8080 +export const site_description = "Read my blogs!" +export const timeline_length = 20 +export const enable_hitcount = true // Can slow down page loading a bit +export const charset = "UTF-8" // Don't change unless you know why + +// Anything in this directory will be in the webroot, so put favicon.ico and anything else here. +export const root_path = "/path/to/root/of/website" + +// Default username if no username is inputted in comment submission +export const default_username = "Anon" + +// RSS feeds +export const rss = true +export const rss_path = "/rss" + +// Dates +// https://date-fns.org/v4.1.0/docs/format +export const date_format = "yyyy-MM-dd" +export const time_zone = "+0000" + +//// Format ///// +// The syntax for this is pretty simple +// %% - A literal % +// %A - List of tags +// %B - List of tags, each one with a hyperlink to that tag page +// %C - Post content +// %D - Published date in the format specified by date_format +// %E - Edited date in the format specified by date_format +// %F - Pretty name +// %G - Tag name (used for the tag page only) +// %H - Frontpage hit count +// %I - User description +// %L - URL Permanent link to the post +// %M - comments +// %N - the username of the user (poster) +// %P - URL to create a new post +// %O - URL to edit this post +// %R - Site wide RSS feed +// %S - post seperator as defined by post_seperator +// %T - Title +// %U - URL the the user (poster) +// %W - Site Description as defined by site_description +// %X - Comment submission box +// %Y - Site Name as defined by site_name +// %Z - Attribution (to me) and source code link and license + +export const timeline_header = `

%Y

+

%W

+Create Post
+RSS Feed
+Hit count: %H +%S` +export const user_page_header = `

%F's posts:

+%I +%S` +export const tag_page_header = `

Posts tagged: %G

%S` +// --------------------------------------------- +export const user_post_format = `

%T

+

%C

+%B
+Permalink
+%X +%M +%S` +export const post_page_format = `

%T

+

%C

+%B
+By %N
+Edit Post
+Posted: %D
+Edited: %E +%S +%X +%M +%S` +export const timeline_post_format = `

%T

+

%C

+Permalink
+By %N +%X +%M +%S` +export const tag_post_format = `

%T

+

%C

+%B
+Permalink
+By %N +%S` +// ------------------------------------- +export const site_wide_footer = `Site is ran by DeaDvey
+%Z` + + +/// Custom CSS to be applied to every page +export const css = ` +/* Put you custom CSS here, +Read about existing classes and ID's in the docs (coming soon)*\ +` + +// pretty please don't change this +export const attribution = "Powered by blogger-nodejs: Source Code, license (WTFPL)" diff --git a/hitcount.txt b/hitcount.txt index b3b2268..eaea6f5 100644 --- a/hitcount.txt +++ b/hitcount.txt @@ -1 +1 @@ -228 \ No newline at end of file +240 \ No newline at end of file