doc: Move "Commit Access" section from 'HACKING' to the manual.
[jackhill/guix/guix.git] / doc / build.scm
index 5bc95d2..e171b53 100644 (file)
 (define info-manual
   (@@ (guix self) info-manual))
 
+(define %manual
+  ;; The manual to build--i.e., the base name of a .texi file, such as "guix"
+  ;; or "guix-cookbook".
+  (or (getenv "GUIX_MANUAL")
+      "guix"))
+
 (define %languages
   '("de" "en" "es" "fr" "ru" "zh_CN"))
 
@@ -164,7 +170,9 @@ as well as images, OS examples, and translations."
 
 (define %makeinfo-html-options
   ;; Options passed to 'makeinfo --html'.
-  '("--css-ref=https://www.gnu.org/software/gnulib/manual.css"))
+  '("--css-ref=https://www.gnu.org/software/gnulib/manual.css"
+    "-c" "EXTRA_HEAD=<meta name=\"viewport\" \
+content=\"width=device-width, initial-scale=1\" />"))
 
 (define guile-lib/htmlprag-fixed
   ;; Guile-Lib with a hotfix for (htmlprag).
@@ -215,9 +223,62 @@ its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
                          (ice-9 match)
                          (ice-9 threads))
 
+            (define (pair-open/close lst)
+              ;; Pair 'open' and 'close' tags produced by 'highlights' and
+              ;; produce nested 'paren' tags instead.
+              (let loop ((lst lst)
+                         (level 0)
+                         (result '()))
+                (match lst
+                  ((('open open) rest ...)
+                   (call-with-values
+                       (lambda ()
+                         (loop rest (+ 1 level) '()))
+                     (lambda (inner close rest)
+                       (loop rest level
+                             (cons `(paren ,level ,open ,inner ,close)
+                                   result)))))
+                  ((('close str) rest ...)
+                   (if (> level 0)
+                       (values (reverse result) str rest)
+                       (begin
+                         (format (current-error-port)
+                                 "warning: extra closing paren; context:~% ~y~%"
+                                 (reverse result))
+                         (loop rest 0 (cons `(close ,str) result)))))
+                  ((item rest ...)
+                   (loop rest level (cons item result)))
+                  (()
+                   (when (> level 0)
+                     (format (current-error-port)
+                             "warning: missing ~a closing parens; context:~% ~y%"
+                             level (reverse result)))
+                   (values (reverse result) "" '())))))
+
+            (define (highlights->sxml* highlights)
+              ;; Like 'highlights->sxml', but handle nested 'paren tags.  This
+              ;; allows for paren matching highlights via appropriate CSS
+              ;; "hover" properties.
+              (define (tag->class tag)
+                (string-append "syntax-" (symbol->string tag)))
+
+              (map (match-lambda
+                     ((? string? str) str)
+                     (('paren level open (body ...) close)
+                      `(span (@ (class ,(string-append "syntax-paren"
+                                                       (number->string level))))
+                             ,open
+                             (span (@ (class "syntax-symbol"))
+                                   ,@(highlights->sxml* body))
+                             ,close))
+                     ((tag text)
+                      `(span (@ (class ,(tag->class tag))) ,text)))
+                   highlights))
+
             (define entity->string
               (match-lambda
                 ("rArr"   "⇒")
+                ("rarr"   "→")
                 ("hellip" "…")
                 ("rsquo"  "’")
                 (e (pk 'unknown-entity e) (primitive-exit 2))))
@@ -252,9 +313,10 @@ its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
                                  (href #$syntax-css-url)))))
                 (('pre ('@ ('class "lisp")) code-snippet ...)
                  `(pre (@ (class "lisp"))
-                       ,(highlights->sxml
-                         (highlight lex-scheme
-                                    (concatenate-snippets code-snippet)))))
+                       ,@(highlights->sxml*
+                          (pair-open/close
+                           (highlight lex-scheme
+                                      (concatenate-snippets code-snippet))))))
                 ((tag ('@ attributes ...) body ...)
                  `(,tag (@ ,@attributes) ,@(map syntax-highlight body)))
                 ((tag body ...)
@@ -306,7 +368,7 @@ its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
 
 (define* (html-manual source #:key (languages %languages)
                       (version "0.0")
-                      (manual "guix")
+                      (manual %manual)
                       (date 1)
                       (options %makeinfo-html-options))
   "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
@@ -333,6 +395,13 @@ makeinfo OPTIONS."
                           (chr chr))
                         (string-downcase language)))
 
+          (define (language->texi-file-name language)
+            (if (string=? language "en")
+                (string-append #$manual-source "/"
+                               #$manual ".texi")
+                (string-append #$manual-source "/"
+                               #$manual "." language ".texi")))
+
           ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
           (setenv "GUIX_LOCPATH"
                   #+(file-append glibc-utf8-locales "/lib/locale"))
@@ -342,15 +411,12 @@ makeinfo OPTIONS."
           (setvbuf (current-error-port) 'line)
 
           (for-each (lambda (language)
-                      (let ((opts `("--html"
-                                    "-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
+                      (let* ((texi (language->texi-file-name language))
+                             (opts `("--html"
+                                     "-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
                                                          language)
-                                    #$@options
-                                    ,(if (string=? language "en")
-                                         (string-append #$manual-source "/"
-                                                        #$manual ".texi")
-                                         (string-append #$manual-source "/"
-                                                        #$manual "." language ".texi")))))
+                                     #$@options
+                                     ,texi)))
                         (format #t "building HTML manual for language '~a'...~%"
                                 language)
                         (mkdir-p (string-append #$output "/"
@@ -380,7 +446,8 @@ makeinfo OPTIONS."
                         (symlink #$images
                                  (string-append #$output "/" (normalize language)
                                                 "/html_node/images"))))
-                    '#$languages))))
+                    (filter (compose file-exists? language->texi-file-name)
+                            '#$languages)))))
 
   (let* ((name   (string-append manual "-html-manual"))
          (manual (computed-file name build)))
@@ -389,7 +456,7 @@ makeinfo OPTIONS."
 
 (define* (pdf-manual source #:key (languages %languages)
                      (version "0.0")
-                     (manual "guix")
+                     (manual %manual)
                      (date 1)
                      (options '()))
   "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
@@ -517,7 +584,10 @@ from SOURCE."
 (define* (html-manual-indexes source
                               #:key (languages %languages)
                               (version "0.0")
-                              (manual "guix")
+                              (manual %manual)
+                              (title (if (string=? "guix" manual)
+                                         "GNU Guix Reference Manual"
+                                         "GNU Guix Cookbook"))
                               (date 1))
   (define build
     (with-extensions (list guile-json-3)
@@ -621,7 +691,7 @@ from SOURCE."
 
             (define (language-index language)
               (define title
-                (translate "GNU Guix Reference Manual" language))
+                (translate #$title language))
 
               (sxml-index
                language title
@@ -679,8 +749,7 @@ from SOURCE."
                     %iso639-languages)))
 
             (define (top-level-index languages)
-              (define title
-                "GNU Guix Reference Manual")
+              (define title #$title)
               (sxml-index
                "en" title
                `(main
@@ -688,7 +757,7 @@ from SOURCE."
                   (@ (class "page centered-block limit-width"))
                   (h2 ,title)
                   (div
-                   "The GNU Guix Reference Manual is available in the following
+                   "This document is available in the following
 languages:\n"
                    (ul
                     ,@(map (lambda (language)
@@ -729,7 +798,7 @@ languages:\n"
                           #:key (languages %languages)
                           (version "0.0")
                           (date (time-second (current-time time-utc)))
-                          (manual "guix"))
+                          (manual %manual))
   "Return the union of the HTML and PDF manuals, as well as the indexes."
   (directory-union (string-append manual "-manual")
                    (map (lambda (proc)