Skip to content

Commit 55984f8

Browse files
committed
try again to get per-year redirects right
1 parent 83bb303 commit 55984f8

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

annual-utils.rkt

+17-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,27 @@
3636

3737

3838

39-
(define (copy-annual-site! site starting-dir year #:current [current? #f])
39+
(define (copy-annual-site! site starting-dir year
40+
#:current [current? #f]
41+
#:copy-current-index? [copy-current-index? #t])
4042
(for* ([p (in-directory starting-dir)]
4143
[fn (in-value (filename p))]
4244
[ext (in-list '(#".html" #".css" #".svg" #".png" #".jpg"))]
4345
#:unless (or (not (path-has-extension? fn ext))
4446
(excluded-path? fn)
45-
(and current? (equal? fn (string->path "index.html")))))
46-
(copyfile #:site site (build-path starting-dir fn)
47-
(string-join (map ~a (append
48-
(if current? null (list year))
49-
(list fn))) "/")))
47+
(and current?
48+
(not copy-current-index?)
49+
(equal? fn (string->path "index.html")))))
50+
(define (copy current?)
51+
(copyfile #:site site (build-path starting-dir fn)
52+
(string-join (map ~a (append
53+
(if current? null (list year))
54+
(list fn))) "/")))
55+
(copy current?)
56+
(when (and current?
57+
copy-current-index?
58+
(equal? fn (string->path "index.html")))
59+
(copy #f)))
5060

5161
(define (copy-subdir-if-extant subdir-name)
5262
(define subdir (build-path starting-dir subdir-name))
@@ -59,4 +69,4 @@
5969
(list subdir-name (filename p)))) "/")))))
6070

6171
(copy-subdir-if-extant "fonts")
62-
(copy-subdir-if-extant "slides"))
72+
(copy-subdir-if-extant "slides"))

rcon/all.rkt

+16-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
(prefix-in 2013: "2013/all.rkt")
1313
(prefix-in 2014: "2014/all.rkt"))
1414

15-
(provide index)
16-
1715
(register-identity con-site)
1816

1917
(define-syntax-rule (copy-con-site! ARG ...)
@@ -64,10 +62,20 @@
6462
(require (prefix-in 2023: "2023/index.rkt"))
6563
(define-runtime-path 2023-dir "2023")
6664
(2023:make 2023-dir)
67-
(copy-con-site! 2023-dir 2023) ; note: don't set `#:current #t`, because we copy below to have it in both places
65+
(copy-con-site! 2023-dir 2023 #:current #t) ; change to `#:current` needs change in "sync.rkt"
66+
67+
;; A `#:current #t` above causes that year's content to be copied to
68+
;; the root directory instead of the year's subdiredtory, except that
69+
;; "index.html" is by itself created in the subdirectory. A
70+
;; routing-rule redirect in "../sync.rkt" will send all references
71+
;; into the subdirectory. A "index.html" file is written in the
72+
;; subdirectory, anyway, because that is needed for a URL ending in
73+
;; the directory and NO slash to be redirected to "index.html", which
74+
;; is then redirected to the root directory.
6875

6976
;; This is a bad idea, because it creates a 301 (permanent)
70-
;; redirect:
77+
;; redirect; instead, there's a routing rule added in "../sync.rkt"
78+
;; to create a 302 (temporary) redirect:
7179
#|
7280
;; On web server, redirect 2023/index.html to root index.html
7381
;; (these refer to remote paths)
@@ -76,12 +84,15 @@
7684
"../index.html"
7785
"2023/index.html"))
7886
|#
79-
;; Instead, there's a routing rule added in "sync.rkt"
8087

88+
;; Don't do this, either, because it doesn't work right with
89+
;; extra files referenced relative to "index.html"
90+
#|
8191
(define-runtime-path current-con-index "2023/index.html")
8292
(define index
8393
(page* #:site con-site
8494
#:link-title "RacketCon" #:title "RacketCon"
8595
#:extra-headers style-header
8696
#:id 'con
8797
@copyfile[#:site con-site current-con-index]))
98+
|#

school/all.rkt

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
;; 2019
2323
(define-runtime-path 2019-dir "2019")
2424
(pollen-rebuild! 2019-dir)
25-
(copy-school-site! 2019-dir 2019 #:current #f)
25+
(copy-school-site! 2019-dir 2019)
2626

2727
;; 2020
2828
(define-runtime-path 2020-dir "2020")
2929
(scribble-page (build-path 2020-dir "index.scrbl") 2020-dir)
30-
(copy-school-site! 2020-dir 2020 #:current #t)
30+
(copy-school-site! 2020-dir 2020 #:current #t) ; change to `#:current` needs change in "sync.rkt"
3131

32+
;; The rest of this is the wrong idea. See "../rcon/all.rkt".
33+
;; The current year's directory is redirected through a routing
34+
;; rule in "../sync.rkt".
35+
36+
#|
3237
;; On web server, redirect 2020/index.html to root index.html
3338
;; (these refer to remote paths)
3439
(void
@@ -43,3 +48,4 @@
4348
#:link-title "Racket School" #:title "Racket School"
4449
#:id 'school
4550
@copyfile[#:site school-site current-school-index]))
51+
|#

sync.rkt

+10-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@
130130
(unless dry-run?
131131
;; Redirect current year's "index.html" to the root "index.html":
132132
(add-routing-rules "con.racket-lang.org"
133+
#:preserve-existing? #f ; so redirect for old year is dropped
133134
(list
134-
(redirect-prefix-routing-rule #:old-prefix "2023/index.html"
135-
#:new-prefix "index.html"
135+
(redirect-prefix-routing-rule #:old-prefix "2023/"
136+
#:new-prefix ""
137+
#:redirect-code "302"))
138+
#:log-info displayln)
139+
(add-routing-rules "school.racket-lang.org"
140+
#:preserve-existing? #f ; so redirect for old year is dropped
141+
(list
142+
(redirect-prefix-routing-rule #:old-prefix "2020/"
143+
#:new-prefix ""
136144
#:redirect-code "302"))
137145
#:log-info displayln))
138146

0 commit comments

Comments
 (0)