MD + commenting started

markdown body in "content" field of article (no DOM.purify cuz only admin write blog)
started commenting function:
TODO in node/comments.js
master
derzombiiie 2021-08-07 11:43:12 +02:00
parent d189472d9e
commit 606b7f7b5b
9 changed files with 91 additions and 9 deletions

View File

@ -1,9 +1,10 @@
# TODO
- Actual post view site thingy
- markdown interpreter thing
- idk comments
- voting
<DONE> markdown interpreter thing
* voting
* idk comments
- Admin interface
- create posts in MD

17
html/js/comment.js Normal file
View File

@ -0,0 +1,17 @@
function displaycomments() {
commenting = new metaentry(undefined,"comment:",".content",{"content":
`Your comment: (no MD)<br>
<textarea class="comment commtext"></textarea>
<input class="comment" onclick="comment($('.commtext').val())" type="submit" value="Submit!" \\>`})
}
function comment(comment) {
$.ajax({
type: "POST",
url: "/comment",
data: {
comment: comment
},
dataType: "json"
})
}

6
html/js/marked.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,8 @@
// post displayer:
$(document).ready(() => {
console.log(1)
content = new entry(postDATA.title, postDATA.author, postDATA.desc, postDATA.href, postDATA.tags, postDATA.id, postDATA.create)
content = new entry(postDATA.title, postDATA.author, marked(postDATA.content), postDATA.href, postDATA.tags, postDATA.id, postDATA.create)
content.appendto(".content")
// commenting thing
displayshare()
displaycomments()
})

View File

@ -9,12 +9,14 @@
<link rel="stylesheet" href="/static/style/fonts.css">
<link rel="stylesheet" href="/static/style/main.css">
<script src="/static/js/jq.js"></script>
<script src="/static/js/marked.min.js"></script>
<script>
postDATA = //<!--POST-DATA-INJECT-->//
postDATA = "a"//<!--POST-DATA-INJECT-->//
</script>
<script src="/static/js/themes.js"></script>
<script src="/static/js/menubar.js"></script>
<script src="/static/js/entry.js"></script>
<script src="/static/js/comment.js"></script>
<script src="/static/js/share.js"></script>
<script src="/static/js/posts.js"></script>
</head>

View File

@ -98,3 +98,10 @@ body, html {
.share {
color: blue
}
/* comments */
textarea.comment {
resize: none;
width: calc( 100% - 0.5em);
height: 5em;
}

View File

@ -4,6 +4,7 @@ const filestuff = require("./filestuff")
var con = require("./console")
const JSONdb = require("simple-json-db")
var posts = require("./posts")
var comments = require("./comments")
const app = express()
const port = 5500
@ -78,6 +79,10 @@ const postsDB = new JSONdb("storage/posts.json")
posts.init(postsDB)
posts.rank()
// readout comments:
const commentDB = new JSONdb("storage/comments.json")
comments.init(commentDB)
// posts:
app.get("/posts", (req, res) => {
if( typeof( req.query.api ) != "undefined" ) {
@ -91,7 +96,7 @@ app.get("/posts", (req, res) => {
}
} else {
res.status( 200 )
filestuff.readFSr(req, res, "html/posts/index.html", "text/html", "//<!--POST-DATA-INJECT-->//", JSON.stringify(postsDB.get(req.query.post)))
filestuff.readFSr(req, res, "html/posts/index.html", "text/html", "\"a\"//<!--POST-DATA-INJECT-->//", JSON.stringify(postsDB.get(req.query.post)))
}
})

42
node/comments.js Normal file
View File

@ -0,0 +1,42 @@
this.init = (db) => {
this.db = db
return this
}
// key structur:
// postID-commentID
// how 2 requests:
// POST /comment // create comment
// comment:
// ---
// GET /comment // read out comments
// post:
// CMDs
// comment postID [ commentID ]
// generating "hot" + "new" articles etc. (should run 1 / 0:30h and at startup + on new article)
this.read = (count, sort) => {
let ret = []
debugger
switch (sort) {
case "hot":
this.ranking.hot.length
for ( let i = 0 ; i < count ; i++ ) {
if ( typeof( this.ranking.hot[i] ) == "number" ) {
ret.push( this.db.get( this.ranking.hot[i] ) )
}
}
break
default:
for ( let i = 0 ; i < count ; i++ ) {
if ( this.db.get( i ) )
ret.push( this.db.get( i ) )
}
break
}
return ret
}

View File

@ -16,9 +16,10 @@
"id": 0
},
"1": {
"title": "My 2 Post",
"title": "Im trying MD post",
"author": "derzombiiie",
"desc": "Lorem ipsum dolor sit.",
"desc": "HERE PRESS THIS THIS NOT CONTENT THIS DESC!",
"content": "# Article!\nwelcome\n*bold***italic** ***bold+italic***\n- point1\n- point2- \n me not more md from the brain :(",
"href": "#",
"tags": [
"testing",