Skip to content

Commit b795ff2

Browse files
committed
Merge pull request #20 from mdorman/update_for_org_changes
Update for org changes
2 parents 39b64d4 + e6b4671 commit b795ff2

File tree

5 files changed

+103
-79
lines changed

5 files changed

+103
-79
lines changed

TODO.org

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,41 @@
1+
* DONE Make it so the tests only prompt for the test blog password once
2+
That's the only thing that annoys me about running the tests right now.
3+
* DONE Convert to be compatible with the Org 8.0 exporter
4+
I have no idea what will be involved---our own sub-exporter of html?
5+
* DONE Fix date issues once and for all
6+
Added some tests to make the failure repeatable, then fixed the
7+
issue. The fix is admittedly a hack, but it would appear to be a
8+
reliable one, at least until WP changes its output.
9+
* DONE Fix line break behavior
110
* TODO Automate mirroring the post into a directory heirarchy
2-
311
Starting from the permalink (at least in WordPress), you could
412
easily construct a filename to save under, rooted under a directory
513
you specify. We could give the option for posting to automatically
614
prompt to save the file in that spot as well.
7-
815
* TODO Packaging for MELPA or whatever
9-
1016
I don't use the Emacs packaging tools, so I don't really know what's
1117
involved. I presume it's simple.
12-
13-
* DONE Make it so the tests only prompt for the test blog password once
14-
15-
That's the only thing that annoys me about running the tests right now.
16-
1718
* TODO Autocompletion of categories or tags
18-
1919
One thing I appreciated about org2blog (though it's implementation
2020
had some warts).
21-
22-
* DONE Convert to be compatible with the Org 8.0 exporter
23-
24-
I have no idea what will be involved---our own sub-exporter of html?
25-
2621
* TODO More testing
27-
2822
I really want this to be rock-solid, so testing some of the more
2923
perverse permutations of things would be nice, to make sure they
3024
work as intended.
31-
3225
* TODO More back-ends
33-
3426
It's not that I love WordPress, really. I would love to see other
3527
options supported---perhaps even static blogging options. I think
3628
I've kept things sufficiently open to allow that.
37-
3829
* TODO More idiomatic, better code
39-
4030
It's my first Emacs project, what do you expect?
41-
4231
* TODO A customize interface
43-
4432
I don't use it myself, really, but it would be a very nice thing.
4533
I'm fairly certain that everything necessary could be done that way,
4634
so it would be mighty cool.
47-
4835
* TODO More automation for setup
49-
5036
It should be possible, in theory, to be given the URL of a blog
5137
(true for WP, and I imagine for others) and have it autodiscover the
5238
posting interface, prompt for username and password, and retrieve
5339
whatever else it needs and then save it somewhere for the user to
5440
use. Gets around the =:blog-id= sort of stuff, or even having to
5541
know about =xmlrpc.php=.
56-
57-
* DONE Fix date issues once and for all
58-
Added some tests to make the failure repeatable, then fixed the
59-
issue. The fix is admittedly a hack, but it would appear to be a
60-
reliable one, at least until WP changes its output.
61-
* DONE Fix line break behavior

acceptance

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh -e
2-
IFS= read -r -p 'Please enter blog password: ' PASSWORD
3-
exec emacs -nw -Q -L /usr/share/emacs/site-lisp/org-mode -L . -l ert -l org-blog --eval '(setq xml-rpc-debug 10)' --eval "(setq org-blog-test-password \"${PASSWORD}\")" --eval '(ert t)'
2+
exec emacs -nw -Q -L /usr/share/emacs/site-lisp/org-mode -L . -l org-blog -l ert --eval "(setq org-blog-test-password \"${PASSWORD}\")" --eval '(setq xml-rpc-debug 10)' --eval '(setq stack-trace-on-error t)' --eval '(ert t)'
3+

