-
Notifications
You must be signed in to change notification settings - Fork 3
Markdown parser #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
emeralit
wants to merge
6
commits into
Dieterbe:master
Choose a base branch
from
emeralit:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
659fcc6
Modifica README
emeralit 6059518
Aggiunto il partial comments.html
emeralit 037f146
Aggiunto parsing markdown -> html
emeralit fad846e
Update README.md
emeralit 60de410
Comma originale, comments.html modifiche markdown
emeralit b071943
Update README.md
emeralit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ./DS_Store | ||
| ./*/.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,12 @@ Comma: a super simple comment server for static websites, in go | |
|
|
||
| This means your website is no longer purely static, but it's a simple, fairly pragmatic solution to dynamically save and load comments (using javascript) | ||
|
|
||
| ****************** | ||
| This is a fork to tailor the program to the needs of the Quickloox blog. | ||
|
|
||
| The comments.html file is a partial used by hugo for comment generation. | ||
| ******************* | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your comments.html is in italian... |
||
|
|
||
| # API | ||
|
|
||
| * GET /foo/bar/whatever/my-post-slug | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <div id="comments-container"> | ||
| <!-- javascript will add comments here. loaded from backend and/or submitted successfully --> | ||
| </div> | ||
|
|
||
| <h3>Commenta</h3> | ||
| <form id="new-comment-form" action="{{.Site.Params.commentServer}}"> | ||
| <input type="hidden" name="post" value="{{ .File.BaseFileName }}"> | ||
| <br /><input type="text" name="name" placeholder="* Nome" required /> | ||
| <br /><input type="email" name="email" placeholder="* Email (non visibile, usata per Gravatar)" required /> | ||
| <br /><input type="url" name="url" placeholder="Sito web" /> | ||
| <br /><input type="text" name="special" placeholder="* Sei un umano?" required /> | ||
| <br /><textarea rows="10" name="message" placeholder="* Commento" required></textarea> | ||
| <button id="new-comment-submit" class="btn-ready" type="submit" value="Send">Invia</button> | ||
| </form> | ||
|
|
||
| <script src="{{ .Site.BaseURL }}js/purify.min.js"></script> | ||
|
|
||
| <script src="{{ .Site.BaseURL }}js/marked.min.js"></script> | ||
|
|
||
| <script language="javascript"> | ||
| function codeToHTMLentities(mdWithHtml) { | ||
| var result = mdWithHtml.replace(/<code>([\s\S]*?)<\/code>/gm, function(a,b){ return "<code>"+toHtmlEntities(b)+"</code>" }); | ||
|
|
||
| result = result.replace(/^```([\s\S]*?)```$/gm, function(a,b){ return "<pre><code>"+toHtmlEntities(b)+"</code></pre>" }); | ||
|
|
||
| result = result.replace(/`([^`]+)`/g, function(a,b){ return "<code>"+toHtmlEntities(b)+"</code>" }); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function toHtmlEntities(str) { | ||
| var map = { | ||
| '&': '&', | ||
| '<': '<', | ||
| '>': '>', | ||
| "'": ''', | ||
| '"': '"' | ||
| }; | ||
|
|
||
| return str.replace(/[&<>"']/g, function(m) { return map[m]; }); | ||
| } | ||
|
|
||
| var monthNames = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"]; | ||
|
|
||
|
|
||
| function domReady(fn) { | ||
| if (document.readyState === "complete" || document.readyState === "interactive") { | ||
| setTimeout(fn, 1); | ||
| } else { | ||
| document.addEventListener("DOMContentLoaded", fn); | ||
| } | ||
| } | ||
|
|
||
| marked.use({ | ||
| breaks: true, | ||
| gfm: true, | ||
| }); | ||
|
|
||
| var addComment = function (data) { | ||
|
|
||
| const container = document.getElementById("comments-container"); | ||
|
|
||
|
|
||
| var txt = ""; | ||
| var d = new Date(data.Ts); | ||
| var date = d.getDate() + " " + monthNames[d.getMonth()] + " " + d.getFullYear() + " alle " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds(); | ||
|
|
||
| var msg = DOMPurify.sanitize(marked.parse(data.Message)); // Converte il markdown e lo sanifica. | ||
|
|
||
| txt += '<article id="comment" class="comment">\n'; | ||
| txt += '\t<img class="commentAvatar" src="https://www.gravatar.com/avatar/' + data.Hash + '?d=mm&s=60">\n'; | ||
| txt += '\t<div class="commentRight">\n'; | ||
| txt += '\t\t<p class="commentAuthor">' + ((data.Link == "") ? data.Author : '<a href="' + data.Link + '" class="commentAuthor">' + data.Author + '</a>') + '</p>\n'; | ||
| txt += '\t\t<time class="entry-date" datetime="' + data.Ts + '">' + date + '</time>\n'; | ||
| txt += '\t\t<div class="commentMessage">' + msg + '</div>\n'; | ||
| txt += '\t</div>\n'; | ||
| txt += '</article>\n'; | ||
|
|
||
| container.innerHTML += txt; | ||
| }; | ||
|
|
||
| domReady(async function () { | ||
| let form = document.getElementById("new-comment-form"); | ||
| let commentsUrl = "{{.Site.Params.commentServer}}/{{ .File.BaseFileName }}"; | ||
|
|
||
| form.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| sendData(); | ||
| }); | ||
|
|
||
| const response = await fetch(commentsUrl); | ||
| if (response.ok) { | ||
| comments = await response.json(); | ||
| comments.forEach(addComment); | ||
| } else { | ||
| e = "<div><b>Impossibile caricare i commenti</b></br>" + status + " " + err + | ||
| "<br/>Funzione commenti disabilitata"; | ||
| form.parentNode.insertBefore(document.createElement(e), form); | ||
| form.display = "none"; | ||
| } | ||
|
|
||
| async function sendData() { | ||
| document.querySelector('#new-comment-submit').textContent = 'Invio in corso...'; | ||
| const formData = new FormData(form); | ||
|
|
||
| // Recupera il testo del commento, lo sanitizza, lo sostituisce nel form | ||
| const msg = formData.get('message'); | ||
| const sanitizedMsg = DOMPurify.sanitize(codeToHTMLentities(msg)); | ||
| //console.log({msg, sanitizedMsg}); | ||
| formData.set('message', sanitizedMsg); | ||
|
|
||
| try { | ||
| const response = await fetch(commentsUrl, { | ||
| method: "POST", | ||
| body: formData, | ||
| }); | ||
| button = document.querySelector('#new-comment-submit'); | ||
| if (response.ok) { | ||
| button.textContent = 'Inviato!'; // Qui lasciamo pure la diciture Inviato!... | ||
| button.className = 'btn-ok'; | ||
| comment = await response.json(); | ||
| addComment(comment); | ||
| form.reset(); // Clear the form | ||
| button.textContent = 'Invia'; // Set the button text back to "Send" | ||
| button.className = 'btn-ready'; // Set the button class back to its default state | ||
| } else { | ||
| button.className = 'btn-err'; | ||
| const message = await response.text(); | ||
| button.textContent = 'failed with status ' + response.status + ' ' + message; | ||
| } | ||
| } catch (e) { | ||
| button.textcontent = 'failed with error ' + e; | ||
| console.error(e); | ||
| } | ||
| } | ||
| }); | ||
| </script> |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can have such a message in your fork, but this should not go into the upstream, e.g. not in this pr