Web: Use a dedicated exporter backend.
[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   "Set up an org-publish project for the gnupg.org website."
7   (progn
8    (require 'ox-gpgweb (concat gpgweb-root-dir "share/ox-gpgweb.el"))
9    (aput 'org-publish-project-alist "gpgweb-org"
10    '(:base-directory "~/s/gnupg-doc/web"
11      :base-extension "org"
12      :language "en"
13      :html-extension "html"
14      :recursive t
15      :publishing-directory "../stage"
16      :publishing-function gpgweb-org-to-html
17      :body-only t
18      :section-numbers nil
19      :tags nil
20      :with-toc nil
21      :makeindex t
22      :auto-sitemap nil
23      :sitemap-title "GnuPG - Sitemap"
24      :sitemap-sort-folders "last"
25      :sitemap-file-entry-format "%t  @@html:<span id=\"smallnote\">@@(%d)@@html:</span>@@"
26      :style-include-default nil
27      :timestamp-file nil
28      :html-head "<link rel=\"stylesheet\" href=\"gnupg.css\" type=\"text/css\" />"
29      :html-head-include-scripts nil))
30
31    (aput 'org-publish-project-alist "gpgweb-other"
32    '(:base-directory "."
33      :base-extension "jpg\\|png\\|css\\|txt\\|rss\\|lst\\|sig"
34      :recursive t
35      :publishing-directory "../stage"
36      :publishing-function org-publish-attachment
37      :completion-function gpgweb-upload))
38
39    (aput 'org-publish-project-alist "gpgweb"
40    '(:components ("gpgweb-org" "gpgweb-other")))))
41
42
43 (defun gpgweb-insert-header (title generated-at)
44   (goto-char (point-min))
45   (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>
46 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
47                \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
48 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
49 <head>
50 <title>" title "</title>
51 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>
52 <meta name=\"DC.Language\" content=\"en\" />
53 <meta name=\"DC.Title\" content=\"" title "\"/>
54 <meta name=\"DC.Description\"
55  content=\"GnuPG is a free implementation of OpenPGP\" />
56 <meta name=\"DC.Creator\" content=\"The People of the GnuPG Project\" />
57 <meta name=\"DC.Publisher\" content=\"The GnuPG Project\" />
58 <meta name=\"DC.Date\" content=\""
59   (format-time-string "%Y-%m-%d" generated-at t) "\" />
60 <meta name=\"DC.Identifier\" content=\"https://gnupg.org/\" />
61 <meta name=\"DC.Rights\" content=\"https://gnupg.org/copying.html\" />
62 <link rel=\"stylesheet\" href=\"/share/site.css\" type=\"text/css\" />
63 </head>
64 <body>\n"))
65
66 (defun gpgweb-insert-menu ()
67   (goto-char (point-min))
68   (when (re-search-forward "^<body>\n" nil t)
69     (insert "<div id=\"header\">&nbsp;</div>
70 <div id=\"leftColumn\">
71   <nav>
72   <ul>
73     <li><a href=\"/index.html\"                 >Home</a></li>
74       <ul>
75         <li><a href=\"/features.html\" >Features</a></li>
76         <li><a href=\"/news.html\"     >News</a></li>
77         <li><a href=\"/service.html\"  >Service</a></li>
78       </ul>
79     <li><a href=\"/donate/index.html\"          >Donate</a></li>
80       <ul>
81         <li><a href=\"/donate/kudos.html\" >List of Donors</a></li>
82       </ul>
83     <li><a href=\"/download/index.html\"        >Download</a></li>
84       <ul>
85         <li><a href=\"/download/integrity_check.html\"
86                                                 >Integrity&nbsp;Check</a></li>
87         <li><a href=\"/download/supported_systems.html\"
88                                                 >Supported&nbsp;Systems</a></li>
89         <li><a href=\"/download/release_notes.html\"
90                                                 >Release&nbsp;Notes</a></li>
91         <li><a href=\"/download/mirrors.html\"   >Mirrors</a></li>
92         <li><a href=\"/download/cvs_access.html\" >GIT</a></li>
93       </ul>
94     <li><a href=\"/documentation/index.html\"   >Documentation</a></li>
95       <ul>
96         <li><a href=\"/documentation/howtos.html\"       >HOWTOs</a></li>
97         <li><a href=\"/documentation/manuals.html\"      >Manuals</a></li>
98         <li><a href=\"/documentation/guides.html\"       >Guides</a></li>
99         <li><a href=\"/documentation/faqs.html\"         >FAQs</a></li>
100         <li><a href=\"/documentation/mailing-lists.html\"
101                                                  >Mailing&nbsp;Lists</a></li>
102         <li><a href=\"/documentation/sites.html\"    >Sites</a></li>
103         <li><a href=\"/documentation/bts.html\"      >Bug&nbsp;Tracker</a></li>
104       </ul>
105     <li><a href=\"/related_software/index.html\">Related software</a></li>
106       <ul>
107         <li><a href=\"/related_software/frontends.html\" >Frontends</a></li>
108         <li><a href=\"/related_software/tools.html\"     >Tools</a></li>
109         <li><a href=\"/related_software/libraries.html\" >Libraries</a></li>
110         <li><a href=\"/related_software/swlist.html\"    >All</a></li>
111       </ul>
112     <li><a href=\"/blog/index.html\"            >Blog</a></li>
113     <li><a href=\"/privacy-policy.html\"        >Privacy Policy</a></li>
114     <li><a href=\"/misc/index.html\"            >Archive</a></li>
115     <li><a href=\"/sitemap.html\"               >Sitemap</a></li>
116   </ul>
117   </nav>
118 </div>
119 <main>
120 ")))
121
122 (defun gpgweb-insert-footer ()
123   (goto-char (point-min))
124   (unless (search-forward "<!--disable-copyright-footer-->" nil t)
125     (goto-char (point-max))
126     (insert "<div id=\"cpyright\">
127     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
128       ><img alt=\"CC-BY-SA 3.0\" style=\"border: 0\"
129             src=\"/share/cc-by-sa-3.0_80x15.png\"/></a><br/>
130     These web pages are
131     Copyright 1998--2014 The GnuPG Project<a href=\"/copying.html\">ยน</a>
132     and licensed under a
133     <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\"
134     >Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.  See
135     <a href=\"/copying.html\">copying</a> for details.
136 </div>
137 </main>
138 </body>
139 </html>")))
140
141
142 ;;; Post-process the generated HTML file:
143 ;;;
144 ;;; - Insert header and footer
145 ;;; - Insert "class=selected" into the active menu entry
146 ;;; - Fixup sitemap.
147 (defun gpgweb-postprocess-html (plist orgfile htmlfile)
148   (let* ((visitingp (find-buffer-visiting htmlfile))
149          (work-buffer (or visitingp (find-file-noselect htmlfile))))
150     (prog1 (with-current-buffer work-buffer
151              (let ((fname (file-name-nondirectory htmlfile))
152                    (fname-2 (replace-regexp-in-string
153                              ".*/stage\\(/.*\\)$" "\\1" htmlfile t))
154                    (title (org-publish-find-title orgfile))
155                    (generated-at (current-time))
156                    (tmppnt))
157                ;; Insert the header and mark the active menu
158                (gpgweb-insert-header title generated-at)
159                (gpgweb-insert-menu)
160                (setq tmppnt (point))
161                (goto-char (point-min))
162                (while (re-search-forward
163                        (concat "href=\"" (regexp-quote fname-2) "\"")
164                        tmppnt t)
165                  (replace-match "\\& class=\"selected\"" t))
166
167                ; Insert the footer
168                (gpgweb-insert-footer)
169
170                ; Fixup the sitemap
171                (when (string-equal fname "sitemap.html")
172                  (goto-char (point-min))
173                  (while (re-search-forward
174                          "^.*<li>.*>\\(GnuPG - \\).*<span.*$" nil t)
175                    (replace-match "" t nil nil 1)))
176
177                ; Due to a problem with the current org exporter (cases
178                ; were we link to file mapped via a webserver alias) we
179                ; have to use a full URL at some places in the org
180                ; source.  We fix that up here.
181                (goto-char (point-min))
182                (while (re-search-forward
183                        "href=\"\\(https://www.gnupg.org\\)/.*\"" nil t)
184                  (replace-match "" t t nil 1))
185
186                ; And save the changes
187                (basic-save-buffer))
188       (unless visitingp (kill-buffer work-buffer))))))
189
190 ;;;
191 ;;; The publishing function used by the HTML exporter
192 ;;;
193 (defun gpgweb-org-to-html (plist filename pub-dir)
194   (gpgweb-postprocess-html plist filename
195                            (org-gpgweb-publish-to-html plist filename pub-dir)))
196
197
198 (defun gpgweb-upload ()
199   (let ((stagedir (plist-get project-plist :publishing-directory)))
200     (message "gpgweb  rootdir '%s'" gpgweb-root-dir)
201     (message "gpgweb stagedir '%s'" stagedir)
202     (shell-command
203      (concat "cd " gpgweb-root-dir " && cd " stagedir
204              "&& rsync -rlt --exclude \"*~\" ./ "
205              "werner@trithemius.gnupg.org:"
206              "/var/www/www/www.gnupg.org/htdocs/ ;"
207              " ssh werner@trithemius.gnupg.org"
208              " touch /var/www/www/www.gnupg.org/htdocs/donate/donors.dat"))
209 ))
210
211 (provide 'gpgweb)