Adjust for org-mode 8.0
[gnupg-doc.git] / web / share / gpgweb.el
1 ;;; gpgweb.el --- elisp helper code for the GnuPG web pages
2
3 (require 'org-exp)
4
5 (defun gpgweb-setup-project ()
6   (progn
7    (aput 'org-publish-project-alist "gpgweb-org"
8    '(:base-directory "~/s/gnupg-doc/web"
9      :base-extension "org"
10      :language "en"
11      :html-extension "html"
12      :recursive t
13      :publishing-directory "../stage"
14      :publishing-function gpgweb-org-to-html
15      :body-only t
16      :section-numbers nil
17      :tags nil
18      :with-toc nil
19      :makeindex t
20      :auto-sitemap t
21      :sitemap-title "GnuPG - Sitemap"
22      :style-include-default nil
23      :timestamp-file t
24      :html-head "<link rel=\"stylesheet\" href=\"gnupg.css\" type=\"text/css\" />"
25      :html-head-include-scripts nil))
26
27    (aput 'org-publish-project-alist "gpgweb-other"
28    '(:base-directory "."
29      :base-extension "jpg\\|png\\|css"
30      :recursive t
31      :publishing-directory "../stage"
32      :publishing-function org-publish-attachment
33      :completion-function gpgweb-upload))
34
35    (aput 'org-publish-project-alist "gpgweb"
36    '(:components ("gpgweb-org" "gpgweb-other")))))
37
38
39 (defun gpgweb-insert-header (title)
40   (goto-char (point-min))
41   (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
42 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
43                \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
44 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
45 <head>
46 <title>" title "</title>
47 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>
48 <meta name=\"title\" content=\"" title "\"/>
49 <meta name=\"generator\" content=\"Org-mode\"/>
50 <meta name=\"generated\" content=\"" generated-at "\"/>
51 <meta name=\"author\" content=\"Werner Koch\"/>
52 <meta name=\"description\" content=\"\"/>
53 <meta name=\"keywords\" content=\"\"/>
54 <link rel=\"stylesheet\" href=\"/share/site.css\" type=\"text/css\" />
55 </head>
56 <body>
57 <div id=\"header\">&nbsp;</div>
58 <div id=\"leftColumn\">
59   <nav>
60   <ul>
61     <li><a href=\"/index.html\"                 >Home</a></li>
62       <ul>
63         <li><a href=\"/features.html\" >Features</a></li>
64         <li><a href=\"/news.html\"     >News</a></li>
65         <li><a href=\"/service.html\"  >Service</a></li>
66         <li><a href=\"/legal.html\"    >Legal</a></li>
67       </ul>
68     <li><a href=\"/download/index.html\"        >Download</a></li>
69       <ul>
70         <li><a href=\"/download/integrity_check.html\"
71                                                 >Integrity&nbsp;Check</a></li>
72         <li><a href=\"/download/supported_systems.html\"
73                                                 >Supported&nbsp;Systems</a></li>
74         <li><a href=\"/download/release_notes.html\"
75                                                 >Release&nbsp;Notes</a></li>
76         <li><a href=\"/download/mirrors.html\"   >Mirrors</a></li>
77         <li><a href=\"/download/cvs_access.html\" >GIT</a></li>
78       </ul>
79     <li><a href=\"/documentation/index.html\"   >Documentation</a></li>
80       <ul>
81         <li><a href=\"/documentation/howtos.html\"       >HOWTOs</a></li>
82         <li><a href=\"/documentation/manuals.html\"      >Manuals</a></li>
83         <li><a href=\"/documentation/guides.html\"       >Guides</a></li>
84         <li><a href=\"/documentation/faqs.html\"         >FAQs</a></li>
85         <li><a href=\"/documentation/mailing-lists.html\"
86                                                  >Mailing&nbsp;Lists</a></li>
87         <li><a href=\"/documentation/sites.html\"    >Sites</a></li>
88         <li><a href=\"/documentation/bts.html\"      >Bug&nbsp;Tracker</a></li>
89       </ul>
90     <li><a href=\"/related_software/index.html\">Related software</a></li>
91       <ul>
92         <li><a href=\"/related_software/frontends.html\" >Frontends</a></li>
93         <li><a href=\"/related_software/tools.html\"     >Tools</a></li>
94         <li><a href=\"/related_software/libraries.html\" >Libraries</a></li>
95       </ul>
96     <li><a href=\"/misc/index.html\"            >Miscellaneous</a></li>
97       <ul>
98         <li><a href=\"/misc/links.html\"         >Links</a></li>
99         <li><a href=\"/misc/logo-contest.html\"  >Logo&nbsp;Contest</a></li>
100         <li><a href=\"/misc/thanks.html\"        >Thanks</a></li>
101         <li><a href=\"/misc/donations.html\"     >Donations</a></li>
102       </ul>
103     <li><a href=\"/sitemap.html\"               >Sitemap</a></li>
104   </ul>
105   </nav>
106 </div>
107 <main>
108 "))
109
110 (defun gpgweb-insert-footer ()
111   (goto-char (point-max))
112   (insert "<div id=\"cpyright\">
113     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
114       ><img alt=\"CC-BY-SA 3.0\" style=\"border: 0\"
115             src=\"share/cc-by-sa-3.0_80x15.png\"/></a><br/>
116     These web pages are
117     Copyright 1998--2013 The GnuPG Project<a href=\"copying.html\">ยน</a>
118     and licensed under a
119     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
120     >Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.  See
121     <a href=\"copying.html\">copying<a/> for details.
122     </div>
123 </main>
124 </body>
125 </html>
126 "))
127
128
129 ;; Our publishing tweaks:
130 ;;
131 ;; - Substitute @FNAME@ by the actual file name.
132 ;; - Substitute @MENU-ACTIVE@ by an empty string.
133 (defun gpgweb-postprocess-html (plist orgfile htmlfile)
134   (let* ((visitingp (find-buffer-visiting htmlfile))
135          (work-buffer (or visitingp (find-file-noselect htmlfile))))
136     (prog1 (with-current-buffer work-buffer
137              (let ((fname (file-name-nondirectory htmlfile))
138                    (title (org-publish-find-title orgfile))
139                    (generated-at (org-today)))
140                (message "post processing %s (%s)" htmlfile orgfile)
141                (gpgweb-insert-header title)
142                (gpgweb-insert-footer)
143                (when (string-match "\\.\\([a-z][a-z]\\.\\)?html$" fname)
144                  (setq fname (substring fname 0 (match-beginning 0))))
145                (goto-char (point-min))
146                (while (search-forward "href=\"@FNAME@" nil t)
147                  (replace-match (concat "href=\"" ) t nil))
148                (goto-char (point-min))
149                (while (search-forward "@MENU-ACTIVE@" nil t)
150                  (replace-match "" t nil)))
151              (basic-save-buffer))
152       (unless visitingp (kill-buffer work-buffer)))))
153
154
155 (defun gpgweb-org-to-html (plist filename pub-dir)
156   (gpgweb-postprocess-html plist filename
157                            (org-html-publish-to-html plist filename pub-dir)))
158
159 (defun gpgweb-upload ()
160   (let ((stagedir (plist-get project-plist :publishing-directory)))
161     (message "gpgweb  rootdir '%s'" gpgweb-root-dir)
162     (message "gpgweb stagedir '%s'" stagedir)
163     (shell-command
164      (concat "cd " gpgweb-root-dir " && cd " stagedir
165              "&& rsync -rlt --exclude \"*~\" ./ "
166              "werner@trithemius.gnupg.org:"
167              "/var/www/www/w3.gnupg.org/htdocs/"))))
168
169
170 (provide 'gpgweb)