Indicate the current selection in the navigation menu.
[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=\"/sitemap.html\"               >Sitemap</a></li>
111   </ul>
112   </nav>
113 </div>
114 <main>
115 "))
116
117 (defun gpgweb-insert-footer ()
118   (goto-char (point-min))
119   (unless (search-forward "<!--disable-copyright-footer-->" nil t)
120     (goto-char (point-max))
121     (insert "<div id=\"cpyright\">
122     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
123       ><img alt=\"CC-BY-SA 3.0\" style=\"border: 0\"
124             src=\"share/cc-by-sa-3.0_80x15.png\"/></a><br/>
125     These web pages are
126     Copyright 1998--2013 The GnuPG Project<a href=\"copying.html\">ยน</a>
127     and licensed under a
128     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
129     >Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.  See
130     <a href=\"copying.html\">copying<a/> for details.
131 </div>"))
132   (goto-char (point-max))
133   (insert "
134 </main>
135 </body>
136 </html>
137 "))
138
139 ;;; Post-process the generated HTML file:
140 ;;;
141 ;;; - Insert header and footer
142 ;;; - Insert "class=selected" into the active menu entry
143 ;;; - Fixup sitemap.
144 (defun gpgweb-postprocess-html (plist orgfile htmlfile)
145   (let* ((visitingp (find-buffer-visiting htmlfile))
146          (work-buffer (or visitingp (find-file-noselect htmlfile))))
147     (prog1 (with-current-buffer work-buffer
148              (let ((fname (file-name-nondirectory htmlfile))
149                    (fname-2 (replace-regexp-in-string
150                              ".*/stage\\(/.*\\)$" "\\1" htmlfile t))
151                    (title (org-publish-find-title orgfile))
152                    (generated-at (org-today))
153                    (tmppnt))
154                ;; Insert the header and mark the active menu
155                (gpgweb-insert-header title)
156                (setq tmppnt (point))
157                (goto-char (point-min))
158                (while (re-search-forward
159                        (concat "href=\"" (regexp-quote fname-2) "\"")
160                        tmppnt t)
161                  (replace-match "\\& class=\"selected\"" t))
162
163                ; Insert the footer
164                (gpgweb-insert-footer)
165
166                ; Fixup the sitemap
167                (when (string-equal fname "sitemap.html")
168                  (goto-char (point-min))
169                  (while (re-search-forward
170                          "^.*<li>.*>\\(GnuPG - \\).*<span.*$" nil t)
171                    (replace-match "" t nil nil 1)))
172                (basic-save-buffer))
173       (unless visitingp (kill-buffer work-buffer))))))
174
175 ;;;
176 ;;; The publishing function used by the HTML exporter
177 ;;;
178 (defun gpgweb-org-to-html (plist filename pub-dir)
179   (gpgweb-postprocess-html plist filename
180                            (org-html-publish-to-html plist filename pub-dir)))
181
182
183 (defun gpgweb-upload ()
184   (let ((stagedir (plist-get project-plist :publishing-directory)))
185     (message "gpgweb  rootdir '%s'" gpgweb-root-dir)
186     (message "gpgweb stagedir '%s'" stagedir)
187     (shell-command
188      (concat "cd " gpgweb-root-dir " && cd " stagedir
189              "&& rsync -rlt --exclude \"*~\" ./ "
190              "werner@trithemius.gnupg.org:"
191              "/var/www/www/w3.gnupg.org/htdocs/"))))
192
193
194 (provide 'gpgweb)
195
196 ;; commit 6f5180bd9fc230a31913cbdb9a4dd48cc247adc2
197 ;; Author: Rick Frankel <rick@rickster.com>
198 ;; Date:   Wed Oct 2 18:26:27 2013 -0400
199 ;;
200 ;;     Fix escaping of links in html export.
201 ;;
202 ;;     * lisp/ox-html.el (org-html-link): Unescape org-escaped links an
203 ;;       re-escape for html (browser).
204 ;;
205 ;;
206 ;; diff --git a/lisp/ox-html.el b/lisp/ox-html.el
207 ;; index 66862bc..0600204 100644
208 ;; --- a/lisp/ox-html.el
209 ;; +++ b/lisp/ox-html.el
210 ;; @@ -2624,7 +2624,9 @@ INFO is a plist holding contextual information.  See
211 ;;          (path
212 ;;           (cond
213 ;;            ((member type '("http" "https" "ftp" "mailto"))
214 ;; -           (concat type ":" raw-path))
215 ;; +           (org-link-escape
216 ;; +            (org-link-unescape
217 ;; +             (concat type ":" raw-path)) org-link-escape-chars-browser))
218 ;;            ((string= type "file")
219 ;;             ;; Treat links to ".org" files as ".html", if needed.
220 ;;             (setq raw-path