2019-07-07 09:00:43 -04:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2022-01-15 06:15:45 -05:00
|
|
|
|
;;; Copyright © 2019-2022 Ludovic Courtès <ludo@gnu.org>
|
2020-04-28 07:51:31 -04:00
|
|
|
|
;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
|
2019-07-07 09:00:43 -04:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; This file contains machinery to build HTML and PDF copies of the manual
|
|
|
|
|
;; that can be readily published on the web site. To do that, run:
|
|
|
|
|
;;
|
|
|
|
|
;; guix build -f build.scm
|
|
|
|
|
;;
|
|
|
|
|
;; The result is a directory hierarchy that can be used as the manual/
|
|
|
|
|
;; sub-directory of the web site.
|
|
|
|
|
|
|
|
|
|
(use-modules (guix)
|
|
|
|
|
(guix gexp)
|
|
|
|
|
(guix git)
|
|
|
|
|
(guix git-download)
|
2019-09-07 09:37:22 -04:00
|
|
|
|
(guix utils)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(git)
|
|
|
|
|
(gnu packages base)
|
2020-10-17 15:53:26 -04:00
|
|
|
|
(gnu packages compression)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(gnu packages gawk)
|
|
|
|
|
(gnu packages gettext)
|
|
|
|
|
(gnu packages guile)
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(gnu packages guile-xyz)
|
2019-07-15 06:33:07 -04:00
|
|
|
|
(gnu packages iso-codes)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(gnu packages texinfo)
|
|
|
|
|
(gnu packages tex)
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(ice-9 match)
|
2020-10-17 15:53:26 -04:00
|
|
|
|
(srfi srfi-1)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(srfi srfi-19)
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(srfi srfi-26)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(srfi srfi-71))
|
|
|
|
|
|
|
|
|
|
(define file-append*
|
|
|
|
|
(@@ (guix self) file-append*))
|
|
|
|
|
|
|
|
|
|
(define translated-texi-manuals
|
2022-01-15 06:15:45 -05:00
|
|
|
|
(@@ (guix self) translate-texi-manuals))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(define info-manual
|
|
|
|
|
(@@ (guix self) info-manual))
|
|
|
|
|
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(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"))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(define %languages
|
2021-04-18 10:48:53 -04:00
|
|
|
|
;; The cookbook is not translated in the same languages as the manual
|
2020-04-28 07:51:31 -04:00
|
|
|
|
(if (string=? %manual "guix-cookbook")
|
2021-04-18 10:48:53 -04:00
|
|
|
|
'("de" "en" "fr")
|
2020-04-28 07:51:31 -04:00
|
|
|
|
'("de" "en" "es" "fr" "ru" "zh_CN")))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(define (texinfo-manual-images source)
|
|
|
|
|
"Return a directory containing all the images used by the user manual, taken
|
|
|
|
|
from SOURCE, the root of the source tree."
|
|
|
|
|
(define graphviz
|
|
|
|
|
(module-ref (resolve-interface '(gnu packages graphviz))
|
|
|
|
|
'graphviz))
|
|
|
|
|
|
|
|
|
|
(define images
|
|
|
|
|
(file-append* source "doc/images"))
|
|
|
|
|
|
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(srfi srfi-26))
|
|
|
|
|
|
|
|
|
|
(define (dot->image dot-file format)
|
|
|
|
|
(invoke #+(file-append graphviz "/bin/dot")
|
|
|
|
|
"-T" format "-Gratio=.9" "-Gnodesep=.005"
|
|
|
|
|
"-Granksep=.00005" "-Nfontsize=9"
|
|
|
|
|
"-Nheight=.1" "-Nwidth=.1"
|
|
|
|
|
"-o" (string-append #$output "/"
|
|
|
|
|
(basename dot-file ".dot")
|
|
|
|
|
"." format)
|
|
|
|
|
dot-file))
|
|
|
|
|
|
|
|
|
|
;; Build graphs.
|
|
|
|
|
(mkdir-p #$output)
|
|
|
|
|
(for-each (lambda (dot-file)
|
|
|
|
|
(for-each (cut dot->image dot-file <>)
|
|
|
|
|
'("png" "pdf")))
|
|
|
|
|
(find-files #$images "\\.dot$"))
|
|
|
|
|
|
|
|
|
|
;; Copy other PNGs.
|
|
|
|
|
(for-each (lambda (png-file)
|
|
|
|
|
(install-file png-file #$output))
|
|
|
|
|
(find-files #$images "\\.png$")))))
|
|
|
|
|
|
|
|
|
|
(computed-file "texinfo-manual-images" build))
|
|
|
|
|
|
|
|
|
|
(define* (texinfo-manual-source source #:key
|
|
|
|
|
(version "0.0")
|
|
|
|
|
(languages %languages)
|
|
|
|
|
(date 1))
|
|
|
|
|
"Gather all the source files of the Texinfo manuals from SOURCE--.texi file
|
|
|
|
|
as well as images, OS examples, and translations."
|
|
|
|
|
(define documentation
|
|
|
|
|
(file-append* source "doc"))
|
|
|
|
|
|
|
|
|
|
(define examples
|
|
|
|
|
(file-append* source "gnu/system/examples"))
|
|
|
|
|
|
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(srfi srfi-19))
|
|
|
|
|
|
|
|
|
|
(define (make-version-texi language)
|
|
|
|
|
;; Create the 'version.texi' file for LANGUAGE.
|
|
|
|
|
(let ((file (if (string=? language "en")
|
|
|
|
|
"version.texi"
|
|
|
|
|
(string-append "version-" language ".texi"))))
|
|
|
|
|
(call-with-output-file (string-append #$output "/" file)
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(let* ((version #$version)
|
|
|
|
|
(time (make-time time-utc 0 #$date))
|
|
|
|
|
(date (time-utc->date time)))
|
|
|
|
|
(format port "
|
|
|
|
|
@set UPDATED ~a
|
|
|
|
|
@set UPDATED-MONTH ~a
|
|
|
|
|
@set EDITION ~a
|
|
|
|
|
@set VERSION ~a\n"
|
|
|
|
|
(date->string date "~e ~B ~Y")
|
|
|
|
|
(date->string date "~B ~Y")
|
|
|
|
|
version version))))))
|
|
|
|
|
|
2020-05-25 11:24:54 -04:00
|
|
|
|
(install-file #$(file-append documentation "/htmlxref.cnf")
|
2019-07-07 09:00:43 -04:00
|
|
|
|
#$output)
|
|
|
|
|
|
|
|
|
|
(for-each (lambda (texi)
|
|
|
|
|
(install-file texi #$output))
|
2020-04-21 17:30:51 -04:00
|
|
|
|
(append (find-files #$documentation "\\.(texi|scm|json)$")
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(find-files #$(translated-texi-manuals source)
|
|
|
|
|
"\\.texi$")))
|
|
|
|
|
|
|
|
|
|
;; Create 'version.texi'.
|
|
|
|
|
(for-each make-version-texi '#$languages)
|
|
|
|
|
|
|
|
|
|
;; Copy configuration templates that the manual includes.
|
|
|
|
|
(for-each (lambda (template)
|
|
|
|
|
(copy-file template
|
|
|
|
|
(string-append
|
|
|
|
|
#$output "/os-config-"
|
|
|
|
|
(basename template ".tmpl")
|
|
|
|
|
".texi")))
|
|
|
|
|
(find-files #$examples "\\.tmpl$"))
|
|
|
|
|
|
|
|
|
|
(symlink #$(texinfo-manual-images source)
|
|
|
|
|
(string-append #$output "/images")))))
|
|
|
|
|
|
|
|
|
|
(computed-file "texinfo-manual-source" build))
|
|
|
|
|
|
|
|
|
|
(define %web-site-url
|
|
|
|
|
;; URL of the web site home page.
|
|
|
|
|
(or (getenv "GUIX_WEB_SITE_URL")
|
|
|
|
|
"/software/guix/"))
|
|
|
|
|
|
|
|
|
|
(define %makeinfo-html-options
|
|
|
|
|
;; Options passed to 'makeinfo --html'.
|
2019-10-21 15:12:45 -04:00
|
|
|
|
'("--css-ref=https://www.gnu.org/software/gnulib/manual.css"
|
|
|
|
|
"-c" "EXTRA_HEAD=<meta name=\"viewport\" \
|
|
|
|
|
content=\"width=device-width, initial-scale=1\" />"))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(define (normalize-language-code language) ;XXX: deduplicate
|
|
|
|
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
|
|
|
|
(string-map (match-lambda
|
|
|
|
|
(#\_ #\-)
|
|
|
|
|
(chr chr))
|
|
|
|
|
(string-downcase language)))
|
|
|
|
|
|
|
|
|
|
(define* (html-manual-identifier-index manual base-url
|
|
|
|
|
#:key
|
|
|
|
|
(name "html-manual-identifier-index"))
|
|
|
|
|
"Return an index of all the identifiers that appear in MANUAL, a
|
|
|
|
|
makeinfo-generated manual. The index is a file that contains an alist; each
|
|
|
|
|
key is an identifier and the associated value is the URL reference pointing to
|
|
|
|
|
that identifier. The URL is constructed by concatenating BASE-URL to the
|
|
|
|
|
actual file name."
|
|
|
|
|
(define build
|
2021-03-20 14:19:29 -04:00
|
|
|
|
(with-extensions (list guile-lib)
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(htmlprag)
|
|
|
|
|
(srfi srfi-1)
|
|
|
|
|
(srfi srfi-26)
|
|
|
|
|
(ice-9 ftw)
|
|
|
|
|
(ice-9 match)
|
|
|
|
|
(ice-9 threads)
|
|
|
|
|
(ice-9 pretty-print))
|
|
|
|
|
|
2021-03-20 14:19:29 -04:00
|
|
|
|
(%strict-tokenizer? #t)
|
|
|
|
|
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(define file-url
|
|
|
|
|
(let ((prefix (string-append #$manual "/")))
|
|
|
|
|
(lambda (file)
|
|
|
|
|
;; Return the URL for FILE.
|
|
|
|
|
(let ((file (string-drop file (string-length prefix)))
|
|
|
|
|
(base #$base-url))
|
|
|
|
|
(if (string-null? base)
|
|
|
|
|
file
|
|
|
|
|
(string-append base "/" file))))))
|
|
|
|
|
|
|
|
|
|
(define (underscore-decode str)
|
|
|
|
|
;; Decode STR, an "underscore-encoded" string as produced by
|
|
|
|
|
;; makeinfo for indexes, such as "_0025base_002dservices" for
|
|
|
|
|
;; "%base-services".
|
|
|
|
|
(let loop ((str str)
|
|
|
|
|
(result '()))
|
|
|
|
|
(match (string-index str #\_)
|
|
|
|
|
(#f
|
|
|
|
|
(string-concatenate-reverse (cons str result)))
|
|
|
|
|
(index
|
|
|
|
|
(let ((char (string->number
|
|
|
|
|
(substring str (+ index 1) (+ index 5))
|
|
|
|
|
16)))
|
|
|
|
|
(loop (string-drop str (+ index 5))
|
|
|
|
|
(append (list (string (integer->char char))
|
|
|
|
|
(string-take str index))
|
|
|
|
|
result)))))))
|
|
|
|
|
|
|
|
|
|
(define (anchor-id->key id)
|
|
|
|
|
;; Convert ID, an anchor ID such as
|
|
|
|
|
;; "index-pam_002dlimits_002dservice" to the corresponding key,
|
|
|
|
|
;; "pam-limits-service" in this example. Drop the suffix of
|
|
|
|
|
;; duplicate anchor IDs like "operating_002dsystem-1".
|
|
|
|
|
(let ((id (if (any (cut string-suffix? <> id)
|
|
|
|
|
'("-1" "-2" "-3" "-4" "-5"))
|
|
|
|
|
(string-drop-right id 2)
|
|
|
|
|
id)))
|
|
|
|
|
(underscore-decode
|
|
|
|
|
(string-drop id (string-length "index-")))))
|
|
|
|
|
|
|
|
|
|
(define* (collect-anchors file #:optional (anchors '()))
|
|
|
|
|
;; Collect the anchors that appear in FILE, a makeinfo-generated
|
|
|
|
|
;; file. Grab those from <dt> tags, which corresponds to
|
|
|
|
|
;; Texinfo @deftp, @defvr, etc. Return ANCHORS augmented with
|
|
|
|
|
;; more name/reference pairs.
|
|
|
|
|
(define string-or-entity?
|
|
|
|
|
(match-lambda
|
|
|
|
|
((? string?) #t)
|
|
|
|
|
(('*ENTITY* _ ...) #t)
|
|
|
|
|
(_ #f)))
|
|
|
|
|
|
|
|
|
|
(define (worthy-entry? lst)
|
|
|
|
|
;; Attempt to match:
|
|
|
|
|
;; Scheme Variable: <strong>x</strong>
|
|
|
|
|
;; but not:
|
|
|
|
|
;; <code>cups-configuration</code> parameter: …
|
|
|
|
|
(let loop ((lst lst))
|
|
|
|
|
(match lst
|
|
|
|
|
(((? string-or-entity?) rest ...)
|
|
|
|
|
(loop rest))
|
|
|
|
|
((('strong _ ...) _ ...)
|
|
|
|
|
#t)
|
2020-10-19 07:21:26 -04:00
|
|
|
|
((('span ('@ ('class "symbol-definition-category"))
|
|
|
|
|
(? string-or-entity?) ...) rest ...)
|
|
|
|
|
#t)
|
|
|
|
|
(x
|
|
|
|
|
#f))))
|
2020-10-16 16:51:30 -04:00
|
|
|
|
|
|
|
|
|
(let ((shtml (call-with-input-file file html->shtml)))
|
|
|
|
|
(let loop ((shtml shtml)
|
|
|
|
|
(anchors anchors))
|
|
|
|
|
(match shtml
|
2020-10-19 07:21:26 -04:00
|
|
|
|
(('dt ('@ ('id id) _ ...) rest ...)
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(if (and (string-prefix? "index-" id)
|
|
|
|
|
(worthy-entry? rest))
|
|
|
|
|
(alist-cons (anchor-id->key id)
|
|
|
|
|
(string-append (file-url file)
|
|
|
|
|
"#" id)
|
|
|
|
|
anchors)
|
|
|
|
|
anchors))
|
|
|
|
|
((tag ('@ _ ...) body ...)
|
|
|
|
|
(fold loop anchors body))
|
|
|
|
|
((tag body ...)
|
|
|
|
|
(fold loop anchors body))
|
|
|
|
|
(_ anchors)))))
|
|
|
|
|
|
|
|
|
|
(define (html-files directory)
|
|
|
|
|
;; Return the list of HTML files under DIRECTORY.
|
|
|
|
|
(map (cut string-append directory "/" <>)
|
|
|
|
|
(scandir #$manual (lambda (file)
|
|
|
|
|
(string-suffix? ".html" file)))))
|
|
|
|
|
|
|
|
|
|
(define anchors
|
|
|
|
|
(sort (concatenate
|
|
|
|
|
(n-par-map (parallel-job-count)
|
|
|
|
|
(cut collect-anchors <>)
|
|
|
|
|
(html-files #$manual)))
|
|
|
|
|
(match-lambda*
|
|
|
|
|
(((key1 . url1) (key2 . url2))
|
|
|
|
|
(if (string=? key1 key2)
|
|
|
|
|
(string<? url1 url2)
|
|
|
|
|
(string<? key1 key2))))))
|
|
|
|
|
|
|
|
|
|
(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display ";; Identifier index for the manual.\n\n"
|
|
|
|
|
port)
|
|
|
|
|
(pretty-print anchors port)))))))
|
|
|
|
|
|
|
|
|
|
(computed-file name build))
|
|
|
|
|
|
|
|
|
|
(define* (html-identifier-indexes manual directory-suffix
|
|
|
|
|
#:key (languages %languages)
|
|
|
|
|
(manual-name %manual)
|
|
|
|
|
(base-url (const "")))
|
|
|
|
|
(map (lambda (language)
|
|
|
|
|
(let ((language (normalize-language-code language)))
|
|
|
|
|
(list language
|
|
|
|
|
(html-manual-identifier-index
|
|
|
|
|
(file-append manual "/" language directory-suffix)
|
|
|
|
|
(base-url language)
|
|
|
|
|
#:name (string-append manual-name "-html-index-"
|
|
|
|
|
language)))))
|
|
|
|
|
languages))
|
|
|
|
|
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(define* (syntax-highlighted-html input
|
|
|
|
|
#:key
|
|
|
|
|
(name "highlighted-syntax")
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(languages %languages)
|
|
|
|
|
(mono-node-indexes
|
|
|
|
|
(html-identifier-indexes input ""
|
|
|
|
|
#:languages
|
|
|
|
|
languages))
|
|
|
|
|
(split-node-indexes
|
|
|
|
|
(html-identifier-indexes input
|
|
|
|
|
"/html_node"
|
|
|
|
|
#:languages
|
|
|
|
|
languages))
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(syntax-css-url
|
|
|
|
|
"/static/base/css/code.css"))
|
|
|
|
|
"Return a derivation called NAME that processes all the HTML files in INPUT
|
|
|
|
|
to (1) add them a link to SYNTAX-CSS-URL, and (2) highlight the syntax of all
|
|
|
|
|
its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
|
|
|
|
|
(define build
|
2021-03-20 14:19:29 -04:00
|
|
|
|
(with-extensions (list guile-lib guile-syntax-highlight)
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (htmlprag)
|
|
|
|
|
(syntax-highlight)
|
|
|
|
|
(syntax-highlight scheme)
|
|
|
|
|
(syntax-highlight lexers)
|
|
|
|
|
(guix build utils)
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(srfi srfi-1)
|
2020-04-13 06:27:17 -04:00
|
|
|
|
(srfi srfi-26)
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(ice-9 match)
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(ice-9 threads)
|
|
|
|
|
(ice-9 vlist))
|
2019-09-06 16:59:32 -04:00
|
|
|
|
|
2021-03-20 14:19:29 -04:00
|
|
|
|
(%strict-tokenizer? #t)
|
|
|
|
|
|
2019-09-25 08:43:46 -04:00
|
|
|
|
(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) "" '())))))
|
|
|
|
|
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(define (highlights->sxml* highlights anchors)
|
2019-09-25 08:43:46 -04:00
|
|
|
|
;; Like 'highlights->sxml', but handle nested 'paren tags. This
|
|
|
|
|
;; allows for paren matching highlights via appropriate CSS
|
2020-04-12 18:12:20 -04:00
|
|
|
|
;; "hover" properties. When a symbol is encountered, look it up
|
|
|
|
|
;; in ANCHORS, a vhash, and emit the corresponding href, if any.
|
2019-09-25 08:43:46 -04:00
|
|
|
|
(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"))
|
2020-04-12 18:12:20 -04:00
|
|
|
|
,@(highlights->sxml* body anchors))
|
2019-09-25 08:43:46 -04:00
|
|
|
|
,close))
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(('symbol text)
|
|
|
|
|
;; Check whether we can emit a hyperlink for TEXT.
|
|
|
|
|
(match (vhash-assoc text anchors)
|
|
|
|
|
(#f
|
|
|
|
|
`(span (@ (class ,(tag->class 'symbol))) ,text))
|
|
|
|
|
((_ . target)
|
|
|
|
|
`(a (@ (class ,(tag->class 'symbol)) (href ,target))
|
|
|
|
|
,text))))
|
2019-09-25 08:43:46 -04:00
|
|
|
|
((tag text)
|
|
|
|
|
`(span (@ (class ,(tag->class tag))) ,text)))
|
|
|
|
|
highlights))
|
|
|
|
|
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(define entity->string
|
|
|
|
|
(match-lambda
|
|
|
|
|
("rArr" "⇒")
|
2019-11-27 09:42:18 -05:00
|
|
|
|
("rarr" "→")
|
2019-09-06 16:59:32 -04:00
|
|
|
|
("hellip" "…")
|
|
|
|
|
("rsquo" "’")
|
2021-12-13 05:28:31 -05:00
|
|
|
|
("nbsp" " ")
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(e (pk 'unknown-entity e) (primitive-exit 2))))
|
|
|
|
|
|
|
|
|
|
(define (concatenate-snippets pieces)
|
|
|
|
|
;; Concatenate PIECES, which contains strings and entities,
|
|
|
|
|
;; replacing entities with their corresponding string.
|
|
|
|
|
(let loop ((pieces pieces)
|
|
|
|
|
(strings '()))
|
|
|
|
|
(match pieces
|
|
|
|
|
(()
|
|
|
|
|
(string-concatenate-reverse strings))
|
|
|
|
|
(((? string? str) . rest)
|
|
|
|
|
(loop rest (cons str strings)))
|
|
|
|
|
((('*ENTITY* "additional" entity) . rest)
|
|
|
|
|
(loop rest (cons (entity->string entity) strings)))
|
|
|
|
|
((('span _ lst ...) . rest) ;for <span class="roman">
|
|
|
|
|
(loop (append lst rest) strings))
|
2020-09-04 04:32:04 -04:00
|
|
|
|
((('var name) . rest) ;for @var{name} within @lisp
|
|
|
|
|
(loop rest (cons name strings))) ;XXX: losing formatting
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(something
|
|
|
|
|
(pk 'unsupported-code-snippet something)
|
|
|
|
|
(primitive-exit 1)))))
|
|
|
|
|
|
2020-10-19 07:21:26 -04:00
|
|
|
|
(define (highlight-definition id category symbol args)
|
|
|
|
|
;; Produce stylable HTML for the given definition (an @deftp,
|
|
|
|
|
;; @deffn, or similar).
|
|
|
|
|
`(dt (@ (id ,id) (class "symbol-definition"))
|
|
|
|
|
(span (@ (class "symbol-definition-category"))
|
|
|
|
|
,@category)
|
|
|
|
|
(span (@ (class "symbol-definition-prototype"))
|
|
|
|
|
,symbol " " ,@args)))
|
|
|
|
|
|
|
|
|
|
(define (space? obj)
|
|
|
|
|
(and (string? obj)
|
|
|
|
|
(string-every char-set:whitespace obj)))
|
|
|
|
|
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(define (syntax-highlight sxml anchors)
|
2019-09-06 16:59:32 -04:00
|
|
|
|
;; Recurse over SXML and syntax-highlight code snippets.
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(let loop ((sxml sxml))
|
|
|
|
|
(match sxml
|
|
|
|
|
(('*TOP* decl body ...)
|
|
|
|
|
`(*TOP* ,decl ,@(map loop body)))
|
|
|
|
|
(('head things ...)
|
|
|
|
|
`(head ,@things
|
|
|
|
|
(link (@ (rel "stylesheet")
|
|
|
|
|
(type "text/css")
|
|
|
|
|
(href #$syntax-css-url)))))
|
|
|
|
|
(('pre ('@ ('class "lisp")) code-snippet ...)
|
|
|
|
|
`(pre (@ (class "lisp"))
|
|
|
|
|
,@(highlights->sxml*
|
|
|
|
|
(pair-open/close
|
|
|
|
|
(highlight lex-scheme
|
|
|
|
|
(concatenate-snippets code-snippet)))
|
|
|
|
|
anchors)))
|
2020-10-19 07:21:26 -04:00
|
|
|
|
|
|
|
|
|
;; Replace the ugly <strong> used for @deffn etc., which
|
|
|
|
|
;; translate to <dt>, with more stylable markup.
|
|
|
|
|
(('dt (@ ('id id)) category ... ('strong thing))
|
|
|
|
|
(highlight-definition id category thing '()))
|
|
|
|
|
(('dt (@ ('id id)) category ... ('strong thing)
|
|
|
|
|
(? space?) ('em args ...))
|
|
|
|
|
(highlight-definition id category thing args))
|
|
|
|
|
|
2020-04-12 18:12:20 -04:00
|
|
|
|
((tag ('@ attributes ...) body ...)
|
|
|
|
|
`(,tag (@ ,@attributes) ,@(map loop body)))
|
|
|
|
|
((tag body ...)
|
|
|
|
|
`(,tag ,@(map loop body)))
|
|
|
|
|
((? string? str)
|
|
|
|
|
str))))
|
|
|
|
|
|
|
|
|
|
(define (process-html file anchors)
|
2019-09-06 16:59:32 -04:00
|
|
|
|
;; Parse FILE and perform syntax highlighting for its Scheme
|
|
|
|
|
;; snippets. Install the result to #$output.
|
|
|
|
|
(format (current-error-port) "processing ~a...~%" file)
|
|
|
|
|
(let* ((shtml (call-with-input-file file html->shtml))
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(highlighted (syntax-highlight shtml anchors))
|
2019-09-06 16:59:32 -04:00
|
|
|
|
(base (string-drop file (string-length #$input)))
|
|
|
|
|
(target (string-append #$output base)))
|
|
|
|
|
(mkdir-p (dirname target))
|
|
|
|
|
(call-with-output-file target
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(write-shtml-as-html highlighted port)))))
|
|
|
|
|
|
|
|
|
|
(define (copy-as-is file)
|
|
|
|
|
;; Copy FILE as is to #$output.
|
|
|
|
|
(let* ((base (string-drop file (string-length #$input)))
|
|
|
|
|
(target (string-append #$output base)))
|
|
|
|
|
(mkdir-p (dirname target))
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(if (eq? 'symlink (stat:type (lstat file)))
|
|
|
|
|
(symlink (readlink file) target)
|
|
|
|
|
(link file target)))
|
|
|
|
|
(lambda args
|
|
|
|
|
(let ((errno (system-error-errno args)))
|
|
|
|
|
(pk 'error-link file target (strerror errno))
|
|
|
|
|
(primitive-exit 3))))))
|
|
|
|
|
|
2020-04-12 18:12:20 -04:00
|
|
|
|
(define (html? file stat)
|
|
|
|
|
(string-suffix? ".html" file))
|
|
|
|
|
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(define language+node-anchors
|
|
|
|
|
(match-lambda
|
|
|
|
|
((language files ...)
|
|
|
|
|
(cons language
|
|
|
|
|
(fold (lambda (file vhash)
|
|
|
|
|
(let ((alist (call-with-input-file file read)))
|
|
|
|
|
;; Use 'fold-right' so that the first entry
|
|
|
|
|
;; wins (e.g., "car" from "Pairs" rather than
|
|
|
|
|
;; from "rnrs base" in the Guile manual).
|
|
|
|
|
(fold-right (match-lambda*
|
|
|
|
|
(((key . value) vhash)
|
|
|
|
|
(vhash-cons key value vhash)))
|
|
|
|
|
vhash
|
|
|
|
|
alist)))
|
|
|
|
|
vlist-null
|
|
|
|
|
files)))))
|
|
|
|
|
|
|
|
|
|
(define mono-node-anchors
|
|
|
|
|
;; List of language/vhash pairs, where each vhash maps an
|
|
|
|
|
;; identifier to the corresponding URL in a single-page manual.
|
|
|
|
|
(map language+node-anchors '#$mono-node-indexes))
|
|
|
|
|
|
|
|
|
|
(define multi-node-anchors
|
|
|
|
|
;; Likewise for split-node manuals.
|
|
|
|
|
(map language+node-anchors '#$split-node-indexes))
|
|
|
|
|
|
2019-09-06 16:59:32 -04:00
|
|
|
|
;; Install a UTF-8 locale so we can process UTF-8 files.
|
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
|
#+(file-append glibc-utf8-locales "/lib/locale"))
|
|
|
|
|
(setlocale LC_ALL "en_US.utf8")
|
|
|
|
|
|
2020-04-12 18:12:20 -04:00
|
|
|
|
;; First process the mono-node 'guix.html' files.
|
2020-10-16 16:51:30 -04:00
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((language . anchors)
|
|
|
|
|
(let ((files (find-files
|
|
|
|
|
(string-append #$input "/" language)
|
|
|
|
|
"^guix(-cookbook|)(\\.[a-zA-Z_-]+)?\\.html$")))
|
|
|
|
|
(n-par-for-each (parallel-job-count)
|
|
|
|
|
(cut process-html <> anchors)
|
|
|
|
|
files))))
|
|
|
|
|
mono-node-anchors)
|
|
|
|
|
|
|
|
|
|
;; Process the multi-node HTML files.
|
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((language . anchors)
|
|
|
|
|
(let ((files (find-files
|
|
|
|
|
(string-append #$input "/" language
|
|
|
|
|
"/html_node")
|
|
|
|
|
"\\.html$")))
|
|
|
|
|
(n-par-for-each (parallel-job-count)
|
|
|
|
|
(cut process-html <> anchors)
|
|
|
|
|
files))))
|
|
|
|
|
multi-node-anchors)
|
2020-04-12 18:12:20 -04:00
|
|
|
|
|
|
|
|
|
;; Last, copy non-HTML files as is.
|
|
|
|
|
(for-each copy-as-is
|
|
|
|
|
(find-files #$input (negate html?)))))))
|
2019-09-06 16:59:32 -04:00
|
|
|
|
|
|
|
|
|
(computed-file name build))
|
|
|
|
|
|
2022-01-18 16:20:12 -05:00
|
|
|
|
(define* (stylized-html source input
|
|
|
|
|
#:key
|
|
|
|
|
(languages %languages)
|
|
|
|
|
(manual %manual)
|
|
|
|
|
(manual-css-url "/static/base/css/manual.css"))
|
|
|
|
|
"Process all the HTML files in INPUT; add them MANUAL-CSS-URL as a <style>
|
|
|
|
|
link, and add a menu to choose among LANGUAGES. Use the Guix PO files found
|
|
|
|
|
in SOURCE."
|
|
|
|
|
(define build
|
|
|
|
|
(with-extensions (list guile-lib)
|
|
|
|
|
(with-imported-modules `((guix build utils)
|
|
|
|
|
((localization)
|
|
|
|
|
=> ,(localization-helper-module
|
|
|
|
|
source languages)))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (htmlprag)
|
|
|
|
|
(localization)
|
|
|
|
|
(guix build utils)
|
|
|
|
|
(srfi srfi-1)
|
|
|
|
|
(ice-9 match)
|
|
|
|
|
(ice-9 threads))
|
|
|
|
|
|
|
|
|
|
(define* (menu-dropdown #:key (label "Item") (url "#") (items '()))
|
|
|
|
|
;; Return an SHTML <li> element representing a dropdown for the
|
|
|
|
|
;; navbar. LABEL is the text of the dropdown menu, and ITEMS is
|
|
|
|
|
;; the list of items in this menu.
|
|
|
|
|
(define id "visible-dropdown")
|
|
|
|
|
|
|
|
|
|
`(li
|
|
|
|
|
(@ (class "navbar-menu-item dropdown dropdown-btn"))
|
|
|
|
|
(input (@ (class "navbar-menu-hidden-input")
|
|
|
|
|
(type "radio")
|
|
|
|
|
(name "dropdown")
|
|
|
|
|
(id ,id)))
|
|
|
|
|
(label (@ (for ,id)) ,label)
|
|
|
|
|
(label (@ (for "all-dropdowns-hidden")) ,label)
|
|
|
|
|
(div
|
|
|
|
|
(@ (class "navbar-submenu")
|
|
|
|
|
(id "navbar-submenu"))
|
|
|
|
|
(div (@ (class "navbar-submenu-triangle"))
|
|
|
|
|
" ")
|
|
|
|
|
(ul ,@items))))
|
|
|
|
|
|
|
|
|
|
(define (menu-item label url)
|
|
|
|
|
;; Return an SHTML <li> element for a menu item with the given
|
|
|
|
|
;; LABEL and URL.
|
|
|
|
|
`(li (a (@ (class "navbar-menu-item")
|
|
|
|
|
(href ,url))
|
|
|
|
|
,label)))
|
|
|
|
|
|
2022-01-19 09:41:59 -05:00
|
|
|
|
(define* (navigation-bar menus #:key split-node?)
|
|
|
|
|
;; Return the navigation bar showing all of MENUS.
|
|
|
|
|
`(header (@ (class "navbar"))
|
|
|
|
|
(h1 (a (@ (class "branding")
|
|
|
|
|
(href ,(if split-node? ".." "#")))))
|
|
|
|
|
(nav (@ (class "navbar-menu"))
|
|
|
|
|
(input (@ (class "navbar-menu-hidden-input")
|
|
|
|
|
(type "radio")
|
|
|
|
|
(name "dropdown")
|
|
|
|
|
(id "all-dropdowns-hidden")))
|
|
|
|
|
(ul ,@menus))
|
|
|
|
|
|
|
|
|
|
;; This is the button that shows up on small screen in
|
|
|
|
|
;; lieu of the drop-down button.
|
|
|
|
|
(a (@ (class "navbar-menu-btn")
|
|
|
|
|
(href ,(if split-node? "../.." ".."))))))
|
|
|
|
|
|
2022-01-18 16:20:12 -05:00
|
|
|
|
(define* (base-language-url code manual
|
|
|
|
|
#:key split-node?)
|
|
|
|
|
;; Return the base URL of MANUAL for language CODE.
|
|
|
|
|
(if split-node?
|
2022-01-19 16:06:35 -05:00
|
|
|
|
(string-append "../../" (normalize code) "/html_node")
|
|
|
|
|
(string-append "../" (normalize code) "/" manual
|
2022-01-18 16:20:12 -05:00
|
|
|
|
(if (string=? code "en")
|
|
|
|
|
""
|
|
|
|
|
(string-append "." code))
|
|
|
|
|
".html")))
|
|
|
|
|
|
|
|
|
|
(define (language-menu-items file)
|
|
|
|
|
;; Return the language menu items to be inserted in FILE.
|
|
|
|
|
(define split-node?
|
|
|
|
|
(string-contains file "/html_node/"))
|
|
|
|
|
|
|
|
|
|
(append
|
|
|
|
|
(map (lambda (code)
|
|
|
|
|
(menu-item (language-code->native-name code)
|
|
|
|
|
(base-language-url code #$manual
|
|
|
|
|
#:split-node?
|
|
|
|
|
split-node?)))
|
|
|
|
|
'#$%languages)
|
|
|
|
|
(list
|
|
|
|
|
(menu-item "⊕"
|
|
|
|
|
(if (string=? #$manual "guix-cookbook")
|
|
|
|
|
"https://translate.fedoraproject.org/projects/guix/documentation-cookbook/"
|
|
|
|
|
"https://translate.fedoraproject.org/projects/guix/documentation-manual/")))))
|
|
|
|
|
|
|
|
|
|
(define (stylized-html sxml file)
|
|
|
|
|
;; Return SXML, which was read from FILE, with additional
|
|
|
|
|
;; styling.
|
2022-01-19 09:41:59 -05:00
|
|
|
|
(define split-node?
|
|
|
|
|
(string-contains file "/html_node/"))
|
|
|
|
|
|
2022-01-18 16:20:12 -05:00
|
|
|
|
(let loop ((sxml sxml))
|
|
|
|
|
(match sxml
|
|
|
|
|
(('*TOP* decl body ...)
|
|
|
|
|
`(*TOP* ,decl ,@(map loop body)))
|
|
|
|
|
(('head elements ...)
|
|
|
|
|
;; Add reference to our own manual CSS, which provides
|
|
|
|
|
;; support for the language menu.
|
|
|
|
|
`(head ,@elements
|
|
|
|
|
(link (@ (rel "stylesheet")
|
|
|
|
|
(type "text/css")
|
|
|
|
|
(href #$manual-css-url)))))
|
|
|
|
|
(('body ('@ attributes ...) elements ...)
|
|
|
|
|
`(body (@ ,@attributes)
|
2022-01-19 09:41:59 -05:00
|
|
|
|
,(navigation-bar
|
|
|
|
|
;; TODO: Add "Contribute" menu, to report
|
|
|
|
|
;; errors, etc.
|
|
|
|
|
(list (menu-dropdown
|
|
|
|
|
#:label
|
|
|
|
|
`(img (@ (alt "Language")
|
|
|
|
|
(src "/static/base/img/language-picker.svg")))
|
|
|
|
|
#:items
|
|
|
|
|
(language-menu-items file)))
|
|
|
|
|
#:split-node? split-node?)
|
2022-01-18 16:20:12 -05:00
|
|
|
|
,@elements))
|
|
|
|
|
((tag ('@ attributes ...) body ...)
|
|
|
|
|
`(,tag (@ ,@attributes) ,@(map loop body)))
|
|
|
|
|
((tag body ...)
|
|
|
|
|
`(,tag ,@(map loop body)))
|
|
|
|
|
((? string? str)
|
|
|
|
|
str))))
|
|
|
|
|
|
|
|
|
|
(define (process-html file)
|
|
|
|
|
;; Parse FILE and add links to translations. Install the result
|
|
|
|
|
;; to #$output.
|
|
|
|
|
(format (current-error-port) "processing ~a...~%" file)
|
|
|
|
|
(let* ((shtml (parameterize ((%strict-tokenizer? #t))
|
|
|
|
|
(call-with-input-file file html->shtml)))
|
|
|
|
|
(processed (stylized-html shtml file))
|
|
|
|
|
(base (string-drop file (string-length #$input)))
|
|
|
|
|
(target (string-append #$output base)))
|
|
|
|
|
(mkdir-p (dirname target))
|
|
|
|
|
(call-with-output-file target
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(write-shtml-as-html processed port)))))
|
|
|
|
|
|
|
|
|
|
;; Install a UTF-8 locale so we can process UTF-8 files.
|
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
|
#+(file-append glibc-utf8-locales "/lib/locale"))
|
|
|
|
|
(setlocale LC_ALL "en_US.utf8")
|
|
|
|
|
(setenv "LC_ALL" "en_US.utf8")
|
|
|
|
|
(setvbuf (current-error-port) 'line)
|
|
|
|
|
|
|
|
|
|
(n-par-for-each (parallel-job-count)
|
|
|
|
|
(lambda (file)
|
|
|
|
|
(if (string-suffix? ".html" file)
|
|
|
|
|
(process-html file)
|
|
|
|
|
;; Copy FILE as is to #$output.
|
|
|
|
|
(let* ((base (string-drop file (string-length #$input)))
|
|
|
|
|
(target (string-append #$output base)))
|
|
|
|
|
(mkdir-p (dirname target))
|
|
|
|
|
(if (eq? 'symlink (stat:type (lstat file)))
|
|
|
|
|
(symlink (readlink file) target)
|
|
|
|
|
(copy-file file target)))))
|
|
|
|
|
(find-files #$input))))))
|
|
|
|
|
|
|
|
|
|
(computed-file "stylized-html-manual" build))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(define* (html-manual source #:key (languages %languages)
|
|
|
|
|
(version "0.0")
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(manual %manual)
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(mono-node-indexes (map list languages))
|
|
|
|
|
(split-node-indexes (map list languages))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(date 1)
|
|
|
|
|
(options %makeinfo-html-options))
|
|
|
|
|
"Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
|
|
|
|
|
makeinfo OPTIONS."
|
|
|
|
|
(define manual-source
|
|
|
|
|
(texinfo-manual-source source
|
|
|
|
|
#:version version
|
|
|
|
|
#:languages languages
|
|
|
|
|
#:date date))
|
|
|
|
|
|
2019-07-16 04:37:12 -04:00
|
|
|
|
(define images
|
|
|
|
|
(texinfo-manual-images source))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(ice-9 match))
|
|
|
|
|
|
|
|
|
|
(define (normalize language)
|
2019-07-15 06:33:07 -04:00
|
|
|
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(string-map (match-lambda
|
|
|
|
|
(#\_ #\-)
|
|
|
|
|
(chr chr))
|
|
|
|
|
(string-downcase language)))
|
|
|
|
|
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(define (language->texi-file-name language)
|
|
|
|
|
(if (string=? language "en")
|
|
|
|
|
(string-append #$manual-source "/"
|
|
|
|
|
#$manual ".texi")
|
|
|
|
|
(string-append #$manual-source "/"
|
|
|
|
|
#$manual "." language ".texi")))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
;; Install a UTF-8 locale so that 'makeinfo' is at ease.
|
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
|
#+(file-append glibc-utf8-locales "/lib/locale"))
|
|
|
|
|
(setenv "LC_ALL" "en_US.utf8")
|
|
|
|
|
|
|
|
|
|
(setvbuf (current-output-port) 'line)
|
|
|
|
|
(setvbuf (current-error-port) 'line)
|
|
|
|
|
|
2020-01-11 18:14:53 -05:00
|
|
|
|
;; 'makeinfo' looks for "htmlxref.cnf" in the current directory, so
|
|
|
|
|
;; copy it right here.
|
|
|
|
|
(copy-file (string-append #$manual-source "/htmlxref.cnf")
|
|
|
|
|
"htmlxref.cnf")
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(for-each (lambda (language)
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(let* ((texi (language->texi-file-name language))
|
|
|
|
|
(opts `("--html"
|
|
|
|
|
"-c" ,(string-append "TOP_NODE_UP_URL=/manual/"
|
2019-07-07 09:00:43 -04:00
|
|
|
|
language)
|
2019-10-21 12:01:45 -04:00
|
|
|
|
#$@options
|
|
|
|
|
,texi)))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(format #t "building HTML manual for language '~a'...~%"
|
|
|
|
|
language)
|
|
|
|
|
(mkdir-p (string-append #$output "/"
|
|
|
|
|
(normalize language)))
|
|
|
|
|
(setenv "LANGUAGE" language)
|
|
|
|
|
(apply invoke #$(file-append texinfo "/bin/makeinfo")
|
|
|
|
|
"-o" (string-append #$output "/"
|
|
|
|
|
(normalize language)
|
|
|
|
|
"/html_node")
|
|
|
|
|
opts)
|
|
|
|
|
(apply invoke #$(file-append texinfo "/bin/makeinfo")
|
|
|
|
|
"--no-split"
|
|
|
|
|
"-o"
|
|
|
|
|
(string-append #$output "/"
|
|
|
|
|
(normalize language)
|
|
|
|
|
"/" #$manual
|
|
|
|
|
(if (string=? language "en")
|
|
|
|
|
""
|
|
|
|
|
(string-append "." language))
|
|
|
|
|
".html")
|
2019-07-16 04:37:12 -04:00
|
|
|
|
opts)
|
|
|
|
|
|
|
|
|
|
;; Make sure images are available.
|
|
|
|
|
(symlink #$images
|
|
|
|
|
(string-append #$output "/" (normalize language)
|
|
|
|
|
"/images"))
|
|
|
|
|
(symlink #$images
|
|
|
|
|
(string-append #$output "/" (normalize language)
|
|
|
|
|
"/html_node/images"))))
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(filter (compose file-exists? language->texi-file-name)
|
|
|
|
|
'#$languages)))))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
2022-01-18 16:20:12 -05:00
|
|
|
|
(let* ((name (string-append manual "-html-manual"))
|
|
|
|
|
(manual* (computed-file name build #:local-build? #f)))
|
|
|
|
|
(syntax-highlighted-html (stylized-html source manual*
|
|
|
|
|
#:languages languages
|
|
|
|
|
#:manual manual)
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:mono-node-indexes mono-node-indexes
|
|
|
|
|
#:split-node-indexes split-node-indexes
|
2019-09-06 16:59:32 -04:00
|
|
|
|
#:name (string-append name "-highlighted"))))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(define* (pdf-manual source #:key (languages %languages)
|
|
|
|
|
(version "0.0")
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(manual %manual)
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(date 1)
|
|
|
|
|
(options '()))
|
|
|
|
|
"Return the HTML manuals built from SOURCE for all LANGUAGES, with the given
|
|
|
|
|
makeinfo OPTIONS."
|
|
|
|
|
(define manual-source
|
|
|
|
|
(texinfo-manual-source source
|
|
|
|
|
#:version version
|
|
|
|
|
#:languages languages
|
|
|
|
|
#:date date))
|
|
|
|
|
|
|
|
|
|
;; FIXME: This union works, except for the table of contents of non-English
|
|
|
|
|
;; manuals, which contains escape sequences like "^^ca^^fe" instead of
|
|
|
|
|
;; accented letters.
|
|
|
|
|
;;
|
|
|
|
|
;; (define texlive
|
gnu: Replace all uses of texlive-union by texlive-updmap.cfg.
* doc/build.scm (pdf-manual) Replace texlive-union by texlive-updmap.cfg.
* gnu/packages/algebra.scm (pari-gp): Likewise.
* gnu/packages/bioinformatics.scm (discrover, velvet): Likewise.
* gnu/packages/chez.scm (chez-scheme, chez-web, chez-sockets): Likewise.
* gnu/packages/docbook.scm (dblatex): Likewise.
* gnu/packages/emacs-xyz.scm (emacs-auctex): Likewise.
* gnu/packages/engineering.scm (fastcap): Likewise.
* gnu/packages/guile-xyz.scm (emacsy, guile-cv): Likewise.
* gnu/packages/lisp.scm (sbcl): Likewise.
* gnu/packages/maths.scm (octave, hypre): Likewise.
* gnu/packages/music.scm (lilypond): Likewise.
* gnu/packages/plotutils.scm (asymptote): Likewise.
* gnu/packages/python-xyz.scm (python-numpy-documentation)
(python-matplotlib-documentation, python-ipython-documentation)
(python-pypandoc): Likewise.
* gnu/packages/radio.scm (gnuradio, libosmo-dsp): Likewise.
* gnu/packages/scheme.scm (mit-scheme): Likewise.
* gnu/packages/statistics.scm (r-with-tests): Likewise.
* gnu/packages/tex.scm (simple-texlive-package)
(texlive-xmltex, texlive-tiny, texlive-jadetex, teximpatient, lyx): Likewise.
2021-01-14 00:23:38 -05:00
|
|
|
|
;; (texlive-updmap.cfg (list texlive-tex-texinfo
|
2019-07-07 09:00:43 -04:00
|
|
|
|
;; texlive-generic-epsf
|
|
|
|
|
;; texlive-fonts-ec)))
|
|
|
|
|
|
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(srfi srfi-34)
|
|
|
|
|
(ice-9 match))
|
|
|
|
|
|
|
|
|
|
(define (normalize language) ;XXX: deduplicate
|
|
|
|
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
|
|
|
|
(string-map (match-lambda
|
|
|
|
|
(#\_ #\-)
|
|
|
|
|
(chr chr))
|
|
|
|
|
(string-downcase language)))
|
|
|
|
|
|
|
|
|
|
;; Install a UTF-8 locale so that 'makeinfo' is at ease.
|
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
|
#+(file-append glibc-utf8-locales "/lib/locale"))
|
|
|
|
|
(setenv "LC_ALL" "en_US.utf8")
|
|
|
|
|
(setenv "PATH"
|
|
|
|
|
(string-append #+(file-append texlive "/bin") ":"
|
|
|
|
|
#+(file-append texinfo "/bin") ":"
|
|
|
|
|
|
|
|
|
|
;; Below are command-line tools needed by
|
|
|
|
|
;; 'texi2dvi' and friends.
|
|
|
|
|
#+(file-append sed "/bin") ":"
|
|
|
|
|
#+(file-append grep "/bin") ":"
|
|
|
|
|
#+(file-append coreutils "/bin") ":"
|
|
|
|
|
#+(file-append gawk "/bin") ":"
|
|
|
|
|
#+(file-append tar "/bin") ":"
|
|
|
|
|
#+(file-append diffutils "/bin")))
|
|
|
|
|
|
|
|
|
|
(setvbuf (current-output-port) 'line)
|
|
|
|
|
(setvbuf (current-error-port) 'line)
|
|
|
|
|
|
|
|
|
|
(setenv "HOME" (getcwd)) ;for kpathsea/mktextfm
|
|
|
|
|
|
|
|
|
|
;; 'SOURCE_DATE_EPOCH' is honored by pdftex.
|
|
|
|
|
(setenv "SOURCE_DATE_EPOCH" "1")
|
|
|
|
|
|
|
|
|
|
(for-each (lambda (language)
|
|
|
|
|
(let ((opts `("--pdf"
|
|
|
|
|
"-I" "."
|
|
|
|
|
#$@options
|
|
|
|
|
,(if (string=? language "en")
|
|
|
|
|
(string-append #$manual-source "/"
|
|
|
|
|
#$manual ".texi")
|
|
|
|
|
(string-append #$manual-source "/"
|
|
|
|
|
#$manual "." language ".texi")))))
|
|
|
|
|
(format #t "building PDF manual for language '~a'...~%"
|
|
|
|
|
language)
|
|
|
|
|
(mkdir-p (string-append #$output "/"
|
|
|
|
|
(normalize language)))
|
|
|
|
|
(setenv "LANGUAGE" language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; FIXME: Unfortunately building PDFs for non-Latin
|
|
|
|
|
;; alphabets doesn't work:
|
|
|
|
|
;; <https://lists.gnu.org/archive/html/help-texinfo/2012-01/msg00014.html>.
|
|
|
|
|
(guard (c ((invoke-error? c)
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"~%~%Failed to produce \
|
|
|
|
|
PDF for language '~a'!~%~%"
|
|
|
|
|
language)))
|
|
|
|
|
(apply invoke #$(file-append texinfo "/bin/makeinfo")
|
|
|
|
|
"--pdf" "-o"
|
|
|
|
|
(string-append #$output "/"
|
|
|
|
|
(normalize language)
|
|
|
|
|
"/" #$manual
|
|
|
|
|
(if (string=? language "en")
|
|
|
|
|
""
|
|
|
|
|
(string-append "."
|
|
|
|
|
language))
|
|
|
|
|
".pdf")
|
|
|
|
|
opts))))
|
|
|
|
|
'#$languages))))
|
|
|
|
|
|
2021-10-28 12:13:53 -04:00
|
|
|
|
(computed-file (string-append manual "-pdf-manual") build
|
|
|
|
|
#:local-build? #f))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(define (guix-manual-text-domain source languages)
|
|
|
|
|
"Return the PO files for LANGUAGES of the 'guix-manual' text domain taken
|
|
|
|
|
from SOURCE."
|
|
|
|
|
(define po-directory
|
|
|
|
|
(file-append* source "/po/doc"))
|
|
|
|
|
|
|
|
|
|
(define build
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils))
|
|
|
|
|
|
|
|
|
|
(mkdir-p #$output)
|
|
|
|
|
(for-each (lambda (language)
|
|
|
|
|
(define directory
|
|
|
|
|
(string-append #$output "/" language
|
|
|
|
|
"/LC_MESSAGES"))
|
|
|
|
|
|
|
|
|
|
(mkdir-p directory)
|
|
|
|
|
(invoke #+(file-append gnu-gettext "/bin/msgfmt")
|
|
|
|
|
"-c" "-o"
|
|
|
|
|
(string-append directory "/guix-manual.mo")
|
|
|
|
|
(string-append #$po-directory "/guix-manual."
|
|
|
|
|
language ".po")))
|
|
|
|
|
'#$(delete "en" languages)))))
|
|
|
|
|
|
|
|
|
|
(computed-file "guix-manual-po" build))
|
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(define* (localization-helper-module source
|
|
|
|
|
#:optional (languages %languages))
|
|
|
|
|
"Return a file-like object for use as the (localization) module. SOURCE
|
|
|
|
|
must be the Guix top-level source directory, from which PO files are taken."
|
|
|
|
|
(define content
|
|
|
|
|
(with-extensions (list guile-json-3)
|
|
|
|
|
#~(begin
|
|
|
|
|
(define-module (localization)
|
|
|
|
|
#:use-module (json)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-19)
|
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (ice-9 popen)
|
|
|
|
|
#:export (normalize
|
|
|
|
|
with-language
|
|
|
|
|
translate
|
|
|
|
|
language-code->name
|
2022-01-18 16:16:12 -05:00
|
|
|
|
language-code->native-name
|
2022-01-17 16:28:52 -05:00
|
|
|
|
seconds->string))
|
|
|
|
|
|
|
|
|
|
(define (normalize language) ;XXX: deduplicate
|
|
|
|
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
|
|
|
|
(string-map (match-lambda
|
|
|
|
|
(#\_ #\-)
|
|
|
|
|
(chr chr))
|
|
|
|
|
(string-downcase language)))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-language language exp ...)
|
|
|
|
|
(let ((lang (getenv "LANGUAGE")))
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
(lambda ()
|
|
|
|
|
(setenv "LANGUAGE" language)
|
|
|
|
|
(setlocale LC_MESSAGES))
|
|
|
|
|
(lambda () exp ...)
|
|
|
|
|
(lambda ()
|
|
|
|
|
(if lang
|
|
|
|
|
(setenv "LANGUAGE" lang)
|
|
|
|
|
(unsetenv "LANGUAGE"))
|
|
|
|
|
(setlocale LC_MESSAGES)))))
|
|
|
|
|
|
|
|
|
|
;; (put 'with-language 'scheme-indent-function 1)
|
|
|
|
|
(define* (translate str language
|
|
|
|
|
#:key (domain "guix-manual"))
|
|
|
|
|
(define exp
|
|
|
|
|
`(begin
|
|
|
|
|
(bindtextdomain "guix-manual"
|
|
|
|
|
#+(guix-manual-text-domain
|
|
|
|
|
source
|
|
|
|
|
languages))
|
|
|
|
|
(bindtextdomain "iso_639-3" ;language names
|
|
|
|
|
#+(file-append iso-codes
|
|
|
|
|
"/share/locale"))
|
2022-01-18 16:16:12 -05:00
|
|
|
|
(setenv "LANGUAGE" ,language)
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(write (gettext ,str ,domain))))
|
|
|
|
|
|
2022-01-18 16:16:12 -05:00
|
|
|
|
;; Since the 'gettext' function caches msgid translations,
|
|
|
|
|
;; regardless of $LANGUAGE, we have to spawn a new process each
|
|
|
|
|
;; time we want to translate to a different language. Bah!
|
|
|
|
|
(let* ((pipe (open-pipe* OPEN_READ
|
|
|
|
|
#+(file-append guile-3.0
|
|
|
|
|
"/bin/guile")
|
|
|
|
|
"-c" (object->string exp)))
|
|
|
|
|
(str (read pipe)))
|
|
|
|
|
(close-pipe pipe)
|
|
|
|
|
str))
|
2022-01-17 16:28:52 -05:00
|
|
|
|
|
|
|
|
|
(define %iso639-languages
|
|
|
|
|
(vector->list
|
|
|
|
|
(assoc-ref (call-with-input-file
|
|
|
|
|
#+(file-append iso-codes
|
|
|
|
|
"/share/iso-codes/json/iso_639-3.json")
|
|
|
|
|
json->scm)
|
|
|
|
|
"639-3")))
|
|
|
|
|
|
|
|
|
|
(define (language-code->name code)
|
|
|
|
|
"Return the full name of a language from its ISO-639-3 code."
|
|
|
|
|
(let ((code (match (string-index code #\_)
|
|
|
|
|
(#f code)
|
|
|
|
|
(index (string-take code index)))))
|
|
|
|
|
(any (lambda (language)
|
|
|
|
|
(and (string=? (or (assoc-ref language "alpha_2")
|
|
|
|
|
(assoc-ref language "alpha_3"))
|
|
|
|
|
code)
|
|
|
|
|
(assoc-ref language "name")))
|
|
|
|
|
%iso639-languages)))
|
|
|
|
|
|
2022-01-18 16:16:12 -05:00
|
|
|
|
(define (language-code->native-name code)
|
|
|
|
|
"Return the name of language CODE in that language."
|
|
|
|
|
(translate (language-code->name code) code
|
|
|
|
|
#:domain "iso_639-3"))
|
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(define (seconds->string seconds language)
|
|
|
|
|
(let* ((time (make-time time-utc 0 seconds))
|
|
|
|
|
(date (time-utc->date time)))
|
|
|
|
|
(with-language language (date->string date "~e ~B ~Y")))))))
|
|
|
|
|
|
|
|
|
|
(scheme-file "localization.scm" content))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(define* (html-manual-indexes source
|
|
|
|
|
#:key (languages %languages)
|
|
|
|
|
(version "0.0")
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(manual %manual)
|
2019-10-22 11:45:19 -04:00
|
|
|
|
(title (if (string=? "guix" manual)
|
|
|
|
|
"GNU Guix Reference Manual"
|
|
|
|
|
"GNU Guix Cookbook"))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(date 1))
|
|
|
|
|
(define build
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(with-imported-modules `((guix build utils)
|
|
|
|
|
((localization)
|
|
|
|
|
=> ,(localization-helper-module
|
|
|
|
|
source languages)))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(localization)
|
|
|
|
|
(sxml simple)
|
|
|
|
|
(srfi srfi-1))
|
|
|
|
|
|
|
|
|
|
(define (guix-url path)
|
|
|
|
|
(string-append #$%web-site-url path))
|
|
|
|
|
|
|
|
|
|
(define (sxml-index language title body)
|
|
|
|
|
;; FIXME: Avoid duplicating styling info from guix-artwork.git.
|
|
|
|
|
`(html (@ (lang ,language))
|
|
|
|
|
(head
|
|
|
|
|
(title ,(string-append title " — GNU Guix"))
|
|
|
|
|
(meta (@ (charset "UTF-8")))
|
|
|
|
|
(meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0")))
|
|
|
|
|
;; Menu prefetch.
|
|
|
|
|
(link (@ (rel "prefetch") (href ,(guix-url "menu/index.html"))))
|
|
|
|
|
;; Base CSS.
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css"))))
|
|
|
|
|
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css"))))
|
|
|
|
|
(link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css")))))
|
|
|
|
|
(body
|
|
|
|
|
(header (@ (class "navbar"))
|
|
|
|
|
(h1 (a (@ (class "branding")
|
|
|
|
|
(href #$%web-site-url)))
|
|
|
|
|
(span (@ (class "a11y-offset"))
|
|
|
|
|
"Guix"))
|
|
|
|
|
(nav (@ (class "menu"))))
|
|
|
|
|
(nav (@ (class "breadcrumbs"))
|
|
|
|
|
(a (@ (class "crumb")
|
|
|
|
|
(href #$%web-site-url))
|
|
|
|
|
"Home"))
|
|
|
|
|
,body
|
|
|
|
|
(footer))))
|
|
|
|
|
|
|
|
|
|
(define (language-index language)
|
|
|
|
|
(define title
|
|
|
|
|
(translate #$title language))
|
|
|
|
|
|
|
|
|
|
(sxml-index
|
|
|
|
|
language title
|
|
|
|
|
`(main
|
|
|
|
|
(article
|
|
|
|
|
(@ (class "page centered-block limit-width"))
|
|
|
|
|
(h2 ,title)
|
|
|
|
|
(p (@ (class "post-metadata centered-text"))
|
|
|
|
|
#$version " — "
|
|
|
|
|
,(seconds->string #$date language))
|
|
|
|
|
|
|
|
|
|
(div
|
|
|
|
|
(ul
|
|
|
|
|
(li (a (@ (href "html_node"))
|
|
|
|
|
"HTML, with a separate page per node"))
|
|
|
|
|
(li (a (@ (href
|
|
|
|
|
,(string-append
|
|
|
|
|
#$manual
|
|
|
|
|
(if (string=? language
|
|
|
|
|
"en")
|
|
|
|
|
""
|
|
|
|
|
(string-append "."
|
|
|
|
|
language))
|
|
|
|
|
".html")))
|
|
|
|
|
"HTML, entirely on one page"))
|
|
|
|
|
,@(if (member language '("ru" "zh_CN"))
|
|
|
|
|
'()
|
|
|
|
|
`((li (a (@ (href ,(string-append
|
|
|
|
|
#$manual
|
|
|
|
|
(if (string=? language "en")
|
|
|
|
|
""
|
|
|
|
|
(string-append "."
|
|
|
|
|
language))
|
|
|
|
|
".pdf"))))
|
|
|
|
|
"PDF")))))))))
|
|
|
|
|
|
|
|
|
|
(define (top-level-index languages)
|
|
|
|
|
(define title #$title)
|
|
|
|
|
(sxml-index
|
|
|
|
|
"en" title
|
|
|
|
|
`(main
|
|
|
|
|
(article
|
|
|
|
|
(@ (class "page centered-block limit-width"))
|
|
|
|
|
(h2 ,title)
|
|
|
|
|
(div
|
|
|
|
|
"This document is available in the following
|
2019-07-15 06:33:07 -04:00
|
|
|
|
languages:\n"
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(ul
|
|
|
|
|
,@(map (lambda (language)
|
|
|
|
|
`(li (a (@ (href ,(normalize language)))
|
2022-01-18 16:16:12 -05:00
|
|
|
|
,(language-code->native-name language))))
|
2022-01-17 16:28:52 -05:00
|
|
|
|
languages)))))))
|
|
|
|
|
|
|
|
|
|
(define (write-html file sxml)
|
|
|
|
|
(call-with-output-file file
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display "<!DOCTYPE html>\n" port)
|
|
|
|
|
(sxml->xml sxml port))))
|
2019-07-15 06:33:07 -04:00
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
|
#+(file-append glibc-utf8-locales "/lib/locale"))
|
|
|
|
|
(setenv "LC_ALL" "en_US.utf8")
|
|
|
|
|
(setlocale LC_ALL "en_US.utf8")
|
2019-07-15 06:33:07 -04:00
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(for-each (lambda (language)
|
|
|
|
|
(define directory
|
|
|
|
|
(string-append #$output "/"
|
|
|
|
|
(normalize language)))
|
2019-07-15 06:33:07 -04:00
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(mkdir-p directory)
|
|
|
|
|
(write-html (string-append directory "/index.html")
|
|
|
|
|
(language-index language)))
|
|
|
|
|
'#$languages)
|
2019-07-15 06:33:07 -04:00
|
|
|
|
|
2022-01-17 16:28:52 -05:00
|
|
|
|
(write-html (string-append #$output "/index.html")
|
|
|
|
|
(top-level-index '#$languages)))))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(computed-file "html-indexes" build))
|
|
|
|
|
|
|
|
|
|
(define* (pdf+html-manual source
|
|
|
|
|
#:key (languages %languages)
|
|
|
|
|
(version "0.0")
|
|
|
|
|
(date (time-second (current-time time-utc)))
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(mono-node-indexes (map list %languages))
|
|
|
|
|
(split-node-indexes (map list %languages))
|
2019-10-21 12:01:45 -04:00
|
|
|
|
(manual %manual))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
"Return the union of the HTML and PDF manuals, as well as the indexes."
|
|
|
|
|
(directory-union (string-append manual "-manual")
|
|
|
|
|
(map (lambda (proc)
|
|
|
|
|
(proc source
|
|
|
|
|
#:date date
|
|
|
|
|
#:languages languages
|
|
|
|
|
#:version version
|
|
|
|
|
#:manual manual))
|
|
|
|
|
(list html-manual-indexes
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(lambda (source . args)
|
|
|
|
|
(apply html-manual source
|
|
|
|
|
#:mono-node-indexes mono-node-indexes
|
|
|
|
|
#:split-node-indexes split-node-indexes
|
|
|
|
|
args))
|
|
|
|
|
pdf-manual))
|
2019-07-07 09:00:43 -04:00
|
|
|
|
#:copy? #t))
|
|
|
|
|
|
|
|
|
|
(define (latest-commit+date directory)
|
|
|
|
|
"Return two values: the last commit ID (a hex string) for DIRECTORY, and its
|
|
|
|
|
commit date (an integer)."
|
|
|
|
|
(let* ((repository (repository-open directory))
|
|
|
|
|
(head (repository-head repository))
|
|
|
|
|
(oid (reference-target head))
|
|
|
|
|
(commit (commit-lookup repository oid)))
|
|
|
|
|
;; TODO: Use (git describe) when it's widely available.
|
|
|
|
|
(values (oid->string oid) (commit-time commit))))
|
|
|
|
|
|
2020-10-17 15:53:26 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Guile manual.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define guile-manual
|
|
|
|
|
;; The Guile manual as HTML, including both the mono-node "guile.html" and
|
|
|
|
|
;; the split-node "html_node" directory.
|
|
|
|
|
(let ((guile guile-3.0-latest))
|
|
|
|
|
(computed-file (string-append "guile-manual-" (package-version guile))
|
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
|
(ice-9 match))
|
|
|
|
|
|
|
|
|
|
(setenv "PATH"
|
|
|
|
|
(string-append #+tar "/bin:"
|
|
|
|
|
#+xz "/bin:"
|
|
|
|
|
#+texinfo "/bin"))
|
|
|
|
|
(invoke "tar" "xf" #$(package-source guile))
|
|
|
|
|
(mkdir-p (string-append #$output "/en/html_node"))
|
|
|
|
|
|
|
|
|
|
(let* ((texi (find-files "." "^guile\\.texi$"))
|
|
|
|
|
(documentation (match texi
|
|
|
|
|
((file) (dirname file)))))
|
|
|
|
|
(with-directory-excursion documentation
|
|
|
|
|
(invoke "makeinfo" "--html" "--no-split"
|
|
|
|
|
"-o" (string-append #$output
|
|
|
|
|
"/en/guile.html")
|
|
|
|
|
"guile.texi")
|
|
|
|
|
(invoke "makeinfo" "--html" "-o" "split"
|
|
|
|
|
"guile.texi")
|
|
|
|
|
(copy-recursively
|
|
|
|
|
"split"
|
|
|
|
|
(string-append #$output "/en/html_node")))))))))
|
|
|
|
|
|
|
|
|
|
(define %guile-manual-base-url
|
|
|
|
|
"https://www.gnu.org/software/guile/manual")
|
|
|
|
|
|
|
|
|
|
(define (for-all-languages index)
|
|
|
|
|
(map (lambda (language)
|
|
|
|
|
(list language index))
|
|
|
|
|
%languages))
|
|
|
|
|
|
|
|
|
|
(define guile-mono-node-indexes
|
|
|
|
|
;; The Guile manual is only available in English so use the same index in
|
|
|
|
|
;; all languages.
|
|
|
|
|
(for-all-languages
|
|
|
|
|
(html-manual-identifier-index (file-append guile-manual "/en")
|
|
|
|
|
%guile-manual-base-url
|
|
|
|
|
#:name "guile-html-index-en")))
|
|
|
|
|
|
|
|
|
|
(define guile-split-node-indexes
|
|
|
|
|
(for-all-languages
|
|
|
|
|
(html-manual-identifier-index (file-append guile-manual "/en/html_node")
|
|
|
|
|
(string-append %guile-manual-base-url
|
|
|
|
|
"/html_node")
|
|
|
|
|
#:name "guile-html-index-en")))
|
|
|
|
|
|
|
|
|
|
(define (merge-index-alists alist1 alist2)
|
|
|
|
|
"Merge ALIST1 and ALIST2, both of which are list of tuples like:
|
|
|
|
|
|
|
|
|
|
(LANGUAGE INDEX1 INDEX2 ...)
|
|
|
|
|
|
|
|
|
|
where LANGUAGE is a string like \"en\" and INDEX1 etc. are indexes as returned
|
|
|
|
|
by 'html-identifier-indexes'."
|
|
|
|
|
(let ((languages (delete-duplicates
|
|
|
|
|
(append (match alist1
|
|
|
|
|
(((languages . _) ...)
|
|
|
|
|
languages))
|
|
|
|
|
(match alist2
|
|
|
|
|
(((languages . _) ...)
|
|
|
|
|
languages))))))
|
|
|
|
|
(map (lambda (language)
|
|
|
|
|
(cons language
|
|
|
|
|
(append (or (assoc-ref alist1 language) '())
|
|
|
|
|
(or (assoc-ref alist2 language) '()))))
|
|
|
|
|
languages)))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
|
|
|
|
|
(let* ((root (canonicalize-path
|
|
|
|
|
(string-append (current-source-directory) "/..")))
|
2020-10-16 16:04:33 -04:00
|
|
|
|
(commit date (latest-commit+date root))
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(version (or (getenv "GUIX_MANUAL_VERSION")
|
|
|
|
|
(string-take commit 7)))
|
2020-10-16 16:04:33 -04:00
|
|
|
|
(select? (let ((vcs? (git-predicate root)))
|
|
|
|
|
(lambda (file stat)
|
|
|
|
|
(and (vcs? file stat)
|
|
|
|
|
;; Filter out this file.
|
2020-10-17 08:32:53 -04:00
|
|
|
|
(not (string=? (basename file) "build.scm"))))))
|
|
|
|
|
(source (local-file root "guix" #:recursive? #t
|
|
|
|
|
#:select? select?)))
|
|
|
|
|
|
|
|
|
|
(define guix-manual
|
|
|
|
|
(html-manual source
|
|
|
|
|
#:manual "guix"
|
|
|
|
|
#:version version
|
|
|
|
|
#:date date))
|
|
|
|
|
|
2020-10-17 15:53:26 -04:00
|
|
|
|
(define guix-mono-node-indexes
|
2020-10-17 08:32:53 -04:00
|
|
|
|
;; Alist of indexes for GUIX-MANUAL, where each key is a language code and
|
|
|
|
|
;; each value is a file-like object containing the identifier index.
|
|
|
|
|
(html-identifier-indexes guix-manual ""
|
2020-10-17 15:53:26 -04:00
|
|
|
|
#:manual-name "guix"
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:base-url (if (string=? %manual "guix")
|
|
|
|
|
(const "")
|
2020-10-20 17:19:48 -04:00
|
|
|
|
(cut string-append
|
|
|
|
|
"/manual/devel/" <>))
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:languages %languages))
|
|
|
|
|
|
2020-10-17 15:53:26 -04:00
|
|
|
|
(define guix-split-node-indexes
|
2020-10-17 08:32:53 -04:00
|
|
|
|
;; Likewise for the split-node variant of GUIX-MANUAL.
|
|
|
|
|
(html-identifier-indexes guix-manual "/html_node"
|
2020-10-17 15:53:26 -04:00
|
|
|
|
#:manual-name "guix"
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:base-url (if (string=? %manual "guix")
|
|
|
|
|
(const "")
|
2020-10-20 17:19:48 -04:00
|
|
|
|
(cut string-append
|
|
|
|
|
"/manual/devel/" <>
|
|
|
|
|
"/html_node"))
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:languages %languages))
|
|
|
|
|
|
2020-10-17 15:53:26 -04:00
|
|
|
|
(define mono-node-indexes
|
|
|
|
|
(merge-index-alists guix-mono-node-indexes guile-mono-node-indexes))
|
|
|
|
|
|
|
|
|
|
(define split-node-indexes
|
|
|
|
|
(merge-index-alists guix-split-node-indexes guile-split-node-indexes))
|
|
|
|
|
|
2019-07-07 09:00:43 -04:00
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"building manual from work tree around commit ~a, ~a~%"
|
|
|
|
|
commit
|
|
|
|
|
(let* ((time (make-time time-utc 0 date))
|
|
|
|
|
(date (time-utc->date time)))
|
|
|
|
|
(date->string date "~e ~B ~Y")))
|
2020-10-17 08:32:53 -04:00
|
|
|
|
|
|
|
|
|
(pdf+html-manual source
|
2020-10-17 15:53:26 -04:00
|
|
|
|
;; Always use the identifier indexes of GUIX-MANUAL and
|
|
|
|
|
;; GUILE-MANUAL. Both "guix" and "guix-cookbook" can
|
|
|
|
|
;; contain links to definitions that appear in either of
|
|
|
|
|
;; these two manuals.
|
2020-10-17 08:32:53 -04:00
|
|
|
|
#:mono-node-indexes mono-node-indexes
|
|
|
|
|
#:split-node-indexes split-node-indexes
|
|
|
|
|
#:version version
|
2019-07-07 09:00:43 -04:00
|
|
|
|
#:date date))
|