Update http -> https where appropriate
[website] / validate.el
1 ;; validate.el --- Lisp code to validate SXEmacs web pages   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2008 - 2016 Steve Youngs
4
5 ;; Author:     Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created:    <2008-09-19>
8 ;; Homepage:   https://www.sxemacs.org/
9 ;; Keywords:   validate web html util
10
11 ;; This file is part of nothing really.
12
13 ;; Redistribution and use in source and binary forms, with or without
14 ;; modification, are permitted provided that the following conditions
15 ;; are met:
16 ;;
17 ;; 1. Redistributions of source code must retain the above copyright
18 ;;    notice, this list of conditions and the following disclaimer.
19 ;;
20 ;; 2. Redistributions in binary form must reproduce the above copyright
21 ;;    notice, this list of conditions and the following disclaimer in the
22 ;;    documentation and/or other materials provided with the distribution.
23 ;;
24 ;; 3. Neither the name of the author nor the names of any contributors
25 ;;    may be used to endorse or promote products derived from this
26 ;;    software without specific prior written permission.
27 ;;
28 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
29 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 ;;; Commentary:
41 ;; 
42 ;;   This is some ugly lisp that is used to validate the SXEmacs web
43 ;;   pages locally with PSGML
44
45 ;;; Todo:
46 ;;
47 ;;     Make it work!
48 ;;     OK, it works, now make it ugly-less
49
50 ;;; Expected Errors
51 ;;
52 ;;   Because we do some fancy things with SSI's and variable
53 ;;   substitution it can sometimes be impossible to validate some
54 ;;   of these pages locally.  Here is a list of expected errors
55 ;;   that you'll see when validating locally...
56 ;;
57 ;; onsgmls:SXEweb-nOHIVR:74:8:E: literal is missing closing delimiter
58 ;; onsgmls:SXEweb-nOHIVR:78:8:E: literal is missing closing delimiter
59 ;; onsgmls:SXEweb-nOHIVR:78:140:E: end tag for element "a" which is not open
60 ;;
61 ;;   Those 3 errors are caused by the "inline shell-script snippets"
62 ;;   we have for generating some dynamic content. onsgmls just can't
63 ;;   cope with them.  They can be safely ignored.
64 ;;
65 ;;   Don't bother trying to validate any of these files...
66 ;;     404.html
67 ;;     canvas.html
68 ;;     rpc_relay.html
69 ;;
70
71 ;;; Code:
72 (defun validate ()
73   "Validate the sxemacs html doc in the current buffer."
74   (interactive)
75   (let* ((vd (temp-directory))
76          (vf (make-temp-name (expand-file-name "SXEweb-" vd)))
77          (sf (buffer-file-name))
78          (td (file-name-as-directory
79               (expand-file-name "templates" (file-dirname sf)))))
80     ;; templates might be in .. rather than .
81     (and (file-directory-p (expand-file-name "../templates" (file-dirname sf)))
82          (setq td (file-name-as-directory
83                    (expand-file-name "../templates" (file-dirname sf)))))
84     (with-current-buffer (get-buffer-create vf)
85       (erase-buffer)
86       (insert-file-contents-literally sf) ; does that move point?
87       (goto-char (point-min))
88       (re-search-forward #r"support\.template\" -->" nil t)
89       (forward-line 1)
90       (insert-file (expand-file-name "support.template" td))
91       (insert-file (expand-file-name "menu.template" td))
92       (insert-file (expand-file-name "header.template" td))
93       (goto-char (point-max))
94       (insert-file (expand-file-name "footer.template" td))
95       (insert-file (expand-file-name "stats.template" td))
96       (insert-file (expand-file-name "copyright.template" td))
97       (while (re-search-backward #r"<!--#echo var=\"css\" -->" nil t)
98         (replace-match "sxemacs.css"))
99       (write-region (point-min) (point-max) vf))
100     (find-file vf)
101     (sgml-parse-prolog)
102     (sleep-for 5)
103     (sgml-validate (sgml-default-validate-command))))
104
105 ;;; validate.el ends here