doc: Build a top-level index of the manuals.
Suggested by Julien Lepiller. * doc/build.scm (html-manual-indexes)[build]: Add 'with-extensions'. (translate): Actually honor DOMAIN. Add call to 'bindtextdomain' for ISO-CODES. (%iso639-languages): New variable. (language-code->name, top-level-index): New procedures. Add call to 'write-html' for OUTPUT/index.html.
This commit is contained in:
parent
21bec78357
commit
e591541d36
1 changed files with 188 additions and 140 deletions
|
@ -34,6 +34,7 @@
|
||||||
(gnu packages gawk)
|
(gnu packages gawk)
|
||||||
(gnu packages gettext)
|
(gnu packages gettext)
|
||||||
(gnu packages guile)
|
(gnu packages guile)
|
||||||
|
(gnu packages iso-codes)
|
||||||
(gnu packages texinfo)
|
(gnu packages texinfo)
|
||||||
(gnu packages tex)
|
(gnu packages tex)
|
||||||
(srfi srfi-19)
|
(srfi srfi-19)
|
||||||
|
@ -183,7 +184,7 @@ makeinfo OPTIONS."
|
||||||
(ice-9 match))
|
(ice-9 match))
|
||||||
|
|
||||||
(define (normalize language)
|
(define (normalize language)
|
||||||
;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn".
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
||||||
(string-map (match-lambda
|
(string-map (match-lambda
|
||||||
(#\_ #\-)
|
(#\_ #\-)
|
||||||
(chr chr))
|
(chr chr))
|
||||||
|
@ -365,16 +366,19 @@ from SOURCE."
|
||||||
(manual "guix")
|
(manual "guix")
|
||||||
(date 1))
|
(date 1))
|
||||||
(define build
|
(define build
|
||||||
|
(with-extensions (list guile-json-3)
|
||||||
(with-imported-modules '((guix build utils))
|
(with-imported-modules '((guix build utils))
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils)
|
(use-modules (guix build utils)
|
||||||
|
(json)
|
||||||
(ice-9 match)
|
(ice-9 match)
|
||||||
(ice-9 popen)
|
(ice-9 popen)
|
||||||
(sxml simple)
|
(sxml simple)
|
||||||
|
(srfi srfi-1)
|
||||||
(srfi srfi-19))
|
(srfi srfi-19))
|
||||||
|
|
||||||
(define (normalize language) ;XXX: deduplicate
|
(define (normalize language) ;XXX: deduplicate
|
||||||
;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn".
|
;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
|
||||||
(string-map (match-lambda
|
(string-map (match-lambda
|
||||||
(#\_ #\-)
|
(#\_ #\-)
|
||||||
(chr chr))
|
(chr chr))
|
||||||
|
@ -402,7 +406,10 @@ from SOURCE."
|
||||||
#+(guix-manual-text-domain
|
#+(guix-manual-text-domain
|
||||||
source
|
source
|
||||||
languages))
|
languages))
|
||||||
(write (gettext ,str "guix-manual"))))
|
(bindtextdomain "iso_639-3" ;language names
|
||||||
|
#+(file-append iso-codes
|
||||||
|
"/share/locale"))
|
||||||
|
(write (gettext ,str ,domain))))
|
||||||
|
|
||||||
(with-language language
|
(with-language language
|
||||||
;; Since the 'gettext' function caches msgid translations,
|
;; Since the 'gettext' function caches msgid translations,
|
||||||
|
@ -497,6 +504,47 @@ from SOURCE."
|
||||||
".pdf"))))
|
".pdf"))))
|
||||||
"PDF")))))))))
|
"PDF")))))))))
|
||||||
|
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
(define (top-level-index languages)
|
||||||
|
(define title
|
||||||
|
"GNU Guix Reference Manual")
|
||||||
|
(sxml-index
|
||||||
|
"en" title
|
||||||
|
`(main
|
||||||
|
(article
|
||||||
|
(@ (class "page centered-block limit-width"))
|
||||||
|
(h2 ,title)
|
||||||
|
(div
|
||||||
|
"The GNU Guix Reference Manual is available in the following
|
||||||
|
languages:\n"
|
||||||
|
(ul
|
||||||
|
,@(map (lambda (language)
|
||||||
|
`(li (a (@ (href ,(normalize language)))
|
||||||
|
,(translate
|
||||||
|
(language-code->name language)
|
||||||
|
language
|
||||||
|
#:domain "iso_639-3"))))
|
||||||
|
languages)))))))
|
||||||
|
|
||||||
(define (write-html file sxml)
|
(define (write-html file sxml)
|
||||||
(call-with-output-file file
|
(call-with-output-file file
|
||||||
(lambda (port)
|
(lambda (port)
|
||||||
|
@ -508,9 +556,6 @@ from SOURCE."
|
||||||
(setenv "LC_ALL" "en_US.utf8")
|
(setenv "LC_ALL" "en_US.utf8")
|
||||||
(setlocale LC_ALL "en_US.utf8")
|
(setlocale LC_ALL "en_US.utf8")
|
||||||
|
|
||||||
(bindtextdomain "guix-manual"
|
|
||||||
#+(guix-manual-text-domain source languages))
|
|
||||||
|
|
||||||
(for-each (lambda (language)
|
(for-each (lambda (language)
|
||||||
(define directory
|
(define directory
|
||||||
(string-append #$output "/"
|
(string-append #$output "/"
|
||||||
|
@ -519,7 +564,10 @@ from SOURCE."
|
||||||
(mkdir-p directory)
|
(mkdir-p directory)
|
||||||
(write-html (string-append directory "/index.html")
|
(write-html (string-append directory "/index.html")
|
||||||
(language-index language)))
|
(language-index language)))
|
||||||
'#$languages))))
|
'#$languages)
|
||||||
|
|
||||||
|
(write-html (string-append #$output "/index.html")
|
||||||
|
(top-level-index '#$languages))))))
|
||||||
|
|
||||||
(computed-file "html-indexes" build))
|
(computed-file "html-indexes" build))
|
||||||
|
|
||||||
|
|
Reference in a new issue