|
1 | | -(ns blogger2cryogen.core |
| 1 | +(ns |
| 2 | + ^{:author "Sanel Zukan" |
| 3 | + :doc "Utility to migrate Blogger posts to Cryogen static site generator."} |
| 4 | + blogger2cryogen.core |
2 | 5 | (:gen-class) |
3 | 6 | (:require [clojure.zip :as zip] |
4 | 7 | [clojure.data.zip.xml :as zx] |
|
37 | 40 | (when-let [^String name (-> s (.split "/") last)] |
38 | 41 | (first (.split name "\\.")))) |
39 | 42 |
|
| 43 | +(defn- escape-dquotes |
| 44 | + "Escape double quotes. Mainly to fix title so we don't get malformed metadata." |
| 45 | + [^String s] |
| 46 | + (.replaceAll s "\"" "\\\\\"")) |
| 47 | + |
40 | 48 | (defn- tidy-html |
41 | 49 | "Pass html string through JTidy for fixing it up if necessary." |
42 | 50 | [^String s] |
|
73 | 81 | (defn- do-dump |
74 | 82 | "Actual content creator." |
75 | 83 | [path title content tags] |
76 | | - (let [header (format "{:title \"%s\"\n :layout :post\n :tags %s\n :toc true}\n\n" title (vec tags))] |
| 84 | + (let [header (format "{:title \"%s\"\n :layout :post\n :tags %s\n :toc true}\n\n" |
| 85 | + (escape-dquotes title) |
| 86 | + (vec tags))] |
77 | 87 | (spit path (str header content)) |
78 | 88 | (println "Wrote" path))) |
79 | 89 |
|
|
106 | 116 | (if-let [i (first nodes)] |
107 | 117 | (let [zipper (zip/xml-zip i) |
108 | 118 | term (first (zx/xml-> zipper :category (zx/attr :term)))] |
109 | | - ;; only take int accout posts, not comments or other stuff |
| 119 | + ;; only take into accout posts, not comments or other stuff |
110 | 120 | (when (post? term) |
111 | 121 | (let [;; tags are list so we can accept multiple tags |
112 | 122 | tags (next (zx/xml-> zipper :category (zx/attr :term))) |
113 | 123 | date (first (zx/xml-> zipper :published zx/text)) |
114 | 124 | link (first (zx/xml-> zipper :link (zx/attr= :rel "alternate") (zx/attr :href))) |
115 | 125 | content (first (zx/xml-> zipper :content zx/text)) |
116 | 126 | title (first (zx/xml-> zipper :title zx/text))] |
117 | | - |
118 | 127 | (do-dump |
119 | 128 | (create-filename posts-dir date link) |
120 | 129 | title |
|
0 commit comments