Fixed an issue with an incomplete example-config.json that made the

server not work at all.
Also added a default.css file
This commit is contained in:
deadvey
2025-10-24 12:28:22 +01:00
parent 66423cb3c0
commit 35163b5584
14 changed files with 105 additions and 131 deletions

1
.gitignore vendored
View File

@@ -8,5 +8,4 @@ data.json
hitcount.txt
*.swp
data
webroot
images/*

View File

@@ -4,7 +4,7 @@ WEBROOT_DIR=webroot
all: config css users posts comments data
clean:
rm -rf data
rm -rf webroot
rm -f webroot/custom.css
rm -f config.json
# config file
@@ -17,7 +17,7 @@ config.json:
css: $(WEBROOT_DIR)/custom.css
$(WEBROOT_DIR)/custom.css:
mkdir -p webroot
echo '* {\n font-family: sans-serif;\n}' > $(WEBROOT_DIR)/custom.css
echo '* { font-family: sans-serif; }' > $(WEBROOT_DIR)/custom.css
# users.json
users: $(DATA_DIR)/users.json

View File

@@ -3,8 +3,9 @@
"seperator": "<hr/>",
"site_name": "My Blog",
"site_url": "https://example.com",
"language": "en-US",
"locale": "en-US",
"port": 8080,
"data_storage": "json",
"cache_data": false,
"allow_signup": true,
"site_description": "Read my blogs!",

View File

@@ -20,6 +20,11 @@ export function increment_hitcount(postID = -1) { // -1 Means it will increment
writedata('posts', post, postID)
return 0
}
else {
post.hitcount = 1;
writedata('posts', post, postID)
return 0
}
return 1
}
}
@@ -72,9 +77,7 @@ export function getdata(data, index=-1) {
if (index < result.length) {
return result[index]
}
else {
return 1 // This index doesn't exist
}
return 1 // This index doesn't exist
}
return result
}

View File

@@ -54,14 +54,11 @@ export function unix_time_to_atom_date(unix_time) {
export function render_tags(tags) {
let string = "" // Initialises the string
if (tags.length == 1 && tags[0] == "") {
string = locale.no_tags; // If there are no tags, output something
string = ''; // If there are no tags, output nothing
}
else {
for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag
string += `<a href="/tag/${tags[tag_index].trim()}">${tags[tag_index].trim()}</a>` // 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 += ", ";
}
string += `<a href="/tag/${tags[tag_index].trim()}">#${tags[tag_index].trim()}</a> ` // Adds the tag to the string as a HTML href
}
}
return string

View File

@@ -19,7 +19,7 @@
</form>
<br/>
<div id='site-name'>
<h1><%- config.site_name %></h2>
<h1><a id='home-page-link' href="/"><%= config.site_name %></a></h1>
</div>
<div id='site-description'>
<h2><%- config.site_description %></h2>

View File

@@ -5,4 +5,5 @@
</style>
<link rel="stylesheet" href="/default.css">
<link rel="stylesheet" href="/custom.css">

View File

@@ -1,29 +1,34 @@
<div id="post-header">
<h1>
<%= post.title %>
<a href='/post/<%= post['id'] %>'><%= post.title %></a>
</h1>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<div id="post-content">
<p>
<%- func.render_md(post.content) %><br/>
</p>
</div>
<div id="post-details">
<div id="post-author">
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<div id="post-edit">
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
</div>
<div id="post-pubdate">
<span id="post-author">
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a></i>
</span>
-
<span id="post-pubdate">
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
</span>
<div id="post-editdate">
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
<div id="post-edit">
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>">
<img src='/icons/edit.png'>
</a><br/>
</div>
<% if (config.enable_hitcount == true) { %>
<div id='post-hitcount'>
Hitcount: <%- post.hitcount %>
@@ -31,6 +36,8 @@
<% } %>
</div>
<hr/>
<div id="post-commentform">
<!-- Comment form -->
<form method="POST" action="/submit_comment">

View File

@@ -1,51 +1,32 @@
<div id="post-header">
<h1>
<%= post.title %>
<a href='/post/<%= post['id'] %>'><%= post.title %></a>
</h1>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<div id="post-content">
<p>
<%- func.render_md(post.content) %><br/>
<%- func.render_md(post.content) %>
</p>
</div>
<div id="post-details">
<div id="post-author">
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
</div>
<div id="post-permalink">
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<span id="post-author">
<i><a href="/user/<%= user.username %>"><%= user.username %></a></i>
</span>
-
<span id="post-pubdate">
<i><%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</span>
<br/>
<div id="post-edit">
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>">
<img src='/icons/edit.png'>
</a><br/>
</div>
<div id="post-pubdate">
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
<div id="post-editdate">
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
</div>
<div id="post-commentform">
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= post["id"] %>">
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
<button type="submit"><%= locale.submit %></button>
</form>
</div>
<div id="post-comments">
<% comments.forEach((comment, index) => { %>
<div id="comment-no-<%= post.id %>-<%= comment.id %>" class="comment post-comment-<%= index %>">
<%- include('../partials/comment', {comment: comment}) %>
</div>
<% }) %>
</div>
<%- config.seperator %>

View File

@@ -3,49 +3,30 @@
<a href='/post/<%= post['id'] %>'><%= post.title %></a>
</h1>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<div id="post-content">
<p>
<%- func.render_md(post.content) %>
</p>
</div>
<div id="post-details">
<div id="post-author">
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
</div>
<div id="post-permalink">
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<span id="post-author">
<i><a href="/user/<%= user.username %>"><%= user.username %></a></i>
</span>
-
<span id="post-pubdate">
<i><%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</span>
<br/>
<div id="post-edit">
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>">
<img src='/icons/edit.png'>
</a><br/>
</div>
<div id="post-pubdate">
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
<div id="post-editdate">
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
</div>
<div id="post-commentform">
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= post["id"] %>">
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
<button type="submit"><%= locale.submit %></button>
</form>
</div>
<div id="post-comments">
<% comments.forEach((comment, index) => { %>
<div id="comment-no-<%= post.id %>-<%= comment.id %>" class="comment post-comment-<%= index %>">
<%- include('../partials/comment', {comment: comment}) %>
</div>
<% }) %>
</div>
<%- config.seperator %>

View File

@@ -1,48 +1,32 @@
<div id="post-header">
<h1>
<%= post.title %>
<a href='/post/<%= post['id'] %>'><%= post.title %></a>
</h1>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<div id="post-content">
<p>
<%- func.render_md(post.content) %><br/>
<%- func.render_md(post.content) %>
</p>
</div>
<div id="post-details">
<div id="post-permalink">
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
</div>
<div id="post-tags">
<%- func.render_tags(post.tags) %><br/>
</div>
<span id="post-author">
<i><a href="/user/<%= user.username %>"><%= user.username %></a></i>
</span>
-
<span id="post-pubdate">
<i><%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</span>
<br/>
<div id="post-edit">
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>">
<img src='/icons/edit.png'>
</a><br/>
</div>
<div id="post-pubdate">
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
<div id="post-editdate">
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
</div>
</div>
<div id="post-commentform">
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= post["id"] %>">
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
<button type="submit"><%= locale.submit %></button>
</form>
</div>
<div id="post-comments">
<% comments.forEach((comment, index) => { %>
<div id="comment-no-<%= post.id %>-<%= comment.id %>" class="comment post-comment-<%= index %>">
<%- include('../partials/comment', {comment: comment}) %>
</div>
<% }) %>
</div>
<%- config.seperator %>

4
webroot/custom.css Normal file
View File

@@ -0,0 +1,4 @@
* {
font-family: sans-serif;
}

16
webroot/default.css Normal file
View File

@@ -0,0 +1,16 @@
body {
max-width: 900px;
margin: auto;
}
#header {
text-align: center;
}
#post-edit img {
width: 20px;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}

BIN
webroot/icons/edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B