summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-07-15 12:33:07 +0200
committerLudovic Courtès <ludo@gnu.org>2019-07-15 12:53:32 +0200
commit0c04bdb948717775f6143f5b0e93fcc5c41b169b (patch)
treee038ba82b421587cda4917b29646fc1c29a66392
parent4e67f2048839c17e7d09f6c1775473018c8815c6 (diff)
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.
-rw-r--r--doc/build.scm360
1 files changed, 204 insertions, 156 deletions
diff --git a/doc/build.scm b/doc/build.scm
index c0952ecb89d..a2f353a090b 100644
--- a/doc/build.scm
+++ b/doc/build.scm
@@ -34,6 +34,7 @@
34 (gnu packages gawk) 34 (gnu packages gawk)
35 (gnu packages gettext) 35 (gnu packages gettext)
36 (gnu packages guile) 36 (gnu packages guile)
37 (gnu packages iso-codes)
37 (gnu packages texinfo) 38 (gnu packages texinfo)
38 (gnu packages tex) 39 (gnu packages tex)
39 (srfi srfi-19) 40 (srfi srfi-19)
@@ -183,7 +184,7 @@ makeinfo OPTIONS."
183 (ice-9 match)) 184 (ice-9 match))
184 185
185 (define (normalize language) 186 (define (normalize language)
186 ;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn". 187 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
187 (string-map (match-lambda 188 (string-map (match-lambda
188 (#\_ #\-) 189 (#\_ #\-)
189 (chr chr)) 190 (chr chr))
@@ -365,161 +366,208 @@ from SOURCE."
365 (manual "guix") 366 (manual "guix")
366 (date 1)) 367 (date 1))
367 (define build 368 (define build
368 (with-imported-modules '((guix build utils)) 369 (with-extensions (list guile-json-3)
369 #~(begin 370 (with-imported-modules '((guix build utils))
370 (use-modules (guix build utils) 371 #~(begin
371 (ice-9 match) 372 (use-modules (guix build utils)
372 (ice-9 popen) 373 (json)
373 (sxml simple) 374 (ice-9 match)
374 (srfi srfi-19)) 375 (ice-9 popen)
375 376 (sxml simple)
376 (define (normalize language) ;XXX: deduplicate 377 (srfi srfi-1)
377 ;; Normalize LANGUAGE. For instance, "zh_CN" become "zh-cn". 378 (srfi srfi-19))
378 (string-map (match-lambda 379
379 (#\_ #\-) 380 (define (normalize language) ;XXX: deduplicate
380 (chr chr)) 381 ;; Normalize LANGUAGE. For instance, "zh_CN" becomes "zh-cn".
381 (string-downcase language))) 382 (string-map (match-lambda
382 383 (#\_ #\-)
383 (define-syntax-rule (with-language language exp ...) 384 (chr chr))
384 (let ((lang (getenv "LANGUAGE"))) 385 (string-downcase language)))
385 (dynamic-wind 386
386 (lambda () 387 (define-syntax-rule (with-language language exp ...)
387 (setenv "LANGUAGE" language) 388 (let ((lang (getenv "LANGUAGE")))
388 (setlocale LC_MESSAGES)) 389 (dynamic-wind
389 (lambda () exp ...) 390 (lambda ()
390 (lambda () 391 (setenv "LANGUAGE" language)
391 (if lang 392 (setlocale LC_MESSAGES))
392 (setenv "LANGUAGE" lang) 393 (lambda () exp ...)
393 (unsetenv "LANGUAGE")) 394 (lambda ()
394 (setlocale LC_MESSAGES))))) 395 (if lang
395 396 (setenv "LANGUAGE" lang)
396 ;; (put 'with-language 'scheme-indent-function 1) 397 (unsetenv "LANGUAGE"))
397 (define* (translate str language 398 (setlocale LC_MESSAGES)))))
398 #:key (domain "guix-manual")) 399
399 (define exp 400 ;; (put 'with-language 'scheme-indent-function 1)
400 `(begin 401 (define* (translate str language
401 (bindtextdomain "guix-manual" 402 #:key (domain "guix-manual"))
402 #+(guix-manual-text-domain 403 (define exp
403 source 404 `(begin
404 languages)) 405 (bindtextdomain "guix-manual"
405 (write (gettext ,str "guix-manual")))) 406 #+(guix-manual-text-domain
406 407 source
407 (with-language language 408 languages))
408 ;; Since the 'gettext' function caches msgid translations, 409 (bindtextdomain "iso_639-3" ;language names
409 ;; regardless of $LANGUAGE, we have to spawn a new process each 410 #+(file-append iso-codes
410 ;; time we want to translate to a different language. Bah! 411 "/share/locale"))
411 (let* ((pipe (open-pipe* OPEN_READ 412 (write (gettext ,str ,domain))))
412 #+(file-append guile-2.2 413
413 "/bin/guile") 414 (with-language language
414 "-c" (object->string exp))) 415 ;; Since the 'gettext' function caches msgid translations,
415 (str (read pipe))) 416 ;; regardless of $LANGUAGE, we have to spawn a new process each
416 (close-pipe pipe) 417 ;; time we want to translate to a different language. Bah!
417 str))) 418 (let* ((pipe (open-pipe* OPEN_READ
418 419 #+(file-append guile-2.2
419 (define (seconds->string seconds language) 420 "/bin/guile")
420 (let* ((time (make-time time-utc 0 seconds)) 421 "-c" (object->string exp)))
421 (date (time-utc->date time))) 422 (str (read pipe)))
422 (with-language language (date->string date "~e ~B ~Y")))) 423 (close-pipe pipe)
423 424 str)))
424 (define (guix-url path) 425
425 (string-append #$%web-site-url path)) 426 (define (seconds->string seconds language)
426 427 (let* ((time (make-time time-utc 0 seconds))
427 (define (sxml-index language title body) 428 (date (time-utc->date time)))
428 ;; FIXME: Avoid duplicating styling info from guix-artwork.git. 429 (with-language language (date->string date "~e ~B ~Y"))))
429 `(html (@ (lang ,language)) 430
430 (head 431 (define (guix-url path)
431 (title ,(string-append title " — GNU Guix")) 432 (string-append #$%web-site-url path))
432 (meta (@ (charset "UTF-8"))) 433
433 (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0"))) 434 (define (sxml-index language title body)
434 ;; Menu prefetch. 435 ;; FIXME: Avoid duplicating styling info from guix-artwork.git.
435 (link (@ (rel "prefetch") (href ,(guix-url "menu/index.html")))) 436 `(html (@ (lang ,language))
436 ;; Base CSS. 437 (head
437 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css")))) 438 (title ,(string-append title " — GNU Guix"))
438 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css")))) 439 (meta (@ (charset "UTF-8")))
439 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css")))) 440 (meta (@ (name "viewport") (content "width=device-width, initial-scale=1.0")))
440 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css")))) 441 ;; Menu prefetch.
441 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css")))) 442 (link (@ (rel "prefetch") (href ,(guix-url "menu/index.html"))))
442 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css")))) 443 ;; Base CSS.
443 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css")))) 444 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/elements.css"))))
444 445 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/common.css"))))
445 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css")))) 446 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/messages.css"))))
446 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css"))))) 447 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/navbar.css"))))
447 (body 448 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/breadcrumbs.css"))))
448 (header (@ (class "navbar")) 449 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/buttons.css"))))
449 (h1 (a (@ (class "branding") 450 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/footer.css"))))
450 (href #$%web-site-url))) 451
451 (span (@ (class "a11y-offset")) 452 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/page.css"))))
452 "Guix")) 453 (link (@ (rel "stylesheet") (href ,(guix-url "static/base/css/post.css")))))
453 (nav (@ (class "menu")))) 454 (body
454 (nav (@ (class "breadcrumbs")) 455 (header (@ (class "navbar"))
455 (a (@ (class "crumb") 456 (h1 (a (@ (class "branding")
456 (href #$%web-site-url)) 457 (href #$%web-site-url)))
457 "Home")) 458 (span (@ (class "a11y-offset"))
458 ,body 459 "Guix"))
459 (footer)))) 460 (nav (@ (class "menu"))))
460 461 (nav (@ (class "breadcrumbs"))
461 (define (language-index language) 462 (a (@ (class "crumb")
462 (define title 463 (href #$%web-site-url))
463 (translate "GNU Guix Reference Manual" language)) 464 "Home"))
464 465 ,body
465 (sxml-index 466 (footer))))
466 language title 467
467 `(main 468 (define (language-index language)
468 (article 469 (define title
469 (@ (class "page centered-block limit-width")) 470 (translate "GNU Guix Reference Manual" language))
470 (h2 ,title) 471
471 (p (@ (class "post-metadata centered-text")) 472 (sxml-index
472 #$version " — " 473 language title
473 ,(seconds->string #$date language)) 474 `(main
474 475 (article
475 (div 476 (@ (class "page centered-block limit-width"))
476 (ul 477 (h2 ,title)
477 (li (a (@ (href "html_node")) 478 (p (@ (class "post-metadata centered-text"))
478 "HTML, with one page per node")) 479 #$version " — "
479 (li (a (@ (href 480 ,(seconds->string #$date language))
480 ,(string-append 481
481 #$manual 482 (div
482 (if (string=? language 483 (ul
483 "en") 484 (li (a (@ (href "html_node"))
484 "" 485 "HTML, with one page per node"))
485 (string-append "." 486 (li (a (@ (href
486 language)) 487 ,(string-append
487 ".html"))) 488 #$manual
488 "HTML, entirely on one page")) 489 (if (string=? language
489 ,@(if (member language '("ru" "zh_CN")) 490 "en")
490 '() 491 ""
491 `((li (a (@ (href ,(string-append 492 (string-append "."
492 #$manual 493 language))
493 (if (string=? language "en") 494 ".html")))
494 "" 495 "HTML, entirely on one page"))
495 (string-append "." 496 ,@(if (member language '("ru" "zh_CN"))
496 language)) 497 '()
497 ".pdf")))) 498 `((li (a (@ (href ,(string-append
498 "PDF"))))))))) 499 #$manual
499 500 (if (string=? language "en")
500 (define (write-html file sxml) 501 ""
501 (call-with-output-file file 502 (string-append "."
502 (lambda (port) 503 language))
503 (display "<!DOCTYPE html>\n" port) 504 ".pdf"))))
504 (sxml->xml sxml port)))) 505 "PDF")))))))))
505 506
506 (setenv "GUIX_LOCPATH" 507 (define %iso639-languages
507 #+(file-append glibc-utf8-locales "/lib/locale")) 508 (vector->list
508 (setenv "LC_ALL" "en_US.utf8") 509 (assoc-ref (call-with-input-file
509 (setlocale LC_ALL "en_US.utf8") 510 #+(file-append iso-codes
510 511 "/share/iso-codes/json/iso_639-3.json")
511 (bindtextdomain "guix-manual" 512 json->scm)
512 #+(guix-manual-text-domain source languages)) 513 "639-3")))
513 514
514 (for-each (lambda (language) 515 (define (language-code->name code)
515 (define directory 516 "Return the full name of a language from its ISO-639-3 code."
516 (string-append #$output "/" 517 (let ((code (match (string-index code #\_)
517 (normalize language))) 518 (#f code)
518 519 (index (string-take code index)))))
519 (mkdir-p directory) 520 (any (lambda (language)
520 (write-html (string-append directory "/index.html") 521 (and (string=? (or (assoc-ref language "alpha_2")
521 (language-index language))) 522 (assoc-ref language "alpha_3"))
522 '#$languages)))) 523 code)
524 (assoc-ref language "name")))
525 %iso639-languages)))
526
527 (define (top-level-index languages)
528 (define title
529 "GNU Guix Reference Manual")
530 (sxml-index
531 "en" title
532 `(main
533 (article
534 (@ (class "page centered-block limit-width"))
535 (h2 ,title)
536 (div
537 "The GNU Guix Reference Manual is available in the following
538languages:\n"
539 (ul
540 ,@(map (lambda (language)
541 `(li (a (@ (href ,(normalize language)))
542 ,(translate
543 (language-code->name language)
544 language
545 #:domain "iso_639-3"))))
546 languages)))))))
547
548 (define (write-html file sxml)
549 (call-with-output-file file
550 (lambda (port)
551 (display "<!DOCTYPE html>\n" port)
552 (sxml->xml sxml port))))
553
554 (setenv "GUIX_LOCPATH"
555 #+(file-append glibc-utf8-locales "/lib/locale"))
556 (setenv "LC_ALL" "en_US.utf8")
557 (setlocale LC_ALL "en_US.utf8")
558
559 (for-each (lambda (language)
560 (define directory
561 (string-append #$output "/"
562 (normalize language)))
563
564 (mkdir-p directory)
565 (write-html (string-append directory "/index.html")
566 (language-index language)))
567 '#$languages)
568
569 (write-html (string-append #$output "/index.html")
570 (top-level-index '#$languages))))))
523 571
524 (computed-file "html-indexes" build)) 572 (computed-file "html-indexes" build))
525 573