-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates.org
78 lines (76 loc) · 3.44 KB
/
templates.org
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
#+name: inline-js
#+begin_src elisp :exports none :results html :var blk=""
(concat
"<script type=\"text/javascript\">\n"
(cadr (org-babel-lob--src-info blk))
"\n"
"</script>")
#+end_src
#+name: compileOrgFiles
#+begin_src elisp :exports none :results none :var path="./articles/"
(setq timeToArchiveInMonth 4
timeToArchiveInMonthSeconds (* timeToArchiveInMonth 2592000)
)
(mapc
(lambda (f) (progn
(when (time-less-p (time-add (current-time) (- 0 timeToArchiveInMonthSeconds )) (nth 5 (file-attributes f)))
(message "compile org file %s" f)
(find-file f)
(org-twbs-export-to-html)
(kill-buffer)
)))
(directory-files path t "\.org$"))
(mapc
(lambda (f) (progn
(when (time-less-p (time-add (current-time) (- 0 timeToArchiveInMonthSeconds )) (nth 5 (file-attributes f)))
(message "post compilation processing - file %s" f)
(find-file f)
(while (re-search-forward "<span style=\"color: #262626; background-color: #0d0d0d;\">\\([ ]*\\)</span>" nil t)
(replace-match "\\1"))
(save-buffer)
(kill-buffer)
)))
(directory-files path t "\.html$"))
#+end_src
#+name: articlesRelativePaths
#+begin_src elisp :exports none :results html
(progn
(defun ListToJsArray (elist varName)
(setq almostJSVar (seq-reduce (lambda (acc content)(concat acc "\"" content "\"" ",")) elist (concat "var " varName " = ["))
almostJSVarLeng (length almostJSVar)
)
(concat (substring almostJSVar 0 (- almostJSVarLeng 1)) "];")
)
(setq
filePaths (mapcar (lambda (fileName) (concat "./articles/" fileName))
(directory-files "./articles/" nil "\.html$"))
fileContents (mapcar (lambda (filePath) (with-temp-buffer
(insert-file-contents filePath)
(search-forward "outline-container-Article")
(beginning-of-line)
(kill-region (point-min) (point))
(search-forward "outline-container-ShareButtons")
(beginning-of-line)
(kill-region (point) (point-max))
(goto-char (point-min))
(replace-string "/" "\\/")
(goto-char (point-min))
(replace-string "\n" "")
(goto-char (point-min))
(replace-string "'" "\\'")
(goto-char (point-min))
(replace-string "\"" "\\\"")
(buffer-string)
)
)
filePaths)
)
(concat
"<script type=\"text/javascript\">\n"
(ListToJsArray (reverse fileContents) "htmlArticles")
"\n"
(ListToJsArray (reverse filePaths) "htmlArticlesPaths")
"\n"
"</script>")
)
#+end_src