fix comment formatting regression from safe markup
authorIan Kelling <ian@iankelling.org>
Tue, 4 Oct 2016 07:37:00 +0000 (00:37 -0700)
committerIan Kelling <ian@iankelling.org>
Tue, 4 Oct 2016 17:09:01 +0000 (10:09 -0700)
_site/cgi/comment
b.rb
comments/blog/site-redesign.html/1475551365.0383508 [new file with mode: 0755]
css/main.scss
get-comments
iank-mod.el
setup.sh

index 4b14c3c..b84c45e 100755 (executable)
@@ -142,6 +142,10 @@ if COMMENT_TXT.length > 1000 or GOTO.length > 150
   fail('length of comment or goto is too great')
 end
 
+if COMMENT_TXT.length <= 2 or COMMENT_TXT =~ /\A\s*\Z/
+  fail('not enough content in comment')
+end
+
 
 captchad = false
 if cgi.has_key?('answer') && cgi.has_key?('question')
@@ -300,7 +304,7 @@ $db.execute('insert into c values (NULL, ?, ?, ?, ?, ?)',
              COMMENT_TXT])
 
 if date
-  new_count = $db.execute(query + 'and date > ?',date)
+  new_count = $db.execute(query + 'and date > ?', date)
 else
   new_count = $db.execute(query)
 end
@@ -328,7 +332,7 @@ END_OF_MESSAGE
       smtp.send_message msg, opts[:from], opts[:to]
     end
   end
-  send_email :subject => 'new comments on iankelling.org'
+  send_email :subject => "new comment on #{DN}"
 end
 
 post(md_file)
diff --git a/b.rb b/b.rb
index 2dc8ad8..c2dbc75 100644 (file)
--- a/b.rb
+++ b/b.rb
@@ -125,15 +125,14 @@ EOF
   end
 
   def comment_html(comment, date)
-    inner = Redcarpet::Markdown.new(Redcarpet::Render::Safe, fenced_code_blocks: true).render(<<EOF)
-#{comment}
-<span class="comment-date">#{Time.at(date).strftime("%b %-d '%y")}</span>
-EOF
     # I tried putting the time,  %I:%M %p UTC, but it looks kinda
     # clunky, going against my simple theme.
+    user_input = Redcarpet::Markdown.new(Redcarpet::Render::Safe,
+                                   fenced_code_blocks: true).render(comment)
     <<EOF
 <div class="comment">
-  #{inner}
+  #{user_input}
+  <p class="comment-date">#{Time.at(date).strftime("%b %-d '%y")}</p>
 </div>
 EOF
   end
diff --git a/comments/blog/site-redesign.html/1475551365.0383508 b/comments/blog/site-redesign.html/1475551365.0383508
new file mode 100755 (executable)
index 0000000..3f2cca6
--- /dev/null
@@ -0,0 +1 @@
+Sample comment with *formatting*.
\ No newline at end of file
index c878224..7c7e4a2 100644 (file)
@@ -80,16 +80,10 @@ body {
   line-height: 1.5; // default is too scrunched
 }
 
-// alternative to a <br>. whatever.
-// https://stackoverflow.com/questions/7363766/how-to-insert-a-line-break-before-an-element-using-css
-.comment-date::before {
-  content: "\A";
-}
-
 .comment-date {
   color: $comment-date-color;
   font-size: 15px;
-  white-space: pre;
+  margin-top: 0;
 }
 
 .post-date {
index 54ea99a..0710319 100755 (executable)
@@ -24,7 +24,7 @@ shell="ssh $(chost iankelling.org)"
 while [[ $1 ]]; do
     case $1 in
         -a) all=true; shift ;;
-        -l) shell= ; shift ;; # -l  for local
+        -l) shell= ; shift ;; # -l  for local site instead of iankelling.org
     esac
 done
 
index 4faea5f..b033cbc 100644 (file)
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-(defun iankmod-start ()
-  (interactive)
-  (shell-command "/a/h/get-comments" "*messages*")
-  (find-file "/tmp/hcomments")
-  (iankmod 1))
+
+;; generally, use m-x iankmod-start. c-u to run on local testing
+;; instance.  Alternatively, run get-comments with whatever args,
+;; manually open /tmp/hcomments, then run (iankmod).
+
+(defun iankmod-start (arg)
+  (interactive "P")
+  (setq iankmod-last-arg (if (equal arg '(4)) " -l" ""))
+  (let ((cmd (concat "/a/h/get-comments" iankmod-last-arg)))
+    (shell-command cmd "*messages*")
+    (find-file "/tmp/hcomments")
+    (iankmod 1)))
+
 (defun iankmod-save ()
   (interactive)
-  (shell-command "/a/h/set-comments" "*messages*"))
+  (basic-save-buffer)
+  (let ((cmd (concat "/a/h/set-comments" iankmod-last-arg)))
+    (shell-command cmd "*messages*")))
 
 
 (defun iankmod-set-state (state)
index deb61b9..cfcee75 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -29,6 +29,7 @@ gitroot=/a/bin/githtml
 shopt -s extglob
 
 type -P a2enmod &>/dev/null || pi apache2
+type -P sqlite3 &>/dev/null || pi sqlite3
 
 acme-tiny-wrapper $domain