cee7bd8ad62c2440c67aca21966e09dd92980d28
[gnupg-doc.git] / web / share / gpgweb.el
1 ;;; gpgweb.el --- elisp helper code for the GnuPG web pages
2
3 (require 'org-exp)
4 ;; cl-macs is required by ox-html.el but for whatever reasons not
5 ;; autoloaded.
6 (load-library "cl-macs")
7
8 (defun gpgweb-setup-project ()
9   (progn
10    (aput 'org-publish-project-alist "gpgweb-org"
11    '(:base-directory "~/s/gnupg-doc/web"
12      :base-extension "org"
13      :language "en"
14      :html-extension "html"
15      :recursive t
16      :publishing-directory "../stage"
17      :publishing-function gpgweb-org-to-html
18      :body-only t
19      :section-numbers nil
20      :tags nil
21      :with-toc nil
22      :makeindex t
23      :auto-sitemap t
24      :sitemap-title "GnuPG - Sitemap"
25      :sitemap-sort-folders "last"
26      :sitemap-file-entry-format "%t  @@html:<span id=\"smallnote\">@@(%d)@@html:</span>@@"
27      :style-include-default nil
28      :timestamp-file t
29      :html-head "<link rel=\"stylesheet\" href=\"gnupg.css\" type=\"text/css\" />"
30      :html-head-include-scripts nil))
31
32    (aput 'org-publish-project-alist "gpgweb-other"
33    '(:base-directory "."
34      :base-extension "jpg\\|png\\|css"
35      :recursive t
36      :publishing-directory "../stage"
37      :publishing-function org-publish-attachment
38      :completion-function gpgweb-upload))
39
40    (aput 'org-publish-project-alist "gpgweb"
41    '(:components ("gpgweb-org" "gpgweb-other")))))
42
43
44
45
46 (defun gpgweb-insert-header (title)
47   (goto-char (point-min))
48   (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
49 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
50                \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
51 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
52 <head>
53 <title>" title "</title>
54 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>
55 <meta name=\"title\" content=\"" title "\"/>
56 <meta name=\"generator\" content=\"Org-mode\"/>
57 <meta name=\"generated\" content=\"" generated-at "\"/>
58 <meta name=\"author\" content=\"Werner Koch\"/>
59 <meta name=\"description\" content=\"\"/>
60 <meta name=\"keywords\" content=\"\"/>
61 <link rel=\"stylesheet\" href=\"/share/site.css\" type=\"text/css\" />
62 </head>
63 <body>
64 <div id=\"header\">&nbsp;</div>
65 <div id=\"leftColumn\">
66   <nav>
67   <ul>
68     <li><a href=\"/index.html\"                 >Home</a></li>
69       <ul>
70         <li><a href=\"/features.html\" >Features</a></li>
71         <li><a href=\"/news.html\"     >News</a></li>
72         <li><a href=\"/service.html\"  >Service</a></li>
73         <li><a href=\"/legal.html\"    >Legal</a></li>
74       </ul>
75     <li><a href=\"/download/index.html\"        >Download</a></li>
76       <ul>
77         <li><a href=\"/download/integrity_check.html\"
78                                                 >Integrity&nbsp;Check</a></li>
79         <li><a href=\"/download/supported_systems.html\"
80                                                 >Supported&nbsp;Systems</a></li>
81         <li><a href=\"/download/release_notes.html\"
82                                                 >Release&nbsp;Notes</a></li>
83         <li><a href=\"/download/mirrors.html\"   >Mirrors</a></li>
84         <li><a href=\"/download/cvs_access.html\" >GIT</a></li>
85       </ul>
86     <li><a href=\"/documentation/index.html\"   >Documentation</a></li>
87       <ul>
88         <li><a href=\"/documentation/howtos.html\"       >HOWTOs</a></li>
89         <li><a href=\"/documentation/manuals.html\"      >Manuals</a></li>
90         <li><a href=\"/documentation/guides.html\"       >Guides</a></li>
91         <li><a href=\"/documentation/faqs.html\"         >FAQs</a></li>
92         <li><a href=\"/documentation/mailing-lists.html\"
93                                                  >Mailing&nbsp;Lists</a></li>
94         <li><a href=\"/documentation/sites.html\"    >Sites</a></li>
95         <li><a href=\"/documentation/bts.html\"      >Bug&nbsp;Tracker</a></li>
96       </ul>
97     <li><a href=\"/related_software/index.html\">Related software</a></li>
98       <ul>
99         <li><a href=\"/related_software/frontends.html\" >Frontends</a></li>
100         <li><a href=\"/related_software/tools.html\"     >Tools</a></li>
101         <li><a href=\"/related_software/libraries.html\" >Libraries</a></li>
102       </ul>
103     <li><a href=\"/misc/index.html\"            >Miscellaneous</a></li>
104       <ul>
105         <li><a href=\"/misc/links.html\"         >Links</a></li>
106         <li><a href=\"/misc/logo-contest.html\"  >Logo&nbsp;Contest</a></li>
107         <li><a href=\"/misc/thanks.html\"        >Thanks</a></li>
108         <li><a href=\"/misc/donations.html\"     >Donations</a></li>
109       </ul>
110     <li><a href=\"/privacy-policy.html\"        >Privacy Policy</a></li>
111     <li><a href=\"/sitemap.html\"               >Sitemap</a></li>
112   </ul>
113   </nav>
114 </div>
115 <main>
116 "))
117
118 (defun gpgweb-insert-footer ()
119   (goto-char (point-min))
120   (unless (search-forward "<!--disable-copyright-footer-->" nil t)
121     (goto-char (point-max))
122     (insert "<div id=\"cpyright\">
123     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
124       ><img alt=\"CC-BY-SA 3.0\" style=\"border: 0\"
125             src=\"share/cc-by-sa-3.0_80x15.png\"/></a><br/>
126     These web pages are
127     Copyright 1998--2013 The GnuPG Project<a href=\"copying.html\">ยน</a>
128     and licensed under a
129     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
130     >Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.  See
131     <a href=\"copying.html\">copying<a/> for details.
132 </div>"))
133   (goto-char (point-max))
134   (insert "
135 </main>
136 <script type=\"text/javascript\">
137   var _paq = _paq || [];
138   _paq.push([\"trackPageView\"]);
139   _paq.push([\"enableLinkTracking\"]);
140
141   (function() {
142     var u=((\"https:\" == document.location.protocol) ? \"https\" : \"http\")
143             + \"://alberti.gnupg.org/piwik/\";
144     _paq.push([\"setTrackerUrl\", u+\"piwik.php\"]);
145     _paq.push([\"setSiteId\", \"6\"]);
146     var d=document,
147         g=d.createElement(\"script\"),
148         s=d.getElementsByTagName(\"script\")[0];
149     g.type=\"text/javascript\";
150     g.defer=true;
151     g.async=true;
152     g.src=u+\"piwik.js\";
153     s.parentNode.insertBefore(g,s);
154   })();
155 </script>
156 </body>
157 </html>
158 "))
159
160 ;;; Post-process the generated HTML file:
161 ;;;
162 ;;; - Insert header and footer
163 ;;; - Insert "class=selected" into the active menu entry
164 ;;; - Fixup sitemap.
165 (defun gpgweb-postprocess-html (plist orgfile htmlfile)
166   (let* ((visitingp (find-buffer-visiting htmlfile))
167          (work-buffer (or visitingp (find-file-noselect htmlfile))))
168     (prog1 (with-current-buffer work-buffer
169              (let ((fname (file-name-nondirectory htmlfile))
170                    (fname-2 (replace-regexp-in-string
171                              ".*/stage\\(/.*\\)$" "\\1" htmlfile t))
172                    (title (org-publish-find-title orgfile))
173                    (generated-at (org-today))
174                    (tmppnt))
175                ;; Insert the header and mark the active menu
176                (gpgweb-insert-header title)
177                (setq tmppnt (point))
178                (goto-char (point-min))
179                (while (re-search-forward
180                        (concat "href=\"" (regexp-quote fname-2) "\"")
181                        tmppnt t)
182                  (replace-match "\\& class=\"selected\"" t))
183
184                ; Insert the footer
185                (gpgweb-insert-footer)
186
187                ; Fixup the sitemap
188                (when (string-equal fname "sitemap.html")
189                  (goto-char (point-min))
190                  (while (re-search-forward
191                          "^.*<li>.*>\\(GnuPG - \\).*<span.*$" nil t)
192                    (replace-match "" t nil nil 1)))
193                (basic-save-buffer))
194       (unless visitingp (kill-buffer work-buffer))))))
195
196 ;;;
197 ;;; The publishing function used by the HTML exporter
198 ;;;
199 (defun gpgweb-org-to-html (plist filename pub-dir)
200   (gpgweb-postprocess-html plist filename
201                            (org-html-publish-to-html plist filename pub-dir)))
202
203
204 (defun gpgweb-upload ()
205   (let ((stagedir (plist-get project-plist :publishing-directory)))
206     (message "gpgweb  rootdir '%s'" gpgweb-root-dir)
207     (message "gpgweb stagedir '%s'" stagedir)
208     (shell-command
209      (concat "cd " gpgweb-root-dir " && cd " stagedir
210              "&& rsync -rlt --exclude \"*~\" ./ "
211              "werner@trithemius.gnupg.org:"
212              "/var/www/www/w3.gnupg.org/htdocs/"))))
213
214
215 (provide 'gpgweb)
216
217 ;; commit 6f5180bd9fc230a31913cbdb9a4dd48cc247adc2
218 ;; Author: Rick Frankel <rick@rickster.com>
219 ;; Date:   Wed Oct 2 18:26:27 2013 -0400
220 ;;
221 ;;     Fix escaping of links in html export.
222 ;;
223 ;;     * lisp/ox-html.el (org-html-link): Unescape org-escaped links an
224 ;;       re-escape for html (browser).
225 ;;
226 ;;
227 ;; diff --git a/lisp/ox-html.el b/lisp/ox-html.el
228 ;; index 66862bc..0600204 100644
229 ;; --- a/lisp/ox-html.el
230 ;; +++ b/lisp/ox-html.el
231 ;; @@ -2624,7 +2624,9 @@ INFO is a plist holding contextual information.  See
232 ;;          (path
233 ;;           (cond
234 ;;            ((member type '("http" "https" "ftp" "mailto"))
235 ;; -           (concat type ":" raw-path))
236 ;; +           (org-link-escape
237 ;; +            (org-link-unescape
238 ;; +             (concat type ":" raw-path)) org-link-escape-chars-browser))
239 ;;            ((string= type "file")
240 ;;             ;; Treat links to ".org" files as ".html", if needed.
241 ;;             (setq raw-path