From 5471d723a030705c349c1633faf134b137bc9a5a Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 30 Oct 2019 00:32:50 +0100 Subject: Added comment curation tool available at /comments.html --- .editorconfig | 4 ++ site.tmpl | 136 +++++++++++++++++++++++++------------------------ src/comments.html | 100 ++++++++++++++++++++++++++++++++++++ src/static/comments.js | 76 +++++++++++++-------------- 4 files changed, 212 insertions(+), 104 deletions(-) create mode 100644 src/comments.html diff --git a/.editorconfig b/.editorconfig index 1923d41..eebf0a8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,7 @@ indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[Makefile] +indent_style = tab +indent_size = 4 diff --git a/site.tmpl b/site.tmpl index 39e8c6c..c745997 100644 --- a/site.tmpl +++ b/site.tmpl @@ -1,6 +1,7 @@ {{ define "header" }} - - + + + @@ -25,74 +26,75 @@ - -
-{{ end }} -{{ define "footer" }} -
- {{ template "ga" . }} + +
+ {{ end }} + {{ define "footer" }} +
+ {{ template "ga" . }} - + + {{ end }} {{ define "navigation" }} - + {{ end }} {{ define "author" }} - by {{ html .Site.Other.Author }} +by {{ html .Site.Other.Author }} {{ end }} {{define "date"}} - + {{end}} {{define "modified"}} -

Modified on {{ .ModTime.Format "2006-01-02T15:04:05" }}

+

Modified on {{ .ModTime.Format "2006-01-02T15:04:05" }}

{{end}} {{ define "page" }} - {{ template "header" . }} - {{ template "navigation" . }} - {{ .Content }} - {{ template "prism" . }} - {{ template "mathjax" . }} - {{ template "footer" . }} +{{ template "header" . }} +{{ template "navigation" . }} +{{ .Content }} +{{ template "prism" . }} +{{ template "mathjax" . }} +{{ template "footer" . }} {{ end }} {{ define "post" }} -
-
-

{{ .Title }}

- {{ if eq .Other.Type "post" }} -
- {{ template "date" .Date }} - {{ template "author" . }} -
- {{ end }} -
-
+
+
+

{{ .Title }}

+ {{ if eq .Other.Type "post" }} +
+ {{ template "date" .Date }} + {{ template "author" . }} +
+ {{ end }} +
+
{{ .Content }} -
-
+
+
- {{ if eq .Other.Type "post" }} - {{ template "comments" . }} - {{ end }} +{{ if eq .Other.Type "post" }} +{{ template "comments" . }} +{{ end }} - {{ template "modified" . }} +{{ template "modified" . }} {{ end }} {{ define "mathjax" }} - - + {{ end }} {{ define "ga" }} - - + + {{ end }} {{ define "prism" }} - - + + {{ end }} {{ define "comments" }} -
-

Comments

-
-
-
-
-
- +
+

Comments

+
+
+
+
+
    +
    - - - + + + {{ end }} diff --git a/src/comments.html b/src/comments.html new file mode 100644 index 0000000..3d990da --- /dev/null +++ b/src/comments.html @@ -0,0 +1,100 @@ + + + + + + + + + Commenta dashboard + + + + + + + +

    Comments

    +
    + + + + + + + + + + diff --git a/src/static/comments.js b/src/static/comments.js index c8234d2..3f373e5 100644 --- a/src/static/comments.js +++ b/src/static/comments.js @@ -10,7 +10,7 @@ var firebaseConfig = { firebase.initializeApp(firebaseConfig); var database = firebase.database(); -var docPath = 'comments' + window.location.pathname.replace('.html', ''); +var docPath = window.location.hostname.replace('.', '-') + '/comments' + window.location.pathname.replace('.html', ''); var submit = document.querySelector('#submit'); var comments = document.querySelector('.comments ul'); var textName = document.querySelector('#name'); @@ -21,43 +21,45 @@ function encodeHTML(s) { return s.replace(/&/g, '&').replace(/ -
    ${encodeHTML(item.name)} - ${encodeHTML(item.published)}
    -
    ${encodeHTML(item.comment)}
    - `; - comments.innerHTML += liItem; - }); + // rendering html + commentList.reverse().forEach(function (item) { + var liItem = `
  • +
    ${encodeHTML(item.name)} - ${encodeHTML(item.published)}
    +
    ${encodeHTML(item.comment)}
    +
  • `; + comments.innerHTML += liItem; + }); -}, function (errorObject) { - console.log("The read failed: " + errorObject.code); -}); + }, function (errorObject) { + console.log("The read failed: " + errorObject.code); + }); -submit.addEventListener('click', function (evt) { - if (textName.value && textComment.value) { - submit.disabled = true; - firebase.database().ref(docPath + '/' + Date.now()).set({ - name: textName.value, - comment: textComment.value, - published: new Date().toISOString().slice(0, 16).replace('T', ' '), - }, function (error) { - if (error) { - alert('Data could not be saved.' + error); - } else { - textName.value = ''; - textComment.value = ''; - submit.disabled = false; - } - }); - } -}); + submit.addEventListener('click', function (evt) { + if (textName.value && textComment.value) { + submit.disabled = true; + firebase.database().ref(docPath + '/' + Date.now()).set({ + name: textName.value, + comment: textComment.value, + published: new Date().toISOString().slice(0, 16).replace('T', ' '), + }, function (error) { + if (error) { + alert('Data could not be saved.' + error); + } else { + textName.value = ''; + textComment.value = ''; + submit.disabled = false; + } + }); + } + }); +} -- cgit v1.2.3