better markdown
This commit is contained in:
parent
78b836bef5
commit
b538d495db
44
app.js
44
app.js
@ -1,12 +1,13 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const showdown = require('showdown')
|
||||||
const crypto = require('crypto'); // For encrypting passwords
|
const crypto = require('crypto'); // For encrypting passwords
|
||||||
const { fromUnixTime, format, getUnixTime } = require("date-fns")
|
const { fromUnixTime, format, getUnixTime } = require("date-fns")
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const users = require('./users.js');
|
const users = require('./users.js');
|
||||||
const posts = require('./posts.js');
|
const posts = require('./posts.js');
|
||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
|
let converter = new showdown.Converter({simpleLineBreaks: true, tables: true, strikethrough: true, tasklists: true, encodeEmails: true})
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 8080;
|
|
||||||
let footer_div = config.site_wide_footer
|
let footer_div = config.site_wide_footer
|
||||||
footer_div = replace_format_indicators(footer_div)
|
footer_div = replace_format_indicators(footer_div)
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
|
|||||||
.replaceAll("%%", "%")
|
.replaceAll("%%", "%")
|
||||||
.replaceAll("%A", (post_object["tags"]))
|
.replaceAll("%A", (post_object["tags"]))
|
||||||
.replaceAll("%B", (hyperlink_tags(post_object["tags"])))
|
.replaceAll("%B", (hyperlink_tags(post_object["tags"])))
|
||||||
.replaceAll("%C", markdown_to_html(post_object["content"]))
|
.replaceAll("%C", converter.makeHtml(post_object["content"]))
|
||||||
.replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
|
.replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
|
||||||
.replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
|
.replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
|
||||||
.replaceAll("%F", users.users[post_object["userID"]]['prettyname'])
|
.replaceAll("%F", users.users[post_object["userID"]]['prettyname'])
|
||||||
@ -65,7 +66,7 @@ function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
|
|||||||
.replaceAll("%O", `/edit/${post_index}`)
|
.replaceAll("%O", `/edit/${post_index}`)
|
||||||
.replaceAll("%R", "/rss")
|
.replaceAll("%R", "/rss")
|
||||||
.replaceAll("%S", config.seperator)
|
.replaceAll("%S", config.seperator)
|
||||||
.replaceAll("%T", markdown_to_html(post_object["title"]))
|
.replaceAll("%T", post_object["title"])
|
||||||
.replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
|
.replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
|
||||||
.replaceAll("%Y", config.site_name)
|
.replaceAll("%Y", config.site_name)
|
||||||
.replaceAll("%W", config.site_description)
|
.replaceAll("%W", config.site_description)
|
||||||
@ -89,22 +90,6 @@ function escape_input(input) {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
// Markdown supported:
|
|
||||||
// *text* = bold
|
|
||||||
// _text_ = italic
|
|
||||||
// [page](url) = hyperlink
|
|
||||||
// ```code``` = code
|
|
||||||
function markdown_to_html(input) {
|
|
||||||
// FIXME backticks before these should negate stuff
|
|
||||||
let output = input
|
|
||||||
.replaceAll(/\[(.*)\]\((https:\/\/|http:\/\/)(.*)\)/g, "<a href='$2$3'>$1</a>")
|
|
||||||
.replaceAll(/\*(.*)\*/g,"<b>$1</b>")
|
|
||||||
.replaceAll(/_(.*)_/g,"<i>$1</i>")
|
|
||||||
.replaceAll(/```(.*)```/gms,"<code>$1</code>")
|
|
||||||
.replaceAll("\n","<br/>")
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get(config.rss_path, (req,res) => {
|
app.get(config.rss_path, (req,res) => {
|
||||||
if (config.rss == false) {
|
if (config.rss == false) {
|
||||||
res.send("Sorry, RSS is disabled!")
|
res.send("Sorry, RSS is disabled!")
|
||||||
@ -122,7 +107,7 @@ app.get(config.rss_path, (req,res) => {
|
|||||||
<item>
|
<item>
|
||||||
<title>${posts.posts[i]["title"]}</title>
|
<title>${posts.posts[i]["title"]}</title>
|
||||||
<link>${config.site_url}/post/${i}.${config.file_extension}</link>
|
<link>${config.site_url}/post/${i}.${config.file_extension}</link>
|
||||||
<description><![CDATA[${posts.posts[i]["content"].replaceAll("\n","<br/>")}]]></description>
|
<description><![CDATA[${converter.makeHtml(posts.posts[i]["content"])}]]></description>
|
||||||
<guid isPermaLink="true">${config.site_url}/post/${i}</guid>
|
<guid isPermaLink="true">${config.site_url}/post/${i}</guid>
|
||||||
<pubDate>${unix_time_to_rss_date(posts.posts[i]['pubdate'])}</pubDate>`
|
<pubDate>${unix_time_to_rss_date(posts.posts[i]['pubdate'])}</pubDate>`
|
||||||
for (let j = 0; j < posts.posts[i]['tags'].length; j++) {
|
for (let j = 0; j < posts.posts[i]['tags'].length; j++) {
|
||||||
@ -197,8 +182,8 @@ app.get("/post", (req,res) => {
|
|||||||
<label>Title: </label><input required name="title"><br/>
|
<label>Title: </label><input required name="title"><br/>
|
||||||
<label>Content*: </label><textarea required name="content"></textarea><br/>
|
<label>Content*: </label><textarea required name="content"></textarea><br/>
|
||||||
<label>Tags (comma seperated): </label><input name="tags"><br/>
|
<label>Tags (comma seperated): </label><input name="tags"><br/>
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit"><br/>
|
||||||
<small>* Markdown supported: *bold*, _italic_, (link)[url] and \`\`\`code block\`\`\`</small>
|
<small>* Markdown supported</small>
|
||||||
</form></html>`);
|
</form></html>`);
|
||||||
});
|
});
|
||||||
app.get("/edit/:post_id", (req,res) => {
|
app.get("/edit/:post_id", (req,res) => {
|
||||||
@ -211,15 +196,12 @@ app.get("/edit/:post_id", (req,res) => {
|
|||||||
<input name="postID" type="hidden" value="${post_id}">
|
<input name="postID" type="hidden" value="${post_id}">
|
||||||
<label>${user.prettyname}'s Password: </label><input type="password" required id="password" name="password"><br/>
|
<label>${user.prettyname}'s Password: </label><input type="password" required id="password" name="password"><br/>
|
||||||
<label>Title: </label><input value="${post['title']}" required name="title"><br/>
|
<label>Title: </label><input value="${post['title']}" required name="title"><br/>
|
||||||
<label>Content: </label>
|
<label>Content*: </label>
|
||||||
<textarea required name="content">${post['content']
|
<textarea required name="content">${post['content']}</textarea><br/>
|
||||||
.replaceAll('"', """)
|
|
||||||
.replaceAll("<", "<")
|
|
||||||
.replaceAll(">", ">")
|
|
||||||
.replaceAll("\\", "\")}</textarea><br/>
|
|
||||||
<label>Tags (comma seperated): </label><input value="${post['tags']}" name="tags"><br/>
|
<label>Tags (comma seperated): </label><input value="${post['tags']}" name="tags"><br/>
|
||||||
<label>Delete forever (no undo): </label><input name="delete" type="checkbox"><br/>
|
<label>Delete forever (no undo): </label><input name="delete" type="checkbox"><br/>
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit"><br/>
|
||||||
|
<small>* Markdown supported</small>
|
||||||
</form></html>`);
|
</form></html>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -281,6 +263,6 @@ app.post("/submit_post", (req,res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(config.port, () => {
|
||||||
console.log(`Server is running at http://localhost:${port} in ${config.root_path}`);
|
console.log(`Server is running at http://localhost:${config.port} in ${config.root_path}`);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export const seperator = "<hr/>"
|
export const seperator = "<hr/>"
|
||||||
export const site_name = "Deadvey's Blog"
|
export const site_name = "Deadvey's Blog"
|
||||||
export const site_url = "https://deadvey.com"
|
export const site_url = "https://deadvey.com"
|
||||||
|
export const port = 8080
|
||||||
export const site_description = "Films, tech, random shit"
|
export const site_description = "Films, tech, random shit"
|
||||||
export const timeline_length = 20
|
export const timeline_length = 20
|
||||||
export const enable_hitcount = true // Can slow down page loading a bit
|
export const enable_hitcount = true // Can slow down page loading a bit
|
||||||
@ -103,6 +104,9 @@ export const css = `
|
|||||||
color: #282828;
|
color: #282828;
|
||||||
border: 1px solid #282828;
|
border: 1px solid #282828;
|
||||||
}
|
}
|
||||||
|
table {
|
||||||
|
border: solid 1px #282828;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
body {
|
body {
|
||||||
@ -129,6 +133,9 @@ export const css = `
|
|||||||
color: #ebdbb2;
|
color: #ebdbb2;
|
||||||
border: 1px solid #ebdbb2;
|
border: 1px solid #ebdbb2;
|
||||||
}
|
}
|
||||||
|
table, td, th {
|
||||||
|
border: solid 1px #ebdbb2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
63
|
124
|
Loading…
x
Reference in New Issue
Block a user