|
@@ -5,7 +5,10 @@
|
5
|
5
|
(:use :cl)
|
6
|
6
|
(:import-from :coleslaw
|
7
|
7
|
:*config*
|
8
|
|
- :publish)
|
|
8
|
+ :deploy
|
|
9
|
+ :get-updated-files
|
|
10
|
+ :page-url
|
|
11
|
+ :plugin-conf-error)
|
9
|
12
|
(:export #:enable))
|
10
|
13
|
|
11
|
14
|
(in-package :coleslaw-twitter)
|
|
@@ -28,19 +31,25 @@
|
28
|
31
|
(when tweet-format
|
29
|
32
|
(setf *tweet-format* tweet-format)))
|
30
|
33
|
|
31
|
|
-(defmethod publish :after (post (eql (find-class 'coleslaw:post)))
|
32
|
|
- (format-post post))
|
33
|
34
|
|
34
|
|
-(defun format-post (post)
|
35
|
|
- "Take a post and return a string of 140 character length, at most. Urls have 23 len and are a must."
|
36
|
|
- (chirp:statuses/update (%format-post post)))
|
|
35
|
+(defmethod deploy :after (staging)
|
|
36
|
+ (declare (ignore staging))
|
|
37
|
+ (loop :for (state file) :in (get-updated-files)
|
|
38
|
+ :when (and (string= "A" state) (string= "post" (pathname-type file)))
|
|
39
|
+ :do (tweet-new-post file)))
|
|
40
|
+
|
|
41
|
+(defun tweet-new-post (file)
|
|
42
|
+ "Retrieve most recent post from in memory DB and publish it."
|
|
43
|
+ (let ((post (coleslaw::find-content-by-path file)))
|
|
44
|
+ (chirp:statuses/update (%format-post 0 post))))
|
37
|
45
|
|
38
|
46
|
(defun %format-post (offset post)
|
39
|
|
- "Guarantee that the tweet content is 140 chars at most."
|
|
47
|
+ "Guarantee that the tweet content is 140 chars at most. The 117 comes from
|
|
48
|
+the spaxe needed for a space and the url."
|
40
|
49
|
(let* ((content-prefix (subseq (render-tweet post) 0 (- 117 offset)))
|
41
|
50
|
(content (format nil "~A ~A/~A" content-prefix
|
42
|
51
|
(coleslaw::domain *config*)
|
43
|
|
- (coleslaw:page-url post)))
|
|
52
|
+ (page-url post)))
|
44
|
53
|
(content-length (chirp:compute-status-length content)))
|
45
|
54
|
(cond
|
46
|
55
|
((>= 140 content-length) content)
|