1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 ;; This file contains machinery to build HTML and PDF copies of the manual
22 ;; that can be readily published on the web site. To do that, run:
24 ;; guix build -f build.scm
26 ;; The result is a directory hierarchy that can be used as the manual/
27 ;; sub-directory of the web site.
36 (gnu packages compression)
38 (gnu packages gettext)
40 (gnu packages guile-xyz)
41 (gnu packages iso-codes)
42 (gnu packages texinfo)
51 (@@ (guix self) file-append*))
53 (define translated-texi-manuals
54 (@@ (guix self) translate-texi-manuals))
57 (@@ (guix self) info-manual))
60 ;; The manual to build--i.e., the base name of a .texi file, such as "guix"
61 ;; or "guix-cookbook".
62 (or (getenv "GUIX_MANUAL")
66 ;; The cookbook is not translated in the same languages as the manual
67 (if (string=? %manual "guix-cookbook")
69 '("de" "en" "es" "fr" "ru" "zh_CN")))
71 (define (texinfo-manual-images source)
72 "Return a directory containing all the images used by the user manual, taken
73 from SOURCE, the root of the source tree."
75 (module-ref (resolve-interface '(gnu packages graphviz))
79 (file-append* source "doc/images"))
82 (with-imported-modules '((guix build utils))
84 (use-modules (guix build utils)
87 (define (dot->image dot-file format)
88 (invoke #+(file-append graphviz "/bin/dot")
89 "-T" format "-Gratio=.9" "-Gnodesep=.005"
90 "-Granksep=.00005" "-Nfontsize=9"
91 "-Nheight=.1" "-Nwidth=.1"
92 "-o" (string-append #$output "/"
93 (basename dot-file ".dot")
99 (for-each (lambda (dot-file)
100 (for-each (cut dot->image dot-file <>)
102 (find-files #$images "\\.dot$"))
105 (for-each (lambda (png-file)
106 (install-file png-file #$output))
107 (find-files #$images "\\.png$")))))
109 (computed-file "texinfo-manual-images" build))
111 (define* (texinfo-manual-source source #:key
113 (languages %languages)
115 "Gather all the source files of the Texinfo manuals from SOURCE--.texi file
116 as well as images, OS examples, and translations."
117 (define documentation
118 (file-append* source "doc"))
121 (file-append* source "gnu/system/examples"))
124 (with-imported-modules '((guix build utils))
126 (use-modules (guix build utils)
129 (define (make-version-texi language)
130 ;; Create the 'version.texi' file for LANGUAGE.
131 (let ((file (if (string=? language "en")
133 (string-append "version-" language ".texi"))))
134 (call-with-output-file (string-append #$output "/" file)
136 (let* ((version #$version)
137 (time (make-time time-utc 0 #$date))
138 (date (time-utc->date time)))
141 @set UPDATED-MONTH ~a
144 (date->string date "~e ~B ~Y")
145 (date->string date "~B ~Y")
146 version version))))))
148 (install-file #$(file-append documentation "/htmlxref.cnf")
151 (for-each (lambda (texi)
152 (install-file texi #$output))
153 (append (find-files #$documentation "\\.(texi|scm|json)$")
154 (find-files #$(translated-texi-manuals source)
157 ;; Create 'version.texi'.
158 (for-each make-version-texi '#$languages)
160 ;; Copy configuration templates that the manual includes.
161 (for-each (lambda (template)
164 #$output "/os-config-"
165 (basename template ".tmpl")
167 (find-files #$examples "\\.tmpl$"))
169 (symlink #$(texinfo-manual-images source)
170 (string-append #$output "/images")))))
172 (computed-file "texinfo-manual-source" build))
174 (define %web-site-url
175 ;; URL of the web site home page.
176 (or (getenv "GUIX_WEB_SITE_URL")
179 (define %makeinfo-html-options
180 ;; Options passed to 'makeinfo --html'.
181 '("--css-ref=https://www.gnu.org/software/gnulib/manual.css"
182 "-c" "EXTRA_HEAD=<meta name=\"viewport\" \
183 content=\"width=device-width, initial-scale=1\" />"))
185 (define (normalize-language-code language) ;XXX: deduplicate
186 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
187 (string-map (match-lambda
190 (string-downcase language)))
192 (define* (html-manual-identifier-index manual base-url
194 (name "html-manual-identifier-index"))
195 "Return an index of all the identifiers that appear in MANUAL, a
196 makeinfo-generated manual. The index is a file that contains an alist; each
197 key is an identifier and the associated value is the URL reference pointing to
198 that identifier. The URL is constructed by concatenating BASE-URL to the
201 (with-extensions (list guile-lib)
202 (with-imported-modules '((guix build utils))
204 (use-modules (guix build utils)
211 (ice-9 pretty-print))
213 (%strict-tokenizer? #t)
216 (let ((prefix (string-append #$manual "/")))
218 ;; Return the URL for FILE.
219 (let ((file (string-drop file (string-length prefix)))
221 (if (string-null? base)
223 (string-append base "/" file))))))
225 (define (underscore-decode str)
226 ;; Decode STR, an "underscore-encoded" string as produced by
227 ;; makeinfo for indexes, such as "_0025base_002dservices" for
231 (match (string-index str #\_)
233 (string-concatenate-reverse (cons str result)))
235 (let ((char (string->number
236 (substring str (+ index 1) (+ index 5))
238 (loop (string-drop str (+ index 5))
239 (append (list (string (integer->char char))
240 (string-take str index))
243 (define (anchor-id->key id)
244 ;; Convert ID, an anchor ID such as
245 ;; "index-pam_002dlimits_002dservice" to the corresponding key,
246 ;; "pam-limits-service" in this example. Drop the suffix of
247 ;; duplicate anchor IDs like "operating_002dsystem-1".
248 (let ((id (if (any (cut string-suffix? <> id)
249 '("-1" "-2" "-3" "-4" "-5"))
250 (string-drop-right id 2)
253 (string-drop id (string-length "index-")))))
255 (define* (collect-anchors file #:optional (anchors '()))
256 ;; Collect the anchors that appear in FILE, a makeinfo-generated
257 ;; file. Grab those from <dt> tags, which corresponds to
258 ;; Texinfo @deftp, @defvr, etc. Return ANCHORS augmented with
259 ;; more name/reference pairs.
260 (define string-or-entity?
263 (('*ENTITY* _ ...) #t)
266 (define (worthy-entry? lst)
268 ;; Scheme Variable: <strong>x</strong>
270 ;; <code>cups-configuration</code> parameter: …
271 (let loop ((lst lst))
273 (((? string-or-entity?) rest ...)
275 ((('strong _ ...) _ ...)
277 ((('span ('@ ('class "symbol-definition-category"))
278 (? string-or-entity?) ...) rest ...)
283 (let ((shtml (call-with-input-file file html->shtml)))
284 (let loop ((shtml shtml)
287 (('dt ('@ ('id id) _ ...) rest ...)
288 (if (and (string-prefix? "index-" id)
289 (worthy-entry? rest))
290 (alist-cons (anchor-id->key id)
291 (string-append (file-url file)
295 ((tag ('@ _ ...) body ...)
296 (fold loop anchors body))
298 (fold loop anchors body))
301 (define (html-files directory)
302 ;; Return the list of HTML files under DIRECTORY.
303 (map (cut string-append directory "/" <>)
304 (scandir #$manual (lambda (file)
305 (string-suffix? ".html" file)))))
309 (n-par-map (parallel-job-count)
310 (cut collect-anchors <>)
311 (html-files #$manual)))
313 (((key1 . url1) (key2 . url2))
314 (if (string=? key1 key2)
316 (string<? key1 key2))))))
318 (call-with-output-file #$output
320 (display ";; Identifier index for the manual.\n\n"
322 (pretty-print anchors port)))))))
324 (computed-file name build))
326 (define* (html-identifier-indexes manual directory-suffix
327 #:key (languages %languages)
328 (manual-name %manual)
329 (base-url (const "")))
330 (map (lambda (language)
331 (let ((language (normalize-language-code language)))
333 (html-manual-identifier-index
334 (file-append manual "/" language directory-suffix)
336 #:name (string-append manual-name "-html-index-"
340 (define* (syntax-highlighted-html input
342 (name "highlighted-syntax")
343 (languages %languages)
345 (html-identifier-indexes input ""
349 (html-identifier-indexes input
354 "/static/base/css/code.css"))
355 "Return a derivation called NAME that processes all the HTML files in INPUT
356 to (1) add them a link to SYNTAX-CSS-URL, and (2) highlight the syntax of all
357 its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
359 (with-extensions (list guile-lib guile-syntax-highlight)
360 (with-imported-modules '((guix build utils))
362 (use-modules (htmlprag)
364 (syntax-highlight scheme)
365 (syntax-highlight lexers)
373 (%strict-tokenizer? #t)
375 (define (pair-open/close lst)
376 ;; Pair 'open' and 'close' tags produced by 'highlights' and
377 ;; produce nested 'paren' tags instead.
382 ((('open open) rest ...)
385 (loop rest (+ 1 level) '()))
386 (lambda (inner close rest)
388 (cons `(paren ,level ,open ,inner ,close)
390 ((('close str) rest ...)
392 (values (reverse result) str rest)
394 (format (current-error-port)
395 "warning: extra closing paren; context:~% ~y~%"
397 (loop rest 0 (cons `(close ,str) result)))))
399 (loop rest level (cons item result)))
402 (format (current-error-port)
403 "warning: missing ~a closing parens; context:~% ~y%"
404 level (reverse result)))
405 (values (reverse result) "" '())))))
407 (define (highlights->sxml* highlights anchors)
408 ;; Like 'highlights->sxml', but handle nested 'paren tags. This
409 ;; allows for paren matching highlights via appropriate CSS
410 ;; "hover" properties. When a symbol is encountered, look it up
411 ;; in ANCHORS, a vhash, and emit the corresponding href, if any.
412 (define (tag->class tag)
413 (string-append "syntax-" (symbol->string tag)))
416 ((? string? str) str)
417 (('paren level open (body ...) close)
418 `(span (@ (class ,(string-append "syntax-paren"
419 (number->string level))))
421 (span (@ (class "syntax-symbol"))
422 ,@(highlights->sxml* body anchors))
425 ;; Check whether we can emit a hyperlink for TEXT.
426 (match (vhash-assoc text anchors)
428 `(span (@ (class ,(tag->class 'symbol))) ,text))
430 `(a (@ (class ,(tag->class 'symbol)) (href ,target))
433 `(span (@ (class ,(tag->class tag))) ,text)))
436 (define entity->string
442 (e (pk 'unknown-entity e) (primitive-exit 2))))
444 (define (concatenate-snippets pieces)
445 ;; Concatenate PIECES, which contains strings and entities,
446 ;; replacing entities with their corresponding string.
447 (let loop ((pieces pieces)
451 (string-concatenate-reverse strings))
452 (((? string? str) . rest)
453 (loop rest (cons str strings)))
454 ((('*ENTITY* "additional" entity) . rest)
455 (loop rest (cons (entity->string entity) strings)))
456 ((('span _ lst ...) . rest) ;for <span class="roman">
457 (loop (append lst rest) strings))
458 ((('var name) . rest) ;for @var{name} within @lisp
459 (loop rest (cons name strings))) ;XXX: losing formatting
461 (pk 'unsupported-code-snippet something)
462 (primitive-exit 1)))))
464 (define (highlight-definition id category symbol args)
465 ;; Produce stylable HTML for the given definition (an @deftp,
466 ;; @deffn, or similar).
467 `(dt (@ (id ,id) (class "symbol-definition"))
468 (span (@ (class "symbol-definition-category"))
470 (span (@ (class "symbol-definition-prototype"))
471 ,symbol " " ,@args)))
475 (string-every char-set:whitespace obj)))
477 (define (syntax-highlight sxml anchors)
478 ;; Recurse over SXML and syntax-highlight code snippets.
479 (let loop ((sxml sxml))
481 (('*TOP* decl body ...)
482 `(*TOP* ,decl ,@(map loop body)))
485 (link (@ (rel "stylesheet")
487 (href #$syntax-css-url)))))
488 (('pre ('@ ('class "lisp")) code-snippet ...)
489 `(pre (@ (class "lisp"))
492 (highlight lex-scheme
493 (concatenate-snippets code-snippet)))
496 ;; Replace the ugly <strong> used for @deffn etc., which
497 ;; translate to <dt>, with more stylable markup.
498 (('dt (@ ('id id)) category ... ('strong thing))
499 (highlight-definition id category thing '()))
500 (('dt (@ ('id id)) category ... ('strong thing)
501 (? space?) ('em args ...))
502 (highlight-definition id category thing args))
504 ((tag ('@ attributes ...) body ...)
505 `(,tag (@ ,@attributes) ,@(map loop body)))
507 `(,tag ,@(map loop body)))
511 (define (process-html file anchors)
512 ;; Parse FILE and perform syntax highlighting for its Scheme
513 ;; snippets. Install the result to #$output.
514 (format (current-error-port) "processing ~a...~%" file)
515 (let* ((shtml (call-with-input-file file html->shtml))
516 (highlighted (syntax-highlight shtml anchors))
517 (base (string-drop file (string-length #$input)))
518 (target (string-append #$output base)))
519 (mkdir-p (dirname target))
520 (call-with-output-file target
522 (write-shtml-as-html highlighted port)))))
524 (define (copy-as-is file)
525 ;; Copy FILE as is to #$output.
526 (let* ((base (string-drop file (string-length #$input)))
527 (target (string-append #$output base)))
528 (mkdir-p (dirname target))
531 (if (eq? 'symlink (stat:type (lstat file)))
532 (symlink (readlink file) target)
535 (let ((errno (system-error-errno args)))
536 (pk 'error-link file target (strerror errno))
537 (primitive-exit 3))))))
539 (define (html? file stat)
540 (string-suffix? ".html" file))
542 (define language+node-anchors
544 ((language files ...)
546 (fold (lambda (file vhash)
547 (let ((alist (call-with-input-file file read)))
548 ;; Use 'fold-right' so that the first entry
549 ;; wins (e.g., "car" from "Pairs" rather than
550 ;; from "rnrs base" in the Guile manual).
551 (fold-right (match-lambda*
552 (((key . value) vhash)
553 (vhash-cons key value vhash)))
559 (define mono-node-anchors
560 ;; List of language/vhash pairs, where each vhash maps an
561 ;; identifier to the corresponding URL in a single-page manual.
562 (map language+node-anchors '#$mono-node-indexes))
564 (define multi-node-anchors
565 ;; Likewise for split-node manuals.
566 (map language+node-anchors '#$split-node-indexes))
568 ;; Install a UTF-8 locale so we can process UTF-8 files.
569 (setenv "GUIX_LOCPATH"
570 #+(file-append glibc-utf8-locales "/lib/locale"))
571 (setlocale LC_ALL "en_US.utf8")
573 ;; First process the mono-node 'guix.html' files.
574 (for-each (match-lambda
575 ((language . anchors)
576 (let ((files (find-files
577 (string-append #$input "/" language)
578 "^guix(-cookbook|)(\\.[a-zA-Z_-]+)?\\.html$")))
579 (n-par-for-each (parallel-job-count)
580 (cut process-html <> anchors)
584 ;; Process the multi-node HTML files.
585 (for-each (match-lambda
586 ((language . anchors)
587 (let ((files (find-files
588 (string-append #$input "/" language
591 (n-par-for-each (parallel-job-count)
592 (cut process-html <> anchors)
596 ;; Last, copy non-HTML files as is.
598 (find-files #$input (negate html?)))))))
600 (computed-file name build))
602 (define* (html-manual source #:key (languages %languages)
605 (mono-node-indexes (map list languages))
606 (split-node-indexes (map list languages))
608 (options %makeinfo-html-options))
609 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
611 (define manual-source
612 (texinfo-manual-source source
614 #:languages languages
618 (texinfo-manual-images source))
621 (with-imported-modules '((guix build utils))
623 (use-modules (guix build utils)
626 (define (normalize language)
627 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
628 (string-map (match-lambda
631 (string-downcase language)))
633 (define (language->texi-file-name language)
634 (if (string=? language "en")
635 (string-append #$manual-source "/"
637 (string-append #$manual-source "/"
638 #$manual "." language ".texi")))
640 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
641 (setenv "GUIX_LOCPATH"
642 #+(file-append glibc-utf8-locales "/lib/locale"))
643 (setenv "LC_ALL" "en_US.utf8")
645 (setvbuf (current-output-port) 'line)
646 (setvbuf (current-error-port) 'line)
648 ;; 'makeinfo' looks for "htmlxref.cnf" in the current directory, so
649 ;; copy it right here.
650 (copy-file (string-append #$manual-source "/htmlxref.cnf")
653 (for-each (lambda (language)
654 (let* ((texi (language->texi-file-name language))
656 "-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
660 (format #t "building HTML manual for language '~a'...~%"
662 (mkdir-p (string-append #$output "/"
663 (normalize language)))
664 (setenv "LANGUAGE" language)
665 (apply invoke #$(file-append texinfo "/bin/makeinfo")
666 "-o" (string-append #$output "/"
670 (apply invoke #$(file-append texinfo "/bin/makeinfo")
673 (string-append #$output "/"
676 (if (string=? language "en")
678 (string-append "." language))
682 ;; Make sure images are available.
684 (string-append #$output "/" (normalize language)
687 (string-append #$output "/" (normalize language)
688 "/html_node/images"))))
689 (filter (compose file-exists? language->texi-file-name)
692 (let* ((name (string-append manual "-html-manual"))
693 (manual (computed-file name build)))
694 (syntax-highlighted-html manual
695 #:mono-node-indexes mono-node-indexes
696 #:split-node-indexes split-node-indexes
697 #:name (string-append name "-highlighted"))))
699 (define* (pdf-manual source #:key (languages %languages)
704 "Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
706 (define manual-source
707 (texinfo-manual-source source
709 #:languages languages
712 ;; FIXME: This union works, except for the table of contents of non-English
713 ;; manuals, which contains escape sequences like "^^ca^^fe" instead of
717 ;; (texlive-union (list texlive-tex-texinfo
718 ;; texlive-generic-epsf
719 ;; texlive-fonts-ec)))
722 (with-imported-modules '((guix build utils))
724 (use-modules (guix build utils)
728 (define (normalize language) ;XXX: deduplicate
729 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
730 (string-map (match-lambda
733 (string-downcase language)))
735 ;; Install a UTF-8 locale so that 'makeinfo' is at ease.
736 (setenv "GUIX_LOCPATH"
737 #+(file-append glibc-utf8-locales "/lib/locale"))
738 (setenv "LC_ALL" "en_US.utf8")
740 (string-append #+(file-append texlive "/bin") ":"
741 #+(file-append texinfo "/bin") ":"
743 ;; Below are command-line tools needed by
744 ;; 'texi2dvi' and friends.
745 #+(file-append sed "/bin") ":"
746 #+(file-append grep "/bin") ":"
747 #+(file-append coreutils "/bin") ":"
748 #+(file-append gawk "/bin") ":"
749 #+(file-append tar "/bin") ":"
750 #+(file-append diffutils "/bin")))
752 (setvbuf (current-output-port) 'line)
753 (setvbuf (current-error-port) 'line)
755 (setenv "HOME" (getcwd)) ;for kpathsea/mktextfm
757 ;; 'SOURCE_DATE_EPOCH' is honored by pdftex.
758 (setenv "SOURCE_DATE_EPOCH" "1")
760 (for-each (lambda (language)
761 (let ((opts `("--pdf"
764 ,(if (string=? language "en")
765 (string-append #$manual-source "/"
767 (string-append #$manual-source "/"
768 #$manual "." language ".texi")))))
769 (format #t "building PDF manual for language '~a'...~%"
771 (mkdir-p (string-append #$output "/"
772 (normalize language)))
773 (setenv "LANGUAGE" language)
776 ;; FIXME: Unfortunately building PDFs for non-Latin
777 ;; alphabets doesn't work:
778 ;; <https://lists.gnu.org/archive/html/help-texinfo/2012-01/msg00014.html>.
779 (guard (c ((invoke-error? c)
780 (format (current-error-port)
781 "~%~%Failed to produce \
782 PDF for language '~a'!~%~%"
784 (apply invoke #$(file-append texinfo "/bin/makeinfo")
786 (string-append #$output "/"
789 (if (string=? language "en")
797 (computed-file (string-append manual "-pdf-manual") build))
799 (define (guix-manual-text-domain source languages)
800 "Return the PO files for LANGUAGES of the 'guix-manual' text domain taken
803 (file-append* source "/po/doc"))
806 (with-imported-modules '((guix build utils))
808 (use-modules (guix build utils))
811 (for-each (lambda (language)
813 (string-append #$output "/" language
817 (invoke #+(file-append gnu-gettext "/bin/msgfmt")
819 (string-append directory "/guix-manual.mo")
820 (string-append #$po-directory "/guix-manual."
822 '#$(delete "en" languages)))))
824 (computed-file "guix-manual-po" build))
826 (define* (html-manual-indexes source
827 #:key (languages %languages)
830 (title (if (string=? "guix" manual)
831 "GNU Guix Reference Manual"
832 "GNU Guix Cookbook"))
835 (with-extensions (list guile-json-3)
836 (with-imported-modules '((guix build utils))
838 (use-modules (guix build utils)
846 (define (normalize language) ;XXX: deduplicate
847 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
848 (string-map (match-lambda
851 (string-downcase language)))
853 (define-syntax-rule (with-language language exp ...)
854 (let ((lang (getenv "LANGUAGE")))
857 (setenv "LANGUAGE" language)
858 (setlocale LC_MESSAGES))
862 (setenv "LANGUAGE" lang)
863 (unsetenv "LANGUAGE"))
864 (setlocale LC_MESSAGES)))))
866 ;; (put 'with-language 'scheme-indent-function 1)
867 (define* (translate str language
868 #:key (domain "guix-manual"))
871 (bindtextdomain "guix-manual"
872 #+(guix-manual-text-domain
875 (bindtextdomain "iso_639-3" ;language names
876 #+(file-append iso-codes
878 (write (gettext ,str ,domain))))
880 (with-language language
881 ;; Since the 'gettext' function caches msgid translations,
882 ;; regardless of $LANGUAGE, we have to spawn a new process each
883 ;; time we want to translate to a different language. Bah!
884 (let* ((pipe (open-pipe* OPEN_READ
885 #+(file-append guile-2.2
887 "-c" (object->string exp)))
892 (define (seconds->string seconds language)
893 (let* ((time (make-time time-utc 0 seconds))
894 (date (time-utc->date time)))
895 (with-language language (date->string date "~e ~B ~Y"))))
897 (define (guix-url path)
898 (string-append #$%web-site-url path))
900 (define (sxml-index language title body)
901 ;; FIXME: Avoid duplicating styling info from guix-artwork.git.
902 `(html (@ (lang ,language))
904 (title ,(string-append title " — GNU Guix"))
905 (meta (@ (charset "UTF-8")))
906 (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0")))
908 (link (@ (rel "prefetch") (href ,(guix-url "menu/index.html"))))
910 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css"))))
911 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css"))))
912 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css"))))
913 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css"))))
914 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css"))))
915 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css"))))
916 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css"))))
918 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css"))))
919 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css")))))
921 (header (@ (class "navbar"))
922 (h1 (a (@ (class "branding")
923 (href #$%web-site-url)))
924 (span (@ (class "a11y-offset"))
926 (nav (@ (class "menu"))))
927 (nav (@ (class "breadcrumbs"))
928 (a (@ (class "crumb")
929 (href #$%web-site-url))
934 (define (language-index language)
936 (translate #$title language))
942 (@ (class "page centered-block limit-width"))
944 (p (@ (class "post-metadata centered-text"))
946 ,(seconds->string #$date language))
950 (li (a (@ (href "html_node"))
951 "HTML, with a separate page per node"))
955 (if (string=? language
961 "HTML, entirely on one page"))
962 ,@(if (member language '("ru" "zh_CN"))
964 `((li (a (@ (href ,(string-append
966 (if (string=? language "en")
973 (define %iso639-languages
975 (assoc-ref (call-with-input-file
976 #+(file-append iso-codes
977 "/share/iso-codes/json/iso_639-3.json")
981 (define (language-code->name code)
982 "Return the full name of a language from its ISO-639-3 code."
983 (let ((code (match (string-index code #\_)
985 (index (string-take code index)))))
986 (any (lambda (language)
987 (and (string=? (or (assoc-ref language "alpha_2")
988 (assoc-ref language "alpha_3"))
990 (assoc-ref language "name")))
993 (define (top-level-index languages)
994 (define title #$title)
999 (@ (class "page centered-block limit-width"))
1002 "This document is available in the following
1005 ,@(map (lambda (language)
1006 `(li (a (@ (href ,(normalize language)))
1008 (language-code->name language)
1010 #:domain "iso_639-3"))))
1013 (define (write-html file sxml)
1014 (call-with-output-file file
1016 (display "<!DOCTYPE html>\n" port)
1017 (sxml->xml sxml port))))
1019 (setenv "GUIX_LOCPATH"
1020 #+(file-append glibc-utf8-locales "/lib/locale"))
1021 (setenv "LC_ALL" "en_US.utf8")
1022 (setlocale LC_ALL "en_US.utf8")
1024 (for-each (lambda (language)
1026 (string-append #$output "/"
1027 (normalize language)))
1030 (write-html (string-append directory "/index.html")
1031 (language-index language)))
1034 (write-html (string-append #$output "/index.html")
1035 (top-level-index '#$languages))))))
1037 (computed-file "html-indexes" build))
1039 (define* (pdf+html-manual source
1040 #:key (languages %languages)
1042 (date (time-second (current-time time-utc)))
1043 (mono-node-indexes (map list %languages))
1044 (split-node-indexes (map list %languages))
1046 "Return the union of the HTML and PDF manuals, as well as the indexes."
1047 (directory-union (string-append manual "-manual")
1051 #:languages languages
1054 (list html-manual-indexes
1055 (lambda (source . args)
1056 (apply html-manual source
1057 #:mono-node-indexes mono-node-indexes
1058 #:split-node-indexes split-node-indexes
1063 (define (latest-commit+date directory)
1064 "Return two values: the last commit ID (a hex string) for DIRECTORY, and its
1065 commit date (an integer)."
1066 (let* ((repository (repository-open directory))
1067 (head (repository-head repository))
1068 (oid (reference-target head))
1069 (commit (commit-lookup repository oid)))
1070 ;; TODO: Use (git describe) when it's widely available.
1071 (values (oid->string oid) (commit-time commit))))
1078 (define guile-manual
1079 ;; The Guile manual as HTML, including both the mono-node "guile.html" and
1080 ;; the split-node "html_node" directory.
1081 (let ((guile guile-3.0-latest))
1082 (computed-file (string-append "guile-manual-" (package-version guile))
1083 (with-imported-modules '((guix build utils))
1085 (use-modules (guix build utils)
1089 (string-append #+tar "/bin:"
1092 (invoke "tar" "xf" #$(package-source guile))
1093 (mkdir-p (string-append #$output "/en/html_node"))
1095 (let* ((texi (find-files "." "^guile\\.texi$"))
1096 (documentation (match texi
1097 ((file) (dirname file)))))
1098 (with-directory-excursion documentation
1099 (invoke "makeinfo" "--html" "--no-split"
1100 "-o" (string-append #$output
1103 (invoke "makeinfo" "--html" "-o" "split"
1107 (string-append #$output "/en/html_node")))))))))
1109 (define %guile-manual-base-url
1110 "https://www.gnu.org/software/guile/manual")
1112 (define (for-all-languages index)
1113 (map (lambda (language)
1114 (list language index))
1117 (define guile-mono-node-indexes
1118 ;; The Guile manual is only available in English so use the same index in
1121 (html-manual-identifier-index (file-append guile-manual "/en")
1122 %guile-manual-base-url
1123 #:name "guile-html-index-en")))
1125 (define guile-split-node-indexes
1127 (html-manual-identifier-index (file-append guile-manual "/en/html_node")
1128 (string-append %guile-manual-base-url
1130 #:name "guile-html-index-en")))
1132 (define (merge-index-alists alist1 alist2)
1133 "Merge ALIST1 and ALIST2, both of which are list of tuples like:
1135 (LANGUAGE INDEX1 INDEX2 ...)
1137 where LANGUAGE is a string like \"en\" and INDEX1 etc. are indexes as returned
1138 by 'html-identifier-indexes'."
1139 (let ((languages (delete-duplicates
1140 (append (match alist1
1141 (((languages . _) ...)
1144 (((languages . _) ...)
1146 (map (lambda (language)
1148 (append (or (assoc-ref alist1 language) '())
1149 (or (assoc-ref alist2 language) '()))))
1153 (let* ((root (canonicalize-path
1154 (string-append (current-source-directory) "/..")))
1155 (commit date (latest-commit+date root))
1156 (version (or (getenv "GUIX_MANUAL_VERSION")
1157 (string-take commit 7)))
1158 (select? (let ((vcs? (git-predicate root)))
1160 (and (vcs? file stat)
1161 ;; Filter out this file.
1162 (not (string=? (basename file) "build.scm"))))))
1163 (source (local-file root "guix" #:recursive? #t
1164 #:select? select?)))
1172 (define guix-mono-node-indexes
1173 ;; Alist of indexes for GUIX-MANUAL, where each key is a language code and
1174 ;; each value is a file-like object containing the identifier index.
1175 (html-identifier-indexes guix-manual ""
1176 #:manual-name "guix"
1177 #:base-url (if (string=? %manual "guix")
1180 "/manual/devel/" <>))
1181 #:languages %languages))
1183 (define guix-split-node-indexes
1184 ;; Likewise for the split-node variant of GUIX-MANUAL.
1185 (html-identifier-indexes guix-manual "/html_node"
1186 #:manual-name "guix"
1187 #:base-url (if (string=? %manual "guix")
1192 #:languages %languages))
1194 (define mono-node-indexes
1195 (merge-index-alists guix-mono-node-indexes guile-mono-node-indexes))
1197 (define split-node-indexes
1198 (merge-index-alists guix-split-node-indexes guile-split-node-indexes))
1200 (format (current-error-port)
1201 "building manual from work tree around commit ~a, ~a~%"
1203 (let* ((time (make-time time-utc 0 date))
1204 (date (time-utc->date time)))
1205 (date->string date "~e ~B ~Y")))
1207 (pdf+html-manual source
1208 ;; Always use the identifier indexes of GUIX-MANUAL and
1209 ;; GUILE-MANUAL. Both "guix" and "guix-cookbook" can
1210 ;; contain links to definitions that appear in either of
1211 ;; these two manuals.
1212 #:mono-node-indexes mono-node-indexes
1213 #:split-node-indexes split-node-indexes