diff --git a/README.md b/README.md index df25d0b..be47566 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,4 @@ See [docs/DOCUMENTATION.md](docs/DOCUMENTATION.md) # Customisation: Customisation of settings can be done via the config.json file (use example-config.json as an example) and see [the configuration guide](docs/CONFIG.md)
Additionaly, more complex configuration of the precise template of the whole site, can be done via [EJS](https://ejs.co/) (in /views) (see [the list of things variables and functions available in EJS](docs/EJS.md) (you will need to understand EJS syntax and JavaScript, to customise this (why did I use EJS? well I originally had this weird system of format indicators with percent (%) signs and stuff (like in unix's date (`date`)) but then I was told EJS is better and it sure is, though it is a bit harder to understand but MUCH more powerful!)) +Also, if you want to change any of the strings on the website, please modify or create a new, customised locale in /locales diff --git a/docs/CLASSES_AND_IDS.md b/docs/CLASSES_AND_IDS.md new file mode 100644 index 0000000..ce1aff7 --- /dev/null +++ b/docs/CLASSES_AND_IDS.md @@ -0,0 +1,4 @@ +Post: + +![images/post-css.png](An image showing the css id's assosciated with each part of a post) + diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index c40ef43..42c80d0 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -1,4 +1,5 @@ # Installation +This program is currently just ran manually.
All you need to do is clone the git repository:
```git clone https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs.git```
Then navigate to /src:
@@ -8,4 +9,4 @@ Then run the initialisation function:
Then you should modify config.json in / to suit your needs.
# Running I would reccomend running the program in tmux so it does not stop running when you close the terminal window.
-I might add support for running in the background later. +• There is currently no init system support. I might add this later (or you could open a PR). diff --git a/docs/images/post-css.png b/docs/images/post-css.png new file mode 100644 index 0000000..aeda7cb Binary files /dev/null and b/docs/images/post-css.png differ diff --git a/locales/en-GB.json b/locales/en-GB.json index 58967b8..a0cf65f 100644 --- a/locales/en-GB.json +++ b/locales/en-GB.json @@ -25,6 +25,7 @@ "rss_feed": "RSS Feed", "atom_feed": "ATOM Feed", + "no_tags": "No Tags", "new_post": "New Post", "edit_post": "Edit Post", "sign_up": "Sign Up", diff --git a/locales/en-US.json b/locales/en-US.json index fc596f2..3b735f2 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -25,6 +25,7 @@ "rss_feed": "RSS Feed", "atom_feed": "ATOM Feed", + "no_tags": "No Tags", "new_post": "New Post", "edit_post": "Edit Post", "sign_up": "Sign Up", diff --git a/package.json b/package.json index 1bec8f3..43ccbaa 100755 --- a/package.json +++ b/package.json @@ -1,4 +1,9 @@ { + "name": "blogger-nodejs", + "version": "0.0.5", + "description": "Simple web logging backend", + "author": "DeaDvey", + "license": "WTFPL", "dependencies": { "date-fns": "^4.1.0", "ejs": "^3.1.10", diff --git a/src/functions.js b/src/functions.js index 1d91eb2..f86bff1 100644 --- a/src/functions.js +++ b/src/functions.js @@ -1,5 +1,7 @@ import { createRequire } from 'module'; const require = createRequire(import.meta.url) +const config = require("../config.json") +const locale = require(`../locales/${config.locale}.json`) // The configuration defines a date format using the date-fns (a datetime library) syntax // eg "yyyy-MM-dd" @@ -8,7 +10,6 @@ const require = createRequire(import.meta.url) // returns the formatted date (string) export function unix_time_to_date_format(unix_time) { const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library - const config = require("../config.json") let date = fromUnixTime(unix_time) let formatted_date = format(date, config.date_format) return formatted_date @@ -20,7 +21,6 @@ export function unix_time_to_date_format(unix_time) { // returns the formatted date (string) export function unix_time_to_rss_date(unix_time) { const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library - const config = require("../config.json") let date = fromUnixTime(unix_time) let formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss") return `${formatted_date} ${config.time_zone}` @@ -37,14 +37,19 @@ export function unix_time_to_atom_date(unix_time) { // eg "string1, string2, string3" // this is so you can have a list of tags that each point to their individual tag page // returns: string -export function hyperlink_tags(tags) { +export function render_tags(tags) { let string = "" // Initialises the string - for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag - string += `${tags[tag_index]}` // Adds the tag to the string as a HTML href - if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma - string += ", "; - } - } + if (tags.length == 1 && tags[0] == "") { + string = locale.no_tags; // If there are no tags, output something + } + else { + for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag + string += `${tags[tag_index]}` // Adds the tag to the string as a HTML href + if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma + string += ", "; + } + } + } return string } // The users are stored as a list of objects [ user_object, user_object, user_object ] @@ -101,8 +106,6 @@ export function render_comment(comment_content) { }; export function render_md(content) { const markdownit = require("markdown-it") - const config = require("../config.json") - const locale = require(`../locales/${config.locale}.json`) const md = markdownit({ html: false, xhtmlOut: false, diff --git a/views/pages/tag.ejs b/views/pages/tag.ejs index 849f76c..38d81c7 100644 --- a/views/pages/tag.ejs +++ b/views/pages/tag.ejs @@ -13,7 +13,7 @@ <% if ( posts[index].deleted != true) { %> <% posts[index].tags.forEach((current_tag, tag_index) => { %> <% if (current_tag == tag) { %> - <%- include('../posts/tag', {post: posts[index], postID: index}); %> + <%- include('../posts/tag', {post: posts[index], user: users[posts[index].userID], comments: comments[index]}); %> <% } %> <% }) %> <% } %> diff --git a/views/pages/timeline.ejs b/views/pages/timeline.ejs index 15e3062..30b9922 100644 --- a/views/pages/timeline.ejs +++ b/views/pages/timeline.ejs @@ -18,7 +18,7 @@
<% for (let index = posts.length - 1; index >= 0; index--) { %> <% if (posts[index]["deleted"] != true) { %> - <%- include('../posts/timeline', {post: posts[index], postID: index, user: users[posts[index].userID]}); %> + <%- include('../posts/timeline', {post: posts[index], postID: index, user: users[posts[index].userID], comments: comments[index]}); %> <% } %> <% } %>
diff --git a/views/pages/user.ejs b/views/pages/user.ejs index 08eebd1..3fd4875 100644 --- a/views/pages/user.ejs +++ b/views/pages/user.ejs @@ -11,7 +11,7 @@
<% for (let index = posts.length - 1; index >= 0; index--) { %> <% if (posts[index].userID == userID) { %> - <%- include('../posts/user', {post: posts[index], postID: index, user: user}); %> + <%- include('../posts/user', {post: posts[index], postID: index, user: user, comments: comments[index]}); %> <% } %> <% } %>
diff --git a/views/posts/post.ejs b/views/posts/post.ejs index ec2aeb6..8ae3d41 100644 --- a/views/posts/post.ejs +++ b/views/posts/post.ejs @@ -1,28 +1,48 @@ -

- <%= post.title %> -

-<%- func.render_md(post.content) %>
- - <%= locale.written_by %> <%= user.username %>
-
-<%- func.hyperlink_tags(post.tags) %>
-<%= locale.edit_post %>
-<%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %>
-<%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
- -<%- config.seperator %> - - -
- -


-

- -
- -<% comments.forEach((comment, postID) => { %> - <%- include('../partials/comment', {comment: comment}) %> -<% }) %> +
+

+ <%= post.title %> +

+
+
+

+ <%- func.render_md(post.content) %>
+

+
+
+
+ <%= locale.written_by %> <%= user.username %>
+
+
+ <%- func.render_tags(post.tags) %>
+
+
+ "><%= locale.edit_post %>
+
+
+ <%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
+ <%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
+ +
+ +
+ "> +


+

+ +
+
+ +
+ <% comments.forEach((comment, index) => { %> +
+ <%- include('../partials/comment', {comment: comment}) %> +
+ <% }) %> +
<%- config.seperator %> diff --git a/views/posts/tag.ejs b/views/posts/tag.ejs index b7fd07e..d68087e 100644 --- a/views/posts/tag.ejs +++ b/views/posts/tag.ejs @@ -1,23 +1,51 @@ -

- <%= post.title %> -

-<%- func.render_md(post.content) %>
-<%= locale.edit_post %>
-<%= locale.permalink %>
-<%- func.hyperlink_tags(post.tags) %> -
+
+

+ <%= post.title %> +

+
+
+

+ <%- func.render_md(post.content) %>
+

+
+
+
+ <%= locale.written_by %> <%= user.username %>
+
+
+ "><%= locale.permalink %> +
+
+ <%- func.render_tags(post.tags) %>
+
+
+ "><%= locale.edit_post %>
+
+
+ <%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
+ <%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
- -
- -


-

- -
+
+ +
+ "> +


+

+ +
+
-<% comments[postID].forEach((comment) => { %> - <%- include('../partials/comment', {comment: comment}) %> -<% }) %> +
+ <% comments.forEach((comment, index) => { %> +
+ <%- include('../partials/comment', {comment: comment}) %> +
+ <% }) %> +
<%- config.seperator %> diff --git a/views/posts/timeline.ejs b/views/posts/timeline.ejs index 251c25a..d68087e 100644 --- a/views/posts/timeline.ejs +++ b/views/posts/timeline.ejs @@ -1,25 +1,51 @@ -

- <%= post.title %> -

-<%- func.render_md(post.content) %>
-<%= locale.edit_post %>
-<%= locale.permalink %>
- - <%= locale.written_by %> <%= user.username %>
-
-
+
+

+ <%= post.title %> +

+
+
+

+ <%- func.render_md(post.content) %>
+

+
+
+
+ <%= locale.written_by %> <%= user.username %>
+
+
+ "><%= locale.permalink %> +
+
+ <%- func.render_tags(post.tags) %>
+
+
+ "><%= locale.edit_post %>
+
+
+ <%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
+ <%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
- -
- -


-

- -
+
+ +
+ "> +


+

+ +
+
-<% comments[postID].forEach((comment, postID) => { %> - <%- include('../partials/comment', {comment: comment}) %> -<% }) %> +
+ <% comments.forEach((comment, index) => { %> +
+ <%- include('../partials/comment', {comment: comment}) %> +
+ <% }) %> +
<%- config.seperator %> diff --git a/views/posts/user.ejs b/views/posts/user.ejs index ccb1984..e4797b8 100644 --- a/views/posts/user.ejs +++ b/views/posts/user.ejs @@ -1,22 +1,48 @@ -

- <%= post.title %> -

-<%- func.render_md(post.content) %>
-<%= locale.edit_post %>
-<%= locale.permalink %>
-
+
+

+ <%= post.title %> +

+
+
+

+ <%- func.render_md(post.content) %>
+

+
+
+
+ "><%= locale.permalink %> +
+
+ <%- func.render_tags(post.tags) %>
+
+
+ "><%= locale.edit_post %>
+
+
+ <%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
+ <%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
+
+
- -
- -


-

- -
+
+ +
+ "> +


+

+ +
+
-<% comments[postID].forEach((comment, postID) => { %> - <%- include('../partials/comment', {comment: comment}) %> -<% }) %> +
+ <% comments.forEach((comment, index) => { %> +
+ <%- include('../partials/comment', {comment: comment}) %> +
+ <% }) %> +
<%- config.seperator %>