summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-07-05 23:50:26 +0200
committerLudovic Courtès <ludo@gnu.org>2025-07-09 14:19:04 +0200
commita40cc32ae876625c4f7c399bc034be95307f1ca0 (patch)
tree7c071698e3a40e9d5851006cb3060bd20dc62003
parent1691a4458cf3f816c9f78c8eb69f1de2b3bb16ab (diff)
doc: Add links to versions and variants as a drop-down menu.
* doc/build.scm (%latest-guix-version): New variable. (stylized-html): Add #:latest-version. [build](menu-item-separator): New variable. (version-menu-items, input-file-language): New procedures. (stylized-html, process-html): Add ‘language’ parameter. Update callers. Change-Id: If7cea2410802eec5af1d3c0407d5569250eb15ef
-rw-r--r--doc/build.scm75
1 files changed, 70 insertions, 5 deletions
diff --git a/doc/build.scm b/doc/build.scm
index 2bc73f915e0..1fa52707711 100644
--- a/doc/build.scm
+++ b/doc/build.scm
@@ -187,6 +187,10 @@ a list of extra files, such as '(\"contributing\")."
187 %cookbook-languages 187 %cookbook-languages
188 %manual-languages)) 188 %manual-languages))
189 189
190(define %latest-guix-version
191 ;; Latest released version.
192 "1.4.0")
193
190(define (texinfo-manual-images source) 194(define (texinfo-manual-images source)
191 "Return a directory containing all the images used by the user manual, taken 195 "Return a directory containing all the images used by the user manual, taken
192from SOURCE, the root of the source tree." 196from SOURCE, the root of the source tree."
@@ -736,6 +740,7 @@ its <pre class=\"lisp\"> blocks (as produced by 'makeinfo --html')."
736 740
737(define* (stylized-html source input 741(define* (stylized-html source input
738 #:key 742 #:key
743 (latest-version %latest-guix-version)
739 (languages %languages) 744 (languages %languages)
740 (manual %manual) 745 (manual %manual)
741 (manual-css-url %manual-css-url)) 746 (manual-css-url %manual-css-url))
@@ -784,6 +789,14 @@ in SOURCE."
784 (href ,url)) 789 (href ,url))
785 ,label))) 790 ,label)))
786 791
792 (define menu-item-separator
793 ;; Thin horizontal line to separate drop-down menu items.
794 `(img (@ (class "hline")
795 (src ,(in-vicinity
796 #$%web-site-url
797 "themes/initial/img/h-separator.png"))
798 (alt ""))))
799
787 (define* (navigation-bar menus #:key split-node?) 800 (define* (navigation-bar menus #:key split-node?)
788 ;; Return the navigation bar showing all of MENUS. 801 ;; Return the navigation bar showing all of MENUS.
789 `(header (@ (class "navbar")) 802 `(header (@ (class "navbar"))
@@ -830,7 +843,42 @@ in SOURCE."
830 "https://translate.fedoraproject.org/projects/guix/documentation-cookbook/" 843 "https://translate.fedoraproject.org/projects/guix/documentation-cookbook/"
831 "https://translate.fedoraproject.org/projects/guix/documentation-manual/"))))) 844 "https://translate.fedoraproject.org/projects/guix/documentation-manual/")))))
832 845
833 (define (stylized-html sxml file) 846 (define (version-menu-items language split-node?)
847 ;; Return the menu items to select the version of the manual of
848 ;; the type of medium (PDF, split-node, etc.).
849 (define language-extension
850 (if (string=? language "en")
851 ""
852 (string-append "." language)))
853
854 (define pdf-link
855 (string-append (if split-node? "../" "")
856 #$manual language-extension ".pdf"))
857
858 (define version-links
859 (list (menu-item #$latest-version
860 (string-append
861 "/manual/" language
862 (if split-node? "/html_node" "")))
863 (menu-item "development"
864 (string-append
865 "/manual/devel/" language
866 (if split-node? "/html_node" "")))
867 menu-item-separator))
868
869 (append (if (string=? #$manual "guix")
870 version-links
871 '())
872 (list (if split-node?
873 (menu-item "single page"
874 (string-append "../" #$manual
875 language-extension
876 ".html"))
877 (menu-item "multiple pages"
878 "html_node"))
879 (menu-item "PDF" pdf-link))))
880
881 (define (stylized-html sxml file language)
834 ;; Return SXML, which was read from FILE, with additional 882 ;; Return SXML, which was read from FILE, with additional
835 ;; styling. 883 ;; styling.
836 (define split-node? 884 (define split-node?
@@ -853,9 +901,16 @@ in SOURCE."
853 ;; TODO: Add "Contribute" menu, to report 901 ;; TODO: Add "Contribute" menu, to report
854 ;; errors, etc. 902 ;; errors, etc.
855 (list (menu-dropdown 903 (list (menu-dropdown
904 #:label "Version"
905 #:items
906 (version-menu-items language
907 split-node?))
908 (menu-dropdown
856 #:label 909 #:label
857 `(img (@ (alt "Language") 910 `(img (@ (alt "Language")
858 (src "/static/base/img/language-picker.svg"))) 911 (src #$(string-append
912 %web-site-url
913 "/themes/initial/img/language-picker.svg"))))
859 #:items 914 #:items
860 (language-menu-items file))) 915 (language-menu-items file)))
861 #:split-node? split-node?) 916 #:split-node? split-node?)
@@ -867,13 +922,13 @@ in SOURCE."
867 ((? string? str) 922 ((? string? str)
868 str)))) 923 str))))
869 924
870 (define (process-html file) 925 (define (process-html file language)
871 ;; Parse FILE and add links to translations. Install the result 926 ;; Parse FILE and add links to translations. Install the result
872 ;; to #$output. 927 ;; to #$output.
873 (format (current-error-port) "processing ~a...~%" file) 928 (format (current-error-port) "processing ~a...~%" file)
874 (let* ((shtml (parameterize ((%strict-tokenizer? #t)) 929 (let* ((shtml (parameterize ((%strict-tokenizer? #t))
875 (call-with-input-file file html->shtml))) 930 (call-with-input-file file html->shtml)))
876 (processed (stylized-html shtml file)) 931 (processed (stylized-html shtml file language))
877 (base (string-drop file (string-length #$input))) 932 (base (string-drop file (string-length #$input)))
878 (target (string-append #$output base))) 933 (target (string-append #$output base)))
879 (mkdir-p (dirname target)) 934 (mkdir-p (dirname target))
@@ -881,6 +936,15 @@ in SOURCE."
881 (lambda (port) 936 (lambda (port)
882 (write-shtml-as-html processed port))))) 937 (write-shtml-as-html processed port)))))
883 938
939 (define (input-file-language file)
940 ;; Return the language code of FILE, an input file, as a string
941 ;; like "sv" or "zh-cn".
942 (match (string-tokenize (string-drop file
943 (string-length #$input))
944 (char-set-complement
945 (char-set #\/)))
946 ((language _ ...) language)))
947
884 ;; Install a UTF-8 locale so we can process UTF-8 files. 948 ;; Install a UTF-8 locale so we can process UTF-8 files.
885 (setenv "GUIX_LOCPATH" 949 (setenv "GUIX_LOCPATH"
886 #+(file-append glibc-utf8-locales "/lib/locale")) 950 #+(file-append glibc-utf8-locales "/lib/locale"))
@@ -891,7 +955,8 @@ in SOURCE."
891 (n-par-for-each (parallel-job-count) 955 (n-par-for-each (parallel-job-count)
892 (lambda (file) 956 (lambda (file)
893 (if (string-suffix? ".html" file) 957 (if (string-suffix? ".html" file)
894 (process-html file) 958 (let ((language (input-file-language file)))
959 (process-html file language))
895 ;; Copy FILE as is to #$output. 960 ;; Copy FILE as is to #$output.
896 (let* ((base (string-drop file (string-length #$input))) 961 (let* ((base (string-drop file (string-length #$input)))
897 (target (string-append #$output base))) 962 (target (string-append #$output base)))