-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheasy-jekyll.el
2152 lines (1980 loc) · 83.5 KB
/
easy-jekyll.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; easy-jekyll.el --- Major mode managing jekyll blogs -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2021 by Masashi Miyaura
;; Author: Masashi Miyaura
;; URL: https://github.com/masasam/emacs-easy-jekyll
;; Version: 2.6.30
;; Package-Requires: ((emacs "25.1") (request "0.3.0"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Emacs major mode for writing blogs made with jekyll
;; You can publish your blog to the server or Github Pages
;; or Amazon S3 or Google Cloud Storage.
;;; Code:
(require 'cl-lib)
(require 'url)
(require 'request)
(defgroup easy-jekyll nil
"Major mode managing jekyll blogs."
:group 'tools)
(defgroup easy-jekyll-faces nil
"Faces used in `easy-jekyll'"
:group 'easy-jekyll :group 'faces)
(defcustom easy-jekyll-basedir nil
"Directory where jekyll html source code is placed."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-preview-url "http://localhost:4000/"
"Preview url of `easy-jekyll'."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-serve-flags ""
"Additional flags to pass to jekyll serve."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-serve-flags2 ""
"Additional flags to pass to jekyll serve."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-serve-value ""
"Additional value to pass to jekyll serve."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-serve-value2 ""
"Additional value to pass to jekyll serve."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-url nil
"Url of the site operated by jekyll."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-sshdomain nil
"Domain of jekyll at your ~/.ssh/config."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-root nil
"Root directory of jekyll at your server."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-previewtime 300
"Preview display time."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-image-directory "images"
"Image file directory under 'static' directory."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-default-picture-directory "~"
"Default directory for selecting images with `easy-jekyll-put-image'."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-amazon-s3-bucket-name nil
"Amazon S3 bucket name."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-google-cloud-storage-bucket-name nil
"Google Cloud Storage bucket name."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-default-ext ".md"
"Default extension when posting new articles."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-helm-ag nil
"Helm-ag use flg."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-no-help nil
"No help flg of `easy-jekyll'."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-emacspeak nil
"Emacspeak flg of `easy-jekyll'."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-additional-help nil
"Additional help flg of `easy-jekyll'."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-sort-default-char t
"Default setting to sort with charactor."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-publish-production nil
"Flag to publish by setting environment 'JEKYLL_ENV' variable to production."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-publish-chmod "Du=rwx,Dgo=rx,Fu=rw,Fog=r"
"Permission when publish.
The default is drwxr-xr-x."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-github-deploy-script "deploy.sh"
"Github-deploy-script file name."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-markdown-extension "md"
"Markdown extension."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-textile-extension "textile"
"Textile extension."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-postdir "_posts"
"Directory where stores its posts."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-additional-postdir nil
"Additional directory where stores its markdown files."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-rsync-delete-directory "_site/"
"Disappear directory when synchronizing with rsync."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-rsync-flags "-rtpl"
"Additional flags for rsync."
:group 'easy-jekyll
:type 'string)
(defcustom easy-jekyll-post-layout "post"
"Default layout for a new post."
:group 'easy-jekyll
:type 'string
)
(defcustom easy-jekyll-help-line 7
"Number of lines of `easy-jekyll-help'."
:group 'easy-jekyll
:type 'integer)
(defcustom easy-jekyll-add-help-line 6
"Number of lines of `easy-jekyll-add-help'."
:group 'easy-jekyll
:type 'integer)
(defvar easy-jekyll--current-postdir 0
"Easy-jekyll current postdir.")
(defvar easy-jekyll--postdir-list nil
"Easy-jekyll postdir list.")
(defvar easy-jekyll--preview-loop t
"Preview loop flg.")
(defvar easy-jekyll--server-process nil
"Jekyll process.")
(if easy-jekyll-no-help
(defvar easy-jekyll--unmovable-line 3
"Impossible to move below this line.")
(defvar easy-jekyll--unmovable-line (+ easy-jekyll-help-line 4)
"Impossible to move below this line."))
(defvar easy-jekyll--draft-list nil
"Draft list flg.")
(defvar easy-jekyll--draft-mode nil
"Display draft-mode.")
(defconst easy-jekyll--unmovable-line-default (+ easy-jekyll-help-line 4)
"Default value of impossible to move below this line.")
(defconst easy-jekyll--buffer-name "*Jekyll Serve*"
"Easy-jekyll buffer name.")
(defconst easy-jekyll--preview-buffer "*Jekyll Preview*"
"Easy-jekyll preview buffer name.")
(defconst easy-jekyll--formats `(,easy-jekyll-markdown-extension
,easy-jekyll-textile-extension))
(defface easy-jekyll-help-face
`((((class color) (background light))
,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-function-name-face
:background "#f0f8ff")
(((class color) (background dark))
,@(and (>= emacs-major-version 27) '(:extend t))
:inherit font-lock-function-name-face
:background "#2f4f4f"))
"Definition of help color."
:group 'easy-jekyll-faces)
(defvar easy-jekyll--mode-buffer nil
"Main buffer of `easy-jekyll'.")
(defvar easy-jekyll--cursor nil
"Cursor of `easy-jekyll'.")
(defvar easy-jekyll--line nil
"Line of `easy-jekyll'.")
(defvar easy-jekyll--sort-time-flg nil
"Sort time flg of `easy-jekyll'.")
(defvar easy-jekyll--sort-char-flg 2
"Sort char flg of `easy-jekyll'.")
(defvar easy-jekyll--refresh nil
"Refresh flg of `easy-jekyll'.")
(defvar easy-jekyll--current-blog 0
"Current blog number.")
(defcustom easy-jekyll-bloglist nil
"Multiple blog setting."
:group 'easy-jekyll
:type 'string)
(push `((easy-jekyll-basedir . ,easy-jekyll-basedir)
(easy-jekyll-url . ,easy-jekyll-url)
(easy-jekyll-root . ,easy-jekyll-root)
(easy-jekyll-sshdomain . ,easy-jekyll-sshdomain)
(easy-jekyll-amazon-s3-bucket-name . ,easy-jekyll-amazon-s3-bucket-name)
(easy-jekyll-google-cloud-storage-bucket-name . ,easy-jekyll-google-cloud-storage-bucket-name)
(easy-jekyll-github-deploy-script . ,easy-jekyll-github-deploy-script)
(easy-jekyll-image-directory . ,easy-jekyll-image-directory)
(easy-jekyll-default-picture-directory . ,easy-jekyll-default-picture-directory)
(easy-jekyll-publish-chmod . ,easy-jekyll-publish-chmod)
(easy-jekyll-previewtime . ,easy-jekyll-previewtime)
(easy-jekyll-preview-url . ,easy-jekyll-preview-url)
(easy-jekyll-sort-default-char . ,easy-jekyll-sort-default-char)
(easy-jekyll-textile-extension . ,easy-jekyll-textile-extension)
(easy-jekyll-markdown-extension . ,easy-jekyll-markdown-extension)
(easy-jekyll-default-ext . ,easy-jekyll-default-ext)
(easy-jekyll-postdir . ,easy-jekyll-postdir)
(easy-jekyll-additional-postdir . ,easy-jekyll-additional-postdir))
easy-jekyll-bloglist)
(defvar easy-jekyll--publish-timer-list
(make-list (length easy-jekyll-bloglist) 'nil)
"Timer list for cancel publish timer.")
(defvar easy-jekyll--firebase-deploy-timer-list
(make-list (length easy-jekyll-bloglist) 'nil)
"Timer list for cancel firebase deploy timer.")
(defvar easy-jekyll--github-deploy-timer-list
(make-list (length easy-jekyll-bloglist) 'nil)
"Timer list for cancel github deploy timer.")
(defvar easy-jekyll--amazon-s3-deploy-timer-list
(make-list (length easy-jekyll-bloglist) 'nil)
"Timer list for cancel amazon s3 deploy timer.")
(defvar easy-jekyll--google-cloud-storage-deploy-timer-list
(make-list (length easy-jekyll-bloglist) 'nil)
"Timer list for cancel google cloud storage deploy timer.")
(defconst easy-jekyll--default-github-deploy-script
"deploy.sh"
"Default `easy-jekyll' github-deploy-script.")
(defconst easy-jekyll--default-image-directory
"images"
"Default `easy-jekyll' image-directory.")
(defconst easy-jekyll--default-picture-directory
"~"
"Default `easy-jekyll' picture-directory.")
(defconst easy-jekyll--default-publish-chmod
"Du=rwx,Dgo=rx,Fu=rw,Fog=r"
"Default `easy-jekyll' publish-chmod.")
(defconst easy-jekyll--default-previewtime
300
"Default `easy-jekyll' previewtime.")
(defconst easy-jekyll--default-preview-url
"http://localhost:4000/"
"Default `easy-jekyll' preview-url.")
(defconst easy-jekyll--default-sort-default-char
t
"Default `easy-jekyll' sort-default-char.")
(defconst easy-jekyll--default-textile-extension
"textile"
"Default `easy-jekyll' textile-extension.")
(defconst easy-jekyll--default-markdown-extension
"md"
"Default `easy-jekyll' markdown-extension.")
(defconst easy-jekyll--default-postdir
"_posts"
"Default `easy-jekyll-postdir'.")
(defconst easy-jekyll--default-additional-postdir
nil
"Default `easy-jekyll-additional-postdir'.")
(defconst easy-jekyll--default-ext
easy-jekyll-default-ext
"Default `easy-jekyll' default-ext.")
(defconst easy-jekyll--buffer-name "*Easy-jekyll*"
"Buffer name of `easy-jekyll'.")
(defconst easy-jekyll--forward-char 20
"Forward-char of `easy-jekyll'.")
(defmacro easy-jekyll-with-env (&rest body)
"Evaluate BODY with `default-directory' set to `easy-jekyll-basedir'.
Report an error if jekyll is not installed, or if `easy-jekyll-basedir' is unset."
`(progn
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(unless (executable-find "jekyll")
(error "'jekyll' is not installed"))
(let ((default-directory easy-jekyll-basedir))
,@body)))
(defmacro easy-jekyll-set-bloglist (body)
"Macros to set variables to `easy-jekyll-bloglist' as BODY."
`(setq ,body
(cdr (assoc ',body
(nth easy-jekyll--current-blog easy-jekyll-bloglist)))))
(defmacro easy-jekyll-eval-bloglist (body)
"Macros to eval variables of BODY from `easy-jekyll-bloglist'."
`(cdr (assoc ',body
(nth easy-jekyll--current-blog easy-jekyll-bloglist))))
(defmacro easy-jekyll-nth-eval-bloglist (body blog)
"Macros to eval variables of BODY from `easy-jekyll-bloglist' at BLOG."
`(cdr (assoc ',body
(nth ,blog easy-jekyll-bloglist))))
(defmacro easy-jekyll-ignore-error (condition &rest body)
"Execute BODY; if the error CONDITION occurs, return nil.
Otherwise, return result of last form in BODY.
CONDITION can also be a list of error conditions."
(declare (debug t) (indent 1))
`(condition-case nil (progn ,@body) (,condition nil)))
;;;###autoload
(defun easy-jekyll-article ()
"Open a list of articles written in jekyll with dired."
(interactive)
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(find-file (expand-file-name easy-jekyll-postdir easy-jekyll-basedir)))
;;;###autoload
(defun easy-jekyll-magit ()
"Open magit at current blog."
(interactive)
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(if (require 'magit nil t)
(magit-status-internal easy-jekyll-basedir)
(error "'magit' is not installed")))
(defun easy-jekyll-emacspeak-filename ()
"Read filename with emacspeak."
(cl-declare (special emacspeak-speak-last-spoken-word-position))
(let ((filename (substring (thing-at-point 'line) easy-jekyll--forward-char -1))
(personality (dtk-get-style)))
(cond
(filename
(dtk-speak (propertize filename 'personality personality))
(setq emacspeak-speak-last-spoken-word-position (point)))
(t (emacspeak-speak-line)))))
;;;###autoload
(defun easy-jekyll-image ()
"Generate image link."
(interactive
(easy-jekyll-with-env
(unless (file-directory-p (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir))
(error "%s does not exist" (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir)))
(let ((insert-default-directory nil))
(let ((file (read-file-name "Image file: " nil
(expand-file-name
easy-jekyll-image-directory easy-jekyll-basedir)
t
(expand-file-name
easy-jekyll-image-directory easy-jekyll-basedir))))
(insert (concat (format "<img src=\"%s%s\""
easy-jekyll-url
(concat
"/"
easy-jekyll-image-directory
"/"
(file-name-nondirectory file)))
" alt=\"\" width=\"100%\"/>")))))))
;;;###autoload
(defun easy-jekyll-put-image ()
"Move image to image directory and generate image link."
(interactive
(easy-jekyll-with-env
(unless (file-directory-p (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir))
(error "%s does not exist" (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir)))
(let ((insert-default-directory nil))
(let* ((file (read-file-name "Image file: " nil
(expand-file-name easy-jekyll-default-picture-directory)
t
(expand-file-name easy-jekyll-default-picture-directory)))
(putfile (expand-file-name
(file-name-nondirectory file)
easy-jekyll-image-directory)))
(when (file-exists-p putfile)
(error "%s already exists!" putfile))
(copy-file file putfile)
(insert (concat (format "<img src=\"%s%s\""
easy-jekyll-url
(concat
"/"
easy-jekyll-image-directory
"/"
(file-name-nondirectory file)))
" alt=\"\" width=\"100%\"/>")))))))
(defun easy-jekyll--request-image (url file)
"Resuest image from URL and save file at the location of FILE."
(request
url
:parser 'buffer-string
:success
(cl-function (lambda (&key data &allow-other-keys)
(when data
(with-current-buffer (get-buffer-create "*request image*")
(erase-buffer)
(insert data)
(write-file file)))))
:error
(cl-function (lambda (&rest args &key error-thrown &allow-other-keys)
(message "Got error: %S" error-thrown)))))
;;;###autoload
(defun easy-jekyll-pull-image ()
"Pull image from internet to image directory and generate image link."
(interactive
(easy-jekyll-with-env
(unless (file-directory-p (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir))
(error "%s does not exist" (expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir)))
(let ((url (read-string "URL: " (if (fboundp 'gui-get-selection)
(gui-get-selection))))
(file (read-file-name "Save as: "
(expand-file-name
easy-jekyll-image-directory
easy-jekyll-basedir)
(car (last (split-string
(substring-no-properties (gui-get-selection))
"/")))
nil)))
(when (file-exists-p (file-truename file))
(error "%s already exists!" (file-truename file)))
(easy-jekyll--request-image url file)
(insert (concat (format "<img src=\"%s%s\""
easy-jekyll-url
(concat
"/"
easy-jekyll-image-directory
"/"
(file-name-nondirectory file)))
" alt=\"\" width=\"100%\"/>"))))))
;;;###autoload
(defun easy-jekyll-publish-clever ()
"Clever publish command.
Automatically select the deployment destination from init.el."
(interactive)
(easy-jekyll-with-env
(cond ((easy-jekyll-eval-bloglist easy-jekyll-root)
(easy-jekyll-publish))
((easy-jekyll-eval-bloglist easy-jekyll-amazon-s3-bucket-name)
(easy-jekyll-amazon-s3-deploy))
((easy-jekyll-eval-bloglist easy-jekyll-google-cloud-storage-bucket-name)
(easy-jekyll-google-cloud-storage-deploy))
((executable-find (expand-file-name
(if (easy-jekyll-eval-bloglist easy-jekyll-github-deploy-script)
(easy-jekyll-eval-bloglist easy-jekyll-github-deploy-script)
easy-jekyll-github-deploy-script)
easy-jekyll-basedir))
(easy-jekyll-github-deploy))
((executable-find "firebase")
(easy-jekyll-firebase-deploy))
(t (error "Nothing is found to publish at %s" easy-jekyll-basedir)))))
;;;###autoload
(defun easy-jekyll-publish ()
"Adapt local change to the server with jekyll."
(interactive)
(unless easy-jekyll-sshdomain
(error "Please set easy-jekyll-sshdomain variable"))
(unless easy-jekyll-root
(error "Please set easy-jekyll-root variable"))
(unless (executable-find "rsync")
(error "'rsync' is not installed"))
(unless (file-exists-p "~/.ssh/config")
(error "There is no ~/.ssh/config"))
(easy-jekyll-with-env
(when (file-directory-p "_site")
(delete-directory "_site" t nil))
(when easy-jekyll-publish-production
(setenv "JEKYLL_ENV" "production"))
(let ((ret (call-process "bundle" nil "*jekyll-publish*" t
"exec" "jekyll" "build" "--destination" "_site")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-publish*"))
(error "'bundle exec jekyll build' command does not end normally")))
(when (get-buffer "*jekyll-publish*")
(kill-buffer "*jekyll-publish*"))
(let ((ret (call-process "rsync"
nil
"*jekyll-rsync*"
t
easy-jekyll-rsync-flags
(concat "--chmod=" easy-jekyll-publish-chmod)
"--delete"
easy-jekyll-rsync-delete-directory
(concat easy-jekyll-sshdomain ":" (shell-quote-argument easy-jekyll-root)))))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-rsync*"))
(error "'rsync' command does not end normally")))
(when (get-buffer "*jekyll-rsync*")
(kill-buffer "*jekyll-rsync*"))
(message "Blog published")
(when easy-jekyll-url
(browse-url easy-jekyll-url))))
;;;###autoload
(defun easy-jekyll-publish-timer (n)
"A timer that publish after the specified number as N of minutes has elapsed."
(interactive "nMinute:")
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(unless (executable-find "jekyll")
(error "'jekyll' is not installed"))
(unless easy-jekyll-sshdomain
(error "Please set easy-jekyll-sshdomain variable"))
(unless easy-jekyll-root
(error "Please set easy-jekyll-root variable"))
(unless (executable-find "rsync")
(error "'rsync' is not installed"))
(unless (file-exists-p "~/.ssh/config")
(error "There is no ~/.ssh/config"))
(let ((blognum easy-jekyll--current-blog))
(if (nth blognum easy-jekyll--publish-timer-list)
(message "There is already reserved publish-timer on %s" easy-jekyll-url)
(setf (nth easy-jekyll--current-blog easy-jekyll--publish-timer-list)
(run-at-time (* n 60) nil
#'(lambda () (easy-jekyll-publish-on-timer blognum)))))))
;;;###autoload
(defun easy-jekyll-cancel-publish-timer ()
"Cancel timer that publish after the specified number of minutes has elapsed."
(interactive)
(if (nth easy-jekyll--current-blog easy-jekyll--publish-timer-list)
(progn
(cancel-timer (nth easy-jekyll--current-blog easy-jekyll--publish-timer-list))
(setf (nth easy-jekyll--current-blog easy-jekyll--publish-timer-list) nil)
(message "Publish-timer canceled on %s" easy-jekyll-url))
(message "There is no reserved publish-timer on %s" easy-jekyll-url)))
(defun easy-jekyll-publish-on-timer (n)
"Adapt local change to the server with jekyll on timer at N."
(let ((default-directory (easy-jekyll-nth-eval-bloglist easy-jekyll-basedir n)))
(when (file-directory-p "_site")
(delete-directory "_site" t nil))
(let ((ret (call-process "bundle" nil "*jekyll-publish*" t
"exec" "jekyll" "build" "--destination" "_site")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-publish*"))
(setf (nth n easy-jekyll--publish-timer-list) nil)
(error "'bundle exec jekyll build' command does not end normally")))
(when (get-buffer "*jekyll-publish*")
(kill-buffer "*jekyll-publish*"))
(let ((ret (call-process "rsync"
nil
"*jekyll-rsync*"
t
easy-jekyll-rsync-flags
(concat "--chmod=" easy-jekyll-publish-chmod)
"--delete"
easy-jekyll-rsync-delete-directory
(concat
(easy-jekyll-nth-eval-bloglist easy-jekyll-sshdomain n)
":"
(shell-quote-argument
(easy-jekyll-nth-eval-bloglist easy-jekyll-root n))))))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-rsync*"))
(error "'rsync' command does not end normally")))
(when (get-buffer "*jekyll-rsync*")
(kill-buffer "*jekyll-rsync*"))
(message "Blog published")
(when (easy-jekyll-nth-eval-bloglist easy-jekyll-url n)
(browse-url (easy-jekyll-nth-eval-bloglist easy-jekyll-url n)))
(setf (nth n easy-jekyll--publish-timer-list) nil)))
;;;###autoload
(defun easy-jekyll-firebase-deploy ()
"Deploy jekyll source at firebase hosting."
(interactive)
(unless (executable-find "firebase")
(error "'firebase-tools' is not installed"))
(easy-jekyll-with-env
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process "bundle" nil "*jekyll-publish*" t
"exec" "jekyll" "build" "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-firebase*"))
(error "'bundle exec jekyll build' command does not end normally")))
(when (get-buffer "*jekyll-firebase*")
(kill-buffer "*jekyll-firebase*"))
(let ((ret (call-process "firebase"
nil
"*jekyll-firebase*"
t
"deploy")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-firebase*"))
(error "'firebase deploy' command does not end normally")))
(when (get-buffer "*jekyll-firebase*")
(kill-buffer "*jekyll-firebase*"))
(message "Blog published")
(when easy-jekyll-url
(browse-url easy-jekyll-url))))
;;;###autoload
(defun easy-jekyll-firebase-deploy-timer (n)
"A timer that firebase deploy after the specified number as N of minutes has elapsed."
(interactive "nMinute:")
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(unless (executable-find "jekyll")
(error "'jekyll' is not installed"))
(unless (executable-find "firebase")
(error "'firebase-tools' is not installed"))
(let ((blognum easy-jekyll--current-blog))
(if (nth blognum easy-jekyll--firebase-deploy-timer-list)
(message "There is already reserved firebase-deploy-timer on %s" easy-jekyll-url)
(setf (nth easy-jekyll--current-blog easy-jekyll--firebase-deploy-timer-list)
(run-at-time (* n 60) nil
#'(lambda () (easy-jekyll-firebase-deploy-on-timer blognum)))))))
;;;###autoload
(defun easy-jekyll-cancel-firebase-deploy-timer ()
"Cancel timer that firebase deploy after the specified number of minutes has elapsed."
(interactive)
(if (nth easy-jekyll--current-blog easy-jekyll--firebase-deploy-timer-list)
(progn
(cancel-timer (nth easy-jekyll--current-blog easy-jekyll--firebase-deploy-timer-list))
(setf (nth easy-jekyll--current-blog easy-jekyll--firebase-deploy-timer-list) nil)
(message "Firebase-deploy-timer canceled on %s" easy-jekyll-url))
(message "There is no reserved firebase-deploy-timer on %s" easy-jekyll-url)))
(defun easy-jekyll-firebase-deploy-on-timer (n)
"Deploy jekyll at firebase hosting on timer at N."
(let ((default-directory (easy-jekyll-nth-eval-bloglist easy-jekyll-basedir n)))
(when (file-directory-p "public")
(delete-directory "public" t nil))
(let ((ret (call-process "bundle" nil "*jekyll-firebase*" t
"exec" "jekyll" "build" "--destination" "public")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-firebase*"))
(setf (nth n easy-jekyll--firebase-deploy-timer-list) nil)
(error "'bundle exec jekyll build' command does not end normally")))
(when (get-buffer "*jekyll-firebase*")
(kill-buffer "*jekyll-firebase*"))
(let ((ret (call-process "firebase"
nil
"*jekyll-firebase*"
t
"deploy")))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-firebase*"))
(error "'firebase deploy' command does not end normally")))
(when (get-buffer "*jekyll-firebase*")
(kill-buffer "*jekyll-firebase*"))
(message "Blog published")
(when (easy-jekyll-nth-eval-bloglist easy-jekyll-url n)
(browse-url (easy-jekyll-nth-eval-bloglist easy-jekyll-url n)))
(setf (nth n easy-jekyll--publish-timer-list) nil)))
(defun easy-jekyll--headers (file)
"Return a draft header string for a new article as FILE."
(let ((datetimezone
(concat
(format-time-string "%Y-%m-%d %T ")
(format-time-string "%z"))))
(concat
"---"
"\nlayout: " easy-jekyll-post-layout
"\ntitle: " file
"\ndate: " datetimezone
"\n---\n")))
;;;###autoload
(defun easy-jekyll-newpost (post-file)
"Create a new post with jekyll.
POST-FILE needs to have and extension '.md' or '.textile'."
(interactive (list (read-from-minibuffer "Filename: " `(,easy-jekyll-default-ext . 1) nil nil nil)))
(easy-jekyll-with-env
(let ((filename (if easy-jekyll--draft-list
(expand-file-name post-file "_drafts")
(expand-file-name
(concat (format-time-string "%Y-%m-%d-" (current-time)) post-file)
easy-jekyll-postdir)))
(file-ext (file-name-extension post-file)))
(when (not (member file-ext easy-jekyll--formats))
(error "Please enter .%s file name or .%s file name"
easy-jekyll-markdown-extension easy-jekyll-textile-extension))
(when (file-exists-p (file-truename filename))
(error "%s already exists!" filename))
(find-file filename)
(insert (easy-jekyll--headers (file-name-base post-file)))
(goto-char (point-max))
(save-buffer))))
(defun easy-jekyll--version ()
"Return the version of jekyll."
(let ((source (split-string
(with-temp-buffer
(shell-command-to-string "bundle exec jekyll --version"))
" ")))
(string-to-number (nth 1 source))))
;;;###autoload
(defun easy-jekyll-preview ()
"Preview jekyll at localhost."
(interactive)
(easy-jekyll-with-env
(when easy-jekyll-publish-production
(setenv "JEKYLL_ENV" "development"))
(if (process-live-p easy-jekyll--server-process)
(browse-url easy-jekyll-preview-url)
(progn
(setq easy-jekyll--server-process
(start-process "jekyll-serve" easy-jekyll--preview-buffer
"bundle" "exec" "jekyll" "serve" easy-jekyll-serve-flags easy-jekyll-serve-value easy-jekyll-serve-flags2 easy-jekyll-serve-value2))
(while easy-jekyll--preview-loop
(if (equal (easy-jekyll--preview-status) "200")
(progn
(setq easy-jekyll--preview-loop nil)
(browse-url easy-jekyll-preview-url)))
(sleep-for 0 100)
(if (and (eq (process-status easy-jekyll--server-process) 'exit)
(not (equal (process-exit-status easy-jekyll--server-process) 0)))
(progn
(switch-to-buffer easy-jekyll--preview-buffer)
(error "Jekyll error look at %s buffer" easy-jekyll--preview-buffer))))
(setq easy-jekyll--preview-loop t)
(run-at-time easy-jekyll-previewtime nil 'easy-jekyll--preview-end)))))
(defun easy-jekyll--preview-status ()
"Return the http status code of the preview."
(nth 1
(split-string
(nth 0
(split-string
(with-current-buffer
(easy-jekyll--url-retrieve-synchronously "http://127.0.0.1:4000/")
(prog1
(buffer-string)
(kill-buffer)))
"\n"))
" ")))
(defun easy-jekyll--url-retrieve-synchronously (url &optional silent inhibit-cookies)
"Retrieve URL synchronously.
Return the buffer containing the data, or nil if there are no data
associated with it (the case for dired, info, or mailto URLs that need
no further processing). URL is either a string or a parsed URL.
If SILENT is non-nil, don't display progress reports and similar messages.
If INHIBIT-COOKIES is non-nil, cookies will neither be stored nor sent
to the server."
(url-do-setup)
(let ((retrieval-done nil)
(asynch-buffer nil))
(setq asynch-buffer
(url-retrieve url (lambda (&rest ignored)
(url-debug 'retrieval "Synchronous fetching done (%S)" (current-buffer))
(setq retrieval-done t
asynch-buffer (current-buffer)))
nil silent inhibit-cookies))
(if (null asynch-buffer)
;; We do not need to do anything, it was a mailto or something
;; similar that takes processing completely outside of the URL
;; package.
nil
(let ((proc (get-buffer-process asynch-buffer)))
;; If the access method was synchronous, `retrieval-done' should
;; hopefully already be set to t. If it is nil, and `proc' is also
;; nil, it implies that the async process is not running in
;; asynch-buffer. This happens e.g. for FTP files. In such a case
;; url-file.el should probably set something like a `url-process'
;; buffer-local variable so we can find the exact process that we
;; should be waiting for. In the mean time, we'll just wait for any
;; process output.
(while (not retrieval-done)
(url-debug 'retrieval
"Spinning in url-retrieve-synchronously: %S (%S)"
retrieval-done asynch-buffer)
(if (buffer-local-value 'url-redirect-buffer asynch-buffer)
(setq proc (get-buffer-process
(setq asynch-buffer
(buffer-local-value 'url-redirect-buffer
asynch-buffer))))
(if (and proc (memq (process-status proc)
'(closed exit signal failed))
;; Make sure another process hasn't been started.
(eq proc (or (get-buffer-process asynch-buffer) proc)))
;; FIXME: It's not clear whether url-retrieve's callback is
;; guaranteed to be called or not. It seems that url-http
;; decides sometimes consciously not to call it, so it's not
;; clear that it's a bug, but even then we need to decide how
;; url-http can then warn us that the download has completed.
;; In the mean time, we use this here workaround.
;; XXX: The callback must always be called. Any
;; exception is a bug that should be fixed, not worked
;; around.
(progn ;; Call delete-process so we run any sentinel now.
(delete-process proc)
(setq retrieval-done t)))
;; We used to use `sit-for' here, but in some cases it wouldn't
;; work because apparently pending keyboard input would always
;; interrupt it before it got a chance to handle process input.
;; `sleep-for' was tried but it lead to other forms of
;; hanging. --Stef
(unless (or (with-local-quit
(accept-process-output proc))
(null proc))
;; accept-process-output returned nil, maybe because the process
;; exited (and may have been replaced with another). If we got
;; a quit, just stop.
(when quit-flag
(delete-process proc))
(setq proc (and (not quit-flag)
(get-buffer-process asynch-buffer)))))))
asynch-buffer)))
(defun easy-jekyll--preview-end ()
"Finish previewing jekyll at localhost."
(unless (null easy-jekyll--server-process)
(delete-process easy-jekyll--server-process))
(when (get-buffer easy-jekyll--preview-buffer)
(kill-buffer easy-jekyll--preview-buffer)))
;;;###autoload
(defun easy-jekyll-github-deploy ()
"Execute `easy-jekyll-github-deploy-script' script locate at `easy-jekyll-basedir'."
(interactive)
(easy-jekyll-with-env
(let ((deployscript (file-truename (expand-file-name
easy-jekyll-github-deploy-script
easy-jekyll-basedir))))
(unless (executable-find deployscript)
(error "%s do not execute" deployscript))
(let ((ret (call-process
deployscript nil "*jekyll-github-deploy*" t)))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-github-deploy*"))
(error "%s command does not end normally" deployscript)))
(when (get-buffer "*jekyll-github-deploy*")
(kill-buffer "*jekyll-github-deploy*"))
(message "Blog deployed")
(when easy-jekyll-url
(browse-url easy-jekyll-url)))))
;;;###autoload
(defun easy-jekyll-github-deploy-timer (n)
"A timer that github-deploy after the specified number as N of minutes has elapsed."
(interactive "nMinute:")
(unless easy-jekyll-basedir
(error "Please set easy-jekyll-basedir variable"))
(unless (executable-find "jekyll")
(error "'jekyll' is not installed"))
(let ((deployscript (file-truename (expand-file-name
easy-jekyll-github-deploy-script
easy-jekyll-basedir)))
(blognum easy-jekyll--current-blog))
(unless (executable-find deployscript)
(error "%s do not execute" deployscript))
(if (nth blognum easy-jekyll--github-deploy-timer-list)
(message "There is already reserved github-deloy-timer on %s" easy-jekyll-url)
(setf (nth easy-jekyll--current-blog easy-jekyll--github-deploy-timer-list)
(run-at-time (* n 60) nil
#'(lambda () (easy-jekyll-github-deploy-on-timer blognum)))))))
;;;###autoload
(defun easy-jekyll-cancel-github-deploy-timer ()
"Cancel timer that github-deploy after the specified number of minutes has elapsed."
(interactive)
(if (nth easy-jekyll--current-blog easy-jekyll--github-deploy-timer-list)
(progn
(cancel-timer (nth easy-jekyll--current-blog easy-jekyll--github-deploy-timer-list))
(setf (nth easy-jekyll--current-blog easy-jekyll--github-deploy-timer-list) nil)
(message "Github-deploy-timer canceled on %s" easy-jekyll-url))
(message "There is no reserved github-deploy-timer on %s" easy-jekyll-url)))
(defun easy-jekyll-github-deploy-on-timer (n)
"Execute `easy-jekyll-github-deploy-script' script on timer locate at `easy-jekyll-basedir' at N."
(let* ((deployscript (file-truename
(expand-file-name
(if (easy-jekyll-nth-eval-bloglist easy-jekyll-github-deploy-script n)
(easy-jekyll-nth-eval-bloglist easy-jekyll-github-deploy-script n)
easy-jekyll--default-github-deploy-script)
(easy-jekyll-nth-eval-bloglist easy-jekyll-basedir n))))
(default-directory (easy-jekyll-nth-eval-bloglist easy-jekyll-basedir n))
(ret (call-process
deployscript nil "*jekyll-github-deploy*" t))
(default-directory easy-jekyll-basedir))
(unless (zerop ret)
(switch-to-buffer (get-buffer "*jekyll-github-deploy*"))
(setf (nth n easy-jekyll--github-deploy-timer-list) nil)
(error "%s command does not end normally" deployscript)))
(when (get-buffer "*jekyll-github-deploy*")
(kill-buffer "*jekyll-github-deploy*"))
(message "Blog deployed")
(when (easy-jekyll-nth-eval-bloglist easy-jekyll-url n)