Compare commits
5 Commits
5a14b125d2
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cfb3f6e60 | |||
| 46e7394a6f | |||
| 736edee1b0 | |||
| 63ca617895 | |||
| 9aff454ec2 |
@@ -9,7 +9,9 @@
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^5.2.1",
|
||||
"express-router": "^0.0.1",
|
||||
"highlight.js": "^11.11.1",
|
||||
"markdown-it": "^14.1.0",
|
||||
"markdown-it-named-code-blocks": "^1.1.0",
|
||||
"mssql": "^12.2.0",
|
||||
"package.json": "^2.0.1"
|
||||
}
|
||||
|
||||
@@ -127,6 +127,8 @@ export function render_comment(comment_content)
|
||||
export function render_md(content)
|
||||
{
|
||||
const markdownit = require("markdown-it")
|
||||
const hljs = require("highlight.js");
|
||||
const namedCodeBlocks = require("markdown-it-named-code-blocks");
|
||||
const md = markdownit
|
||||
({ // this is just defining some options for markdown-it, should I add this to config.json?
|
||||
html: false,
|
||||
@@ -135,7 +137,21 @@ export function render_md(content)
|
||||
linkify: false,
|
||||
typographer: true,
|
||||
quotes: locale.quotes,
|
||||
highlight: function (content, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
return (
|
||||
'<pre class="hljs"><code>' +
|
||||
hljs.highlight(content, { language: lang, ignoreIllegals: true }).value +
|
||||
"</code></pre>"
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
'<pre class="hljs"><code>' + md.utils.escapeHtml(content) + "</code></pre>"
|
||||
);
|
||||
}
|
||||
})
|
||||
.use(namedCodeBlocks)
|
||||
.disable('image');
|
||||
return md.render(content)
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ router.post(`${config.site_path}/submit_post`, (req,res) => {
|
||||
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||
comments.push({'id': id, 'comments': []})
|
||||
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`)
|
||||
res.redirect(302, `/post/${id}`);
|
||||
res.redirect(302, `${config.sitr_path}/post/${id}`);
|
||||
}
|
||||
else {
|
||||
res.render("partials/message", {
|
||||
|
||||
+11
-4
@@ -5,12 +5,15 @@ const func = require('../functions')
|
||||
const router = express.Router();
|
||||
|
||||
///////////////////// Form pages ////////////////////////////
|
||||
// new post
|
||||
router.get(`${config.site_path}/${config.new_post_url}`, (req,res) => {
|
||||
res.render("forms/new_post", {
|
||||
config,
|
||||
locale,
|
||||
});
|
||||
}); // /post
|
||||
|
||||
// signup
|
||||
router.get(`${config.site_path}/${config.signup_url}`, (req,res) => {
|
||||
// if the server does allow signup
|
||||
if (config.allow_signup == true) {
|
||||
@@ -29,24 +32,28 @@ router.get(`${config.site_path}/${config.signup_url}`, (req,res) => {
|
||||
}
|
||||
// If allow_signup is undefined or not a boolean, error
|
||||
else {
|
||||
res.redirect(301,"/")
|
||||
res.redirect(301,config.site_path)
|
||||
console.log("Error, invalid value for allow_signup (bool)")
|
||||
}
|
||||
}); // /signup
|
||||
|
||||
// edit account
|
||||
router.get(`${config.site_path}/${config.edit_account_base_url}/:user_id`, (req,res) => {
|
||||
const userID = parseInt(req.params.user_id);
|
||||
res.render("forms/edit_account",
|
||||
{
|
||||
config,
|
||||
locale,
|
||||
user: data.getdata('users', 'id', userID),
|
||||
user: data.getdata('users', 'id', userID)[0],
|
||||
userID
|
||||
});
|
||||
}); // /delete_account
|
||||
|
||||
// edit post
|
||||
router.get(`${config.site_path}/${config.edit_post_base_url}/:post_id`, (req,res) => {
|
||||
const postID = req.params.post_id
|
||||
const post = data.getdata('posts','id', postID)
|
||||
const user = data.getdata('users', 'id', post.userID)
|
||||
const post = data.getdata('posts','id', postID)[0]
|
||||
const user = data.getdata('users', 'id', post.userID)[0]
|
||||
res.render("forms/edit_post",
|
||||
{
|
||||
config,
|
||||
|
||||
@@ -89,7 +89,7 @@ router.get(`${config.site_path}/post/:post_index`, (req, res) => {
|
||||
}
|
||||
else {
|
||||
console.log("Error loading page")
|
||||
res.redirect(301,"/")
|
||||
res.redirect(301,config.site_path)
|
||||
}
|
||||
}); // /post/:post_index
|
||||
|
||||
@@ -118,7 +118,7 @@ router.get(`${config.site_path}/comment/:postID-:commentID`, (req,res) => {
|
||||
const commentID = parseInt(req.params.commentID);
|
||||
const postID = parseInt(req.params.postID);
|
||||
|
||||
let posts_comments = data.getdata('comments', 'id', postID)["comments"]
|
||||
let posts_comments = data.getdata('comments', 'id', postID)[0]["comments"]
|
||||
let comment = 1
|
||||
// For loop to find the comment with matching ID
|
||||
posts_comments.forEach((current_comment, index) => {
|
||||
|
||||
+4
-1
@@ -50,6 +50,9 @@ function perform_checks()
|
||||
exit_flag = false
|
||||
required_values = ['site_admin','seperator','site_name','site_url','locale','port','cache_data','allow_signup','site_description','request_data_limit','enable_hitcount','charset','root_path','edit_account_base_url','new_post_url','signup_url','default_commenter_username','rss','atom','date_format','time_zone','css']
|
||||
// Perform some standard checks:
|
||||
if (config.site_path.slice(-1) == "/") { // cut off a trailing /
|
||||
config.site_path = config.site_path.substring(0,config.site_path.length-1);
|
||||
}
|
||||
|
||||
// data_storage
|
||||
switch (config.data_storage)
|
||||
@@ -83,6 +86,6 @@ function perform_checks()
|
||||
perform_checks()
|
||||
|
||||
app.listen(config.port, () => {
|
||||
console.log(`Server is running at http://localhost:${config.port} webroot: ${config.root_path}`);
|
||||
console.log(`Server is running at http://localhost:${config.port}${config.site_path} webroot: ${config.root_path}`);
|
||||
console.log("Running in: ", __dirname)
|
||||
})
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="<%= config.language %">
|
||||
<html lang="<%= config.language %>">
|
||||
<head>
|
||||
<%- include("../partials/head") %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<header id="site-header">
|
||||
<%- include("../headers/site_wide") %>
|
||||
</header>
|
||||
<form action="<%= config.site_path %>/submit_edit_user" method="POST">
|
||||
<input name="userID" type="hidden" value="<%= userID %>">
|
||||
<label><%= locale.password %>:</label><br/>
|
||||
@@ -18,5 +22,6 @@
|
||||
<label><%- locale.delete_account_confirmation %>: </label><input type="checkbox" name="agreement"><br/>
|
||||
<input type="submit" value="Submit"><br/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
<%- include("../partials/head") %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<header id="site-header">
|
||||
<%- include("../headers/site_wide") %>
|
||||
</header>
|
||||
<form action="<%= config.site_path %>/submit_edit_post" method="POST" onsubmit="sha512password()">
|
||||
<input name="userID" type="hidden" value="<%= post['userID'] %>">
|
||||
<input name="postID" type="hidden" value="<%= postID %>">
|
||||
@@ -23,5 +27,6 @@
|
||||
<label>Delete forever (no undo): </label><input name="delete" type="checkbox"><br/>
|
||||
<input type="submit" value="Submit"><br/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
<%- include('../partials/head.ejs') %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<header id="site-header">
|
||||
<%- include("../headers/site_wide") %>
|
||||
</header>
|
||||
<form action="<%= config.site_path %>/submit_post" method="POST">
|
||||
<label><%= locale.username %>:</label><br/>
|
||||
<input required name="username"><br/><br/>
|
||||
@@ -21,5 +25,7 @@
|
||||
<input name="tags"><br/><br/>
|
||||
|
||||
<input type="submit" value="Submit"><br/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</form></html>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
<%- include("../partials/head") %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<header id="site-header">
|
||||
<%- include("../headers/site_wide") %>
|
||||
</header>
|
||||
<form action="<%= config.site_path %>/submit_signup" method="POST">
|
||||
<label><%= locale.username %></label><br/>
|
||||
<input required name="username"><br/><br/>
|
||||
@@ -20,5 +24,6 @@
|
||||
<label><%- locale.signup_agreement %>: </label><input type="checkbox" name="agreement" required><br/>
|
||||
<input type="submit" value="Submit"><br/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<meta charset="<%- config.charset %>">
|
||||
<meta name='robots' content='noindex'>
|
||||
<title><%= config.site_path %></title>
|
||||
<title><%= config.site_name %></title>
|
||||
|
||||
<style>
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title><%= config.site_name %></title>
|
||||
<link><%= config.site_url %></title>
|
||||
<description><%= config.site_description %></description>
|
||||
<updated><%= func.unix_time_to_atom_date(getUnixTime(new Date())) %></updated>
|
||||
<id><%= config.site_url %></id>
|
||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||
<% if (posts[postID]["deleted"] != true) { %>
|
||||
<entry>
|
||||
<title><%= posts[postID]["title"] %></title>
|
||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||
<summary><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></summary>
|
||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||
<pubDate><%# func.unix_time_to_atom_date(posts[postID]['pubdate']) %></pubDate>
|
||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||
<% } %>
|
||||
</entry>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</feed>
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title><%= config.site_name %></title>
|
||||
<link><%= config.site_url %></title>
|
||||
<description><%= config.site_description %></description>
|
||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||
<% if (posts[postID]["deleted"] != true) { %>
|
||||
<item>
|
||||
<title><%= posts[postID]["title"] %></title>
|
||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||
<description><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></description>
|
||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||
<pubDate><%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %></pubDate>
|
||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||
<% } %>
|
||||
</item>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title><%= config.site_name %></title>
|
||||
<link><%= config.site_url %></title>
|
||||
<description><%= config.site_description %></description>
|
||||
<updated><%= func.unix_time_to_atom_date(getUnixTime(new Date())) %></updated>
|
||||
<id><%= config.site_url %></id>
|
||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||
<% if (posts[postID]["userID"] == userID) { %>
|
||||
<% if (posts[postID]["deleted"] != true) { %>
|
||||
<entry>
|
||||
<title><%= posts[postID]["title"] %></title>
|
||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||
<summary><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></summary>
|
||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||
<pubDate><%# func.unix_time_to_atom_date(posts[postID]['pubdate']) %></pubDate>
|
||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||
<% } %>
|
||||
</entry>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</feed>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title><%= config.site_name %></title>
|
||||
<link><%= config.site_url %></title>
|
||||
<description><%= config.site_description %></description>
|
||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||
<% if (posts[postID]["userID"] == userID) { %>
|
||||
<% if (posts[postID]["deleted"] != true) { %>
|
||||
<item>
|
||||
<title><%= posts[postID]["title"] %></title>
|
||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||
<description><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></description>
|
||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||
<pubDate><%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %></pubDate>
|
||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||
<% } %>
|
||||
</item>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</channel>
|
||||
</rss>
|
||||
+6
-2
@@ -30,7 +30,6 @@ a {
|
||||
border: none;
|
||||
border-radius: 0px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
@@ -56,7 +55,9 @@ a:hover {
|
||||
.comment:nth-child(even) {
|
||||
background: #1E1E1E;
|
||||
}
|
||||
|
||||
.named-fence-filename {
|
||||
border: 1px white solid;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
@@ -70,4 +71,7 @@ a:hover {
|
||||
.comment:nth-child(even) {
|
||||
background: #EEEEEE;
|
||||
}
|
||||
.named-fence-filename {
|
||||
border: 1px black solid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user