Add redirections to language subdirs

Julien LepillerTue Oct 06 14:23:50+0200 2020

194780c

Add redirections to language subdirs

systems/xana.scm

2121
(use-modules (gnu services mcron))
2222
(use-modules (gnu services networking))
2323
(use-modules (gnu services web))
24-
(use-modules (config certbot) (config cuirass) (config network) (config os))
24+
(use-modules (config certbot) (config cuirass) (config network) (config os) (config web))
2525
(use-modules (guix gexp))
2626
(use-package-modules base compression gettext guile guile-xyz linux version-control
2727
                     wget)
2828
29+
(define lepiller-policy
30+
  (append
31+
    web-base-policy
32+
    '("# accept-language: en,en-US;q=0.8,ja;q=0.6"
33+
      "set $first_language '';"
34+
      "if ($http_accept_language ~* '(en|eo|fr)') {"
35+
      "  set $first_language $1;"
36+
      "}"
37+
      "if ($first_language = '') {"
38+
      "  set $first_language 'en';"
39+
      "}"
40+
      "set $my_uri $first_language/$uri;"
41+
      "location ~ ^/[^/]*$ {"
42+
      "  return 301 /$first_language/$uri;"
43+
      "}"
44+
      )
45+
    (web-html-policy
46+
      '("    try_files $my_uri $uri $uri/ =404;"))
47+
    '("error_page 404 /404.html;")))
48+
2949
(define (makefile-job directory target packages env)
3050
  #~(lambda ()
3151
      (define path

115135
                    "/etc/letsencrypt/live/offlate.lepiller.eu/privkey.pem")
116136
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
117137
                  (server-name '("offlate.lepiller.eu"))
118-
                  (root "/srv/http/offlate/public"))))
138+
                  (root "/srv/http/offlate/public")
139+
                  (index '("index.html"))
140+
                  (try-files '("$uri" "$uri/" "=404"))
141+
                  (raw-content lepiller-policy))))
119142
        (simple-service 'i18n-http-server nginx-service-type
120143
          (list (nginx-server-configuration
121144
                  (ssl-certificate