diff --git a/.nfs0000000000542e1500000001 b/.nfs0000000000542e1500000001
new file mode 100644
index 0000000..9e0ac12
Binary files /dev/null and b/.nfs0000000000542e1500000001 differ
diff --git a/README.md b/README.md
index 16d7275..778e86c 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ See the software in action: [deadvey.com](https://deadvey.com)
# Confiuration
Read the [configuation guide](CONFIG.md) for configuration help (in config.json)
-# features
+# Features
* post creation via the web frontend (no need to remote to your server to make a post)
* multi user
* powerful customisation
@@ -17,17 +17,16 @@ Read the [configuation guide](CONFIG.md) for configuration help (in config.json)
* Markdown syntax in posts
* Commenting on posts
* sign up and delete account
+* ejs
# Bugs
* probably scales like shit
* probably insecure as hell
-# planned features/todo list
+# Planned features/todo list
* custom CSS _file_
* custom strings use format indicators
* seperate functions into modules
-* builtin crypto
-* ejs
* user specific RSS feeds
* atom
* federation (looks tricky)
@@ -37,30 +36,15 @@ Read the [configuation guide](CONFIG.md) for configuration help (in config.json)
* inline comments and docs
* give each post a hard postID to prevent potential issues
* clean up code a bit
+* comment pages?
-# format indicators
-* %% - 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
-* %J - URL delete account
-* %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
-* %Q - URL to sign up
-* %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
+TODO (not finished)
+# EJS variable names
+* config.variable_name - pass any variable in config.json
+* hitcount - value in hitcount.txt (a single number)
+## Posts (/views/posts/)
+* post - an object that includes the data for that post, eg post.title, post.content etc
+* user - the object of the user who posted this
+* index - an int that refers to the index of the current post
+## Comments (/views/partials/comment.ejs)
+* comment - an object storing the comment, eg comment.name, comment.content
diff --git a/app.js b/app.js
index 36fc436..4006924 100755
--- a/app.js
+++ b/app.js
@@ -6,8 +6,10 @@ const crypto = require('crypto'); // For encrypting passwords, I use sha512
// fromUnixTime(): Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
// format(): Return the formatted date string in the given format. The result may vary by locale.
// getUnixTime(): Get the seconds timestamp of the given date.
-// find out more at https://date-fns.org/ \or docs: https://date-fns.org/docs/Getting-Startedyyyyyyyy
+// find out more at https://date-fns.org/ \or docs: https://date-fns.org/docs/Getting-Started
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
+const ejs = require("ejs")
+const func = require("./functions.js")
// There's only one possible argument, so we can just check if the user passed that one
// TODO I plan on adding more such as --help and --post so I should make this more robust at some point
@@ -20,6 +22,7 @@ let users // contains a list of users, each user is an object containing usernam
let posts // contains a list of posts,
let comments // contains a list of comments
let config // contains a set of configuration for the site, see example-config.js for an example
+let ejs_templates
try {
// We're going to try and import the modules,
@@ -27,6 +30,7 @@ try {
posts = require('./posts.json');
comments = require('./comments.json');
config = require('./config.json');
+ ejs_templates = require("./ejs-templates.js")
}
catch (error) {
// if they don't all import then
@@ -56,6 +60,9 @@ const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static(config.root_path));
+// set the view engine to ejs
+app.set('view engine', 'ejs');
+
// Initialise the program by creating users.js, comments.js, posts.js and config.js
// All require default content in them to start off with
// Then exit successfully
@@ -110,16 +117,6 @@ function get_userID(username) {
return -1 // If user is not present, return -1
}
-// The configuration defines a date format using the date-fns (a datetime library) syntax
-// eg "yyyy-MM-dd"
-// this converts unix time (an integer) into a string that is formatted according to config.js
-// uses date-fns's fromUnixTime() and format() functions
-// returns the formatted date (string)
-function unix_time_to_date_format(unix_time) {
- date = fromUnixTime(unix_time)
- formatted_date = format(date, config.date_format)
- return formatted_date
-}
// This is similar to the above function, however, instead of formatting to the users
// configuration, it formats to RFC-822 which is the date format used by RSS feeds
@@ -173,8 +170,8 @@ function replace_format_indicators(template, post_index=-1, tag_name="tag", user
.replaceAll("%A", (post_object["tags"]))
.replaceAll("%B", (hyperlink_tags(post_object["tags"])))
.replaceAll("%C", converter.makeHtml(post_object["content"]))
- .replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
- .replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
+ //.replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
+ //.replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
.replaceAll("%F", users[post_object["userID"]]['prettyname'])
.replaceAll("%G", tag_name)
.replaceAll("%I", converter.makeHtml(users[post_object['userID']]['description']))
@@ -235,13 +232,13 @@ function return_comments(post_id) {
.replaceAll(/>> ([0-9]*)/g, ">> $1")
.replaceAll(/>> ([0-9]*)/g, ">> $1")
.replaceAll("\n", "
")
- comment_content += `