Permalink
Browse files

Fuck markdown. Tired of fighting bugs in 3bmd and pandoc, doing thing…

…s the old-fashioned way.
  • Loading branch information...
1 parent 56a9351 commit c63849d11c6e662284cb2cee366f10c7771d7bc2 @vsedach committed Nov 27, 2011
Showing with 129 additions and 187 deletions.
  1. +3 −3 TODO
  2. +1 −2 cliki-convert.asd
  3. +0 −38 cliki-convert/artefacts.lisp
  4. +20 −23 cliki-convert/cliki-convert.lisp
  5. +1 −1 cliki-convert/package.lisp
  6. +0 −1 cliki2.asd
  7. +15 −10 src/article.lisp
  8. +83 −105 src/markup.lisp
  9. +1 −2 src/package.lisp
  10. +1 −1 src/search.lisp
  11. +4 −1 static/css/style.css
View
6 TODO
@@ -1,10 +1,10 @@
-* fix import of <pre> blocks
-* fix import of :(CLHS "foo") links
-* fix parser bug that shows up on Araneida page
+* fix BS with clhs-lookup pathnames and Symbol-Table.text
* article deletion (404 on subsequent access but still have history)
+* table colors and formatting
* make visited links purple
* create article button
* list all articles page
* list uncategorized articles page
+* make sure ASDF-Install still works
* robots.txt for site/ crawling
* expires headers for images
View
@@ -1,6 +1,5 @@
(asdf:defsystem :cliki-convert
:components ((:module "cliki-convert"
:components ((:file "package")
- (:file "artefacts" :depends-on ("package"))
- (:file "cliki-convert" :depends-on ("package" "artefacts")))))
+ (:file "cliki-convert" :depends-on ("package")))))
:depends-on (#:cliki2 #:cl-fad #:external-program #:local-time))
@@ -1,38 +0,0 @@
-(in-package #:cliki2.converter)
-
-(defrule article-link (and #\\ "_(" (+ (and (! #\)) character)) #\))
- (:lambda (list)
- (text (cdr list))))
-
-(defrule category-link (and #\\ "*(" (+ (and (! #\)) character)) #\))
- (:lambda (list)
- (text (cdr list))))
-
-(defrule hyperspec-link (and "\\#" "H(" (+ (and (! #\)) character)) #\))
- (:lambda (list)
- (text #\_ (cdr list))))
-
-(defun category-char-p (character)
- (not (member character '(#\: #\" #\)))))
-
-(defrule category-name (and (? #\") (+ (category-char-p character)) (? #\"))
- (:lambda (list)
- (text (second list))))
-
-(defrule category-list (and (and "/(")
- category-name
- (* (and (! #\)) character))
- ")")
- (:lambda (list)
- (format nil "_/(~A)" (second list))))
-
-(defrule remove-artefacts
- (* (or article-link
- category-link
- hyperspec-link
- category-list
- character))
- (:text t))
-
-(defun remove-artefacts (str)
- (parse 'remove-artefacts str))
@@ -4,35 +4,34 @@
(in-package #:cliki2.converter)
-(defun convert-old-cliki-page (file)
- (remove-artefacts
- (cl-ppcre:regex-replace-all
- "\\n *"
- (with-output-to-string (out) ;; this is thoroughly horrible
- (with-input-from-string (in (with-output-to-string (out)
- (dolist (p (ppcre:split "\\n\\s*\\n"
- (alexandria:read-file-into-string
- file :external-format :latin1)))
- (format out "<p>~A</p>" p))))
- (external-program:run
- "/usr/bin/pandoc"
- (list "-f" "html" "-t" "markdown" "-")
- :input in
- :output out)))
- (string #\Newline))))
+(defun read-file (path)
+ (alexandria:read-file-into-string path :external-format :latin1))
+
+(defun convert-article-revision (content)
+ (flet ((fixup-tag (regex str fixup)
+ (ppcre:regex-replace-all regex str
+ (lambda (match register)
+ (declare (ignore match))
+ (funcall fixup register))
+ :simple-calls t))
+ (fmt-category (category) (format nil "/(~A)" category))
+ (fmt-package (url) (format nil "_P(~A)" url))
+ (fmt-hyperspec (symbol) (format nil "_H(~A)" symbol)))
+ (loop for regex in '(":\\(CLHS \"(.*?)\"\\)" ":\\(package \"(.*?)\"\\)" "/\\(\"(.*?)\".*?\\)")
+ for action in (list #'fmt-hyperspec #'fmt-package #'fmt-category)
+ do (setf content (fixup-tag regex content action)))
+ content))
(defun load-old-articles (old-article-dir &key verbose)
"WARNING: This WILL blow away your old store."
(close-store)
- (cliki2::close-search-index)
- (iter (for item in '("content/" "index/" "store/"))
+ (iter (for item in '("articles/" "store/"))
(for path = (merge-pathnames item cliki2::*datadir*))
(cl-fad:delete-directory-and-files path :if-does-not-exist :ignore)
(ensure-directories-exist path))
(open-store (merge-pathnames "store/" cliki2::*datadir*))
- (cliki2::open-search-index)
(let ((old-articles (make-hash-table :test 'equalp))) ;; equalp is case insensitive
(dolist (file (cl-fad:list-directory old-article-dir))
@@ -50,9 +49,7 @@
;; discard deleted pages
(loop for article being the hash-key of old-articles do
(when (search "*(delete this page)"
- (alexandria:read-file-into-string
- (car (last (gethash article old-articles)))
- :external-format :latin1)
+ (read-file (car (last (gethash article old-articles))))
:test #'char-equal)
(remhash article old-articles)))
;; import into store
@@ -75,7 +72,7 @@
(revision (cliki2::add-revision
article
"import from CLiki"
- (convert-old-cliki-page file)
+ (convert-article-revision (read-file file))
:author cliki-import-user
:author-ip "0.0.0.0"
:date date)))
@@ -1,4 +1,4 @@
(in-package #:cl)
(defpackage #:cliki2.converter
- (:use #:cl #:esrap #:iter #:bknr.datastore))
+ (:use #:cl #:iter #:bknr.datastore))
View
@@ -8,7 +8,6 @@
#:ironclad
#:colorize
#:cl-recaptcha
- #:3bmd
#:sanitize
#:diff
#:cl-interpol
View
@@ -13,12 +13,10 @@
(intern (string-upcase (cut-whitespace category-title)) '#:cliki2.categories))
(defun content-categories (content)
- (mapcar
- (lambda (x)
- (subseq x 2 (1- (length x))))
- (cl-ppcre:all-matches-as-strings
- '(:sequence #\* #\( (:greedy-repetition 0 nil (:inverted-char-class #\))) #\))
- content)))
+ (let (categories)
+ (ppcre:do-register-groups (category) (#?/\*\(([^\)]*)\)/ content)
+ (pushnew category categories :test #'string-equal))
+ categories))
;;; article
@@ -52,7 +50,7 @@
(defun article-description (article)
(let ((content (cached-content article)))
(subseq content 0
- (1- (max 1 (or (nth-value 1 (cl-ppcre:scan ".*\\.[\\s]" content))
+ (1- (max 1 (or (nth-value 1 (ppcre:scan #?/.*\.[\s]/ content))
(position #\Newline content)
(max 30 (length content))))))))
@@ -62,8 +60,14 @@
(defmethod link-to ((article-titled string))
#?[/${(uri-encode (string-downcase (cut-whitespace article-titled)))}])
+(defun %print-article-link (title class)
+ #H[<a href="${(link-to title)}" class="${class}">${title}</a>])
+
(defun pprint-article-link (title)
- #H[<a href="${(link-to title)}" class="${(if (find-article title) "internal" "new")}">${title}</a>])
+ (%print-article-link title (if (find-article title) "internal" "new")))
+
+(defun pprint-category-link (title)
+ (%print-article-link title "category"))
;;; revisions
@@ -98,7 +102,8 @@
:author author
:author-ip author-ip
:date date
- :summary summary)))
+ :summary summary))
+ (content (remove #\Return content)))
(alexandria:write-string-into-file
content
(ensure-directories-exist (revision-path new-revision))
@@ -122,7 +127,7 @@
(awhen (content-categories content)
#H[<div id="categories"><hr />Categories: ]
(loop for category in it for divider = nil then t do
- (when divider #H" | ") (pprint-article-link category))
+ (when divider #H" | ") (pprint-category-link category))
#H[</div>])
(setf *footer*
(let ((title (title (article revision))))
Oops, something went wrong.

0 comments on commit c63849d

Please sign in to comment.