org-blog-buffer.el

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,24 @@
2323
(provide 'org-blog-buffer)
2424

2525
(require 'org)
26+
(require 'org-blog)
2627
(require 'ox)
2728
(require 'ox-html)
28-
(require 'org-blog)
2929

3030
(eval-when-compile
3131
(require 'cl))
3232

3333
(defconst org-blog-buffer-options-alist
3434
(reduce
3535
(lambda (l i)
36-
(let ((field (plist-get (cdr i) :attr)))
36+
(let ((field (plist-get (cdr i) :to-buffer)))
37+
;; Only add our fields, distinguised by the POST_ prefix
3738
(if (string-prefix-p "POST_" field t)
3839
(cons (list (car i) field nil nil t) l)
3940
l)))
4041
org-blog-post-mapping
4142
:initial-value nil))
4243

43-
(org-export-define-derived-backend 'blog 'html
44-
:filters-alist '((:filter-final-output . org-blog-filter-tag-newline)
45-
(:filter-plain-text . org-blog-filter-text-newlines))
46-
:options-alist org-blog-buffer-options-alist)
47-
4844
;;; Filters
4945
(defun org-blog-filter-tag-newline (content backend info)
5046
"Remove superfluous leading space and trailing newlines from tags
@@ -53,26 +49,38 @@ TREE is the parse tree being exported. BACKEND is the export
5349
back-end used. INFO is a plist used as a communication channel.
5450
5551
Assume BACKEND is `blog'."
56-
;; (print (format "content is: %s" content))
5752
;; <tag>, </tag>, <tag/>, (replace-regexp-in-string "\\(<\\([[:alpha:]]+\\|/[[:alpha:]]+\\|[[:alpha:]]+/\\)>\\)\n+" "\\1" content)
5853
(replace-regexp-in-string "\s*\\(<[^>]+>\\)\n+" "\\1" content))
5954

60-
;;; Filters
6155
(defun org-blog-filter-text-newlines (content backend info)
6256
"Remove superfluous newlines in elements (except verse blocks)
6357
6458
TREE is the parse tree being exported. BACKEND is the export
6559
back-end used. INFO is a plist used as a communication channel.
6660
6761
Assume BACKEND is `blog'."
68-
;; (print (format "content is: %s" content))
69-
(print (format "parent is %s" (org-export-get-parent content)))
7062
(cond ((eq 'verse-block (car (org-export-get-parent content)))
71-
(print "in verse")
7263
content)
7364
(t
7465
(replace-regexp-in-string "\n" " " content))))
7566

67+
(defun org-blog-translate-link (link content info)
68+
"Fixup links"
69+
(let ((type (org-element-property :type link)))
70+
(cond ((member type '("custom-id" "id"))
71+
(let ((destination (org-export-resolve-id-link link info)))
72+
(format "<a href=\"%s\">%s</a>" destination contents)))
73+
((equal type "fuzzy")
74+
;; This is not ideal
75+
(let ((destination (org-element-property :path link)))
76+
(format "<a href=\"%s\">%s</a>" destination contents))))))
77+
78+
(org-export-define-derived-backend 'blog 'html
79+
:filters-alist '((:filter-final-output . org-blog-filter-tag-newline)
80+
(:filter-plain-text . org-blog-filter-text-newlines))
81+
:options-alist org-blog-buffer-options-alist
82+
:translate-alist '((link . org-blog-translate-link)))
83+
7684
(defun org-blog-buffer-extract-post ()
7785
"Transform a buffer into a post.
7886
@@ -89,12 +97,16 @@ retain the maximum flexibility for further transformation."
8997
(sort
9098
(reduce
9199
(lambda (l i)
92-
(let ((v (plist-get attrs (car i)))
93-
(filter (plist-get (cdr i) :from-buffer)))
94-
(if v
95-
(cons (cons (car i) (if filter
96-
(funcall filter v attrs)
97-
v)) l)
100+
(let* ((v (plist-get attrs (car i)))
101+
(filter (plist-get (cdr i) :from-buffer))
102+
(value (if (and v
103+
(not (= 0 (length v))))
104+
(if filter
105+
(funcall filter v attrs)
106+
v))))
107+
;; We should only cons if there's a v and the output of the filter is non-nil
108+
(if value
109+
(cons (cons (car i) value) l)
98110
l)))
99111
org-blog-post-mapping
100112
:initial-value (when content
@@ -111,6 +123,7 @@ update the buffer to reflect the values it contains."
111123
(save-restriction
112124
;; Get the current values
113125
(let ((current (org-blog-buffer-extract-post)))
126+
;; Iterate over the stuff to merge in
114127
(mapc
115128
(lambda (item)
116129
(let ((k (car item))
@@ -129,16 +142,24 @@ update the buffer to reflect the values it contains."
129142
"default")))
130143
(goto-char (point-min))
131144
(cond
132-
;; Inserting a new keyword
145+
;; No existing value associated with keyword
133146
((eq (cdr (assq k current)) nil)
134147
(when val
135-
(insert (concat "#+" (plist-get (cdr (assq k org-blog-post-mapping)) :attr) ": " val "\n"))))
136-
;; Updating an existing keyword
148+
(insert (concat "#+" (plist-get (cdr (assq k org-blog-post-mapping)) :to-buffer) ": " val "\n"))))
149+
;; Existing value associated with keyword does not match new value
137150
((not (equal (cdr (assq k current)) val))
138-
(let ((re (org-make-options-regexp (list (plist-get (cdr (assq k org-blog-post-mapping)) :attr)) nil))
151+
;; Prepare to search for the keyword
152+
(let ((re (org-make-options-regexp (list (plist-get (cdr (assq k org-blog-post-mapping)) :to-buffer)) nil))
139153
(case-fold-search t))
140-
(re-search-forward re nil t)
141-
(replace-match (concat "#+" (plist-get (cdr (assq k org-blog-post-mapping)) :attr) ": " val) t t)))))))
154+
(cond
155+
;; If it was found
156+
((re-search-forward re nil t)
157+
(message "Updating existing value with %s" val)
158+
(replace-match (concat "#+" (plist-get (cdr (assq k org-blog-post-mapping)) :to-buffer) ": " val) t t)
159+
(message "Done replacing value"))
160+
;; It was not found
161+
(val
162+
(insert (concat "#+" (plist-get (cdr (assq k org-blog-post-mapping)) :to-buffer) ": " val "\n"))))))))))
142163
;; Reverse sort fields to insert alphabetically
143164
(sort
144165
(copy-alist merge)
@@ -176,10 +197,12 @@ retain
176197
its line
177198
breaks
178199
#+END_VERSE
200+
201+
[[org-blog-buffer.el][There's a link in here, too]]
179202
")
180203
(post-struct '((:blog . "t1b")
181204
(:category "t1c1" "t1c2")
182-
(:content . "<p>Just a little bit of content. There is still part of the paragraph. Line breaks are refolded.</p><p class=\"verse\">Though the material in verse should<br/>retain<br/>its line<br/>breaks<br/></p>")
205+
(:content . "<p>Just a little bit of content. There is still part of the paragraph. Line breaks are refolded.</p><p class=\"verse\">Though the material in verse should<br/>retain<br/>its line<br/>breaks<br/></p><p><a href=\"org-blog-buffer.el\">There's a link in here, too</a></p>")
183206
(:date 20738 4432)
184207
(:description . "t1e")
185208
(:id . "1")

org-blog-wp.el

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,13 @@ function to make other calls."
184184
((equal (length userblogs) 1)
185185
(setcdr (assq :xmlrpc complete) (cdr (assoc "xmlrpc" (car userblogs))))
186186
(cdr (assoc "blogid" (car userblogs))))
187-
;; FIXME: Prompt the user from the list of blogs (if there's more than 1
188-
;; Then shove the blog info into complete
187+
;; If there's mroe than one blog, ask the user to choose from them
189188
(t
190189
(reduce
191-
(lambda (entry)
192-
(when (string= (cdr (assoc "blogName" entry)))
193-
(setcdr (assq :xmlrpc complete) (cdr (assoc "xmlrpc" userblog)))
194-
(cdr (assoc "blogid" userblog))))
190+
(lambda (chosen entry)
191+
(when (string= (cdr (assoc "blogName" result)) (cdr (assoc "blogName" entry)))
192+
(setcdr (assq :xmlrpc complete) (cdr (assoc "xmlrpc" entry)))
193+
(cdr (assoc "blogid" entry))))
195194
userblogs
196195
:initial-value (completing-read
197196
"Blog Name: "

org-blog.el

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,48 @@ Each loaded back-end should add its name to the list.")
5555
(defun org-blog-property-strip (v i)
5656
"Strip properties from a property string."
5757
(when v
58-
(set-text-properties 0 (length v) nil v)
59-
v))
58+
;; If we got a list, only do the head
59+
(when (listp v)
60+
(message "Saw list value for %s" v)
61+
(setq v (car v)))
62+
;; (message "Setting text properties on %s" v)
63+
(let ((clean (substring-no-properties v)))
64+
;; (message "Doing string match on %s" v)
65+
(unless (string-match "^\s*$" clean)
66+
;; (message "Found non-whitespace characters")
67+
clean))))
6068

6169
(defun org-blog-date-format (v i)
6270
"Properly format a date."
63-
(date-to-time
64-
(org-export-get-date i "%Y%m%dT%T%z")))
65-
66-
(defconst org-blog-post-mapping '((:blog :attr "POST_BLOG" :from-buffer org-blog-property-strip)
67-
(:category :attr "POST_CATEGORY" :from-buffer org-blog-property-split)
68-
(:date :attr "DATE" :from-buffer org-blog-date-format)
69-
(:description :attr "DESCRIPTION" :from-buffer org-blog-property-strip)
70-
(:id :attr "POST_ID" :from-buffer org-blog-property-strip)
71-
(:keywords :attr "KEYWORDS" :from-buffer org-blog-property-split)
72-
(:link :attr "POST_LINK" :from-buffer org-blog-property-strip)
73-
(:name :attr "POST_NAME" :from-buffer org-blog-property-strip)
74-
(:parent :attr "POST_PARENT" :from-buffer org-blog-property-strip)
75-
(:status :attr "POST_STATUS" :from-buffer org-blog-property-strip)
76-
(:title :attr "TITLE" :from-buffer (lambda (v i) (org-blog-property-strip (car v) i)))
77-
(:type :attr "POST_TYPE" :from-buffer org-blog-property-strip)))
71+
(when v
72+
(date-to-time
73+
(org-export-get-date i "%Y%m%dT%T%z"))))
74+
75+
(defun org-blog-title-format (value info)
76+
"Properly format a title."
77+
(let ((default (or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
78+
(and visited-file
79+
(file-name-sans-extension
80+
(file-name-nondirectory visited-file))))
81+
(buffer-name (buffer-base-buffer))))
82+
(val (org-element-interpret-data (plist-get info :title) info)))
83+
(cond ((equal default val)
84+
nil)
85+
(t
86+
val))))
87+
88+
(defconst org-blog-post-mapping '((:blog :to-buffer "POST_BLOG" :from-buffer org-blog-property-strip)
89+
(:category :to-buffer "POST_CATEGORY" :from-buffer org-blog-property-split)
90+
(:date :to-buffer "DATE" :from-buffer org-blog-date-format)
91+
(:description :to-buffer "DESCRIPTION" :from-buffer org-blog-property-strip)
92+
(:id :to-buffer "POST_ID" :from-buffer org-blog-property-strip)
93+
(:keywords :to-buffer "KEYWORDS" :from-buffer org-blog-property-split)
94+
(:link :to-buffer "POST_LINK" :from-buffer org-blog-property-strip)
95+
(:name :to-buffer "POST_NAME" :from-buffer org-blog-property-strip)
96+
(:parent :to-buffer "POST_PARENT" :from-buffer org-blog-property-strip)
97+
(:status :to-buffer "POST_STATUS" :from-buffer org-blog-property-strip)
98+
(:title :to-buffer "TITLE" :from-buffer org-blog-title-format)
99+
(:type :to-buffer "POST_TYPE" :from-buffer org-blog-property-strip)))
78100

79101
(require 'org-blog-buffer)
80102
(require 'org-blog-wp)

0 commit comments

Comments
 (0)