Fix extension handling a bit more
Previously, it was spliting versions up for the package pages. To stop this, now it just matches the extensions it knows about (currently .html and .json).
This commit is contained in:
parent
b15c8f706e
commit
bd8b9f951c
1 changed files with 30 additions and 24 deletions
|
|
@ -46,37 +46,43 @@
|
||||||
'(("json" . application/json)
|
'(("json" . application/json)
|
||||||
("html" . text/html)))
|
("html" . text/html)))
|
||||||
|
|
||||||
|
(define (ends-with-recognised-extension? path)
|
||||||
|
(any (lambda (extension)
|
||||||
|
(string-suffix? (string-append "." extension)
|
||||||
|
path))
|
||||||
|
(map car extensions-to-mime-types)))
|
||||||
|
|
||||||
(match (split-and-decode-uri-path (uri-path (request-uri request)))
|
(match (split-and-decode-uri-path (uri-path (request-uri request)))
|
||||||
(()
|
(()
|
||||||
(values '()
|
(values '()
|
||||||
(or (request-accept request)
|
(or (request-accept request)
|
||||||
(list 'text/html))))
|
(list 'text/html))))
|
||||||
((single-component)
|
((single-component)
|
||||||
|
(if (ends-with-recognised-extension? single-component)
|
||||||
(match (string-split single-component #\.)
|
(match (string-split single-component #\.)
|
||||||
((part)
|
|
||||||
(values (list single-component)
|
|
||||||
(or (request-accept request)
|
|
||||||
(list 'text/html))))
|
|
||||||
((first-parts ... extension)
|
((first-parts ... extension)
|
||||||
(values (list (string-join first-parts "."))
|
(values (list (string-join first-parts "."))
|
||||||
(or (cons
|
(or (cons
|
||||||
(or (assoc-ref extensions-to-mime-types extension)
|
(assoc-ref extensions-to-mime-types extension)
|
||||||
'text/html)
|
|
||||||
(request-accept request)))))))
|
|
||||||
((first-components ... last-component)
|
|
||||||
(match (string-split last-component #\.)
|
|
||||||
((part)
|
|
||||||
(values (append first-components
|
|
||||||
(list part))
|
|
||||||
(or (request-accept request)
|
(or (request-accept request)
|
||||||
(list 'text/html))))
|
(list 'text/html)))))))
|
||||||
|
(values (list single-component)
|
||||||
|
(or (request-accept request)
|
||||||
|
(list 'text/html)))))
|
||||||
|
((first-components ... last-component)
|
||||||
|
(if (ends-with-recognised-extension? last-component)
|
||||||
|
(match (string-split last-component #\.)
|
||||||
((first-parts ... extension)
|
((first-parts ... extension)
|
||||||
(values (append first-components
|
(values (append first-components
|
||||||
(list (string-join first-parts ".")))
|
(list (string-join first-parts ".")))
|
||||||
(or (cons
|
(or (cons
|
||||||
(or (assoc-ref extensions-to-mime-types extension)
|
(assoc-ref extensions-to-mime-types extension)
|
||||||
'text/html)
|
(or (request-accept request)
|
||||||
(request-accept request)))))))))
|
(list 'text/html)))))))
|
||||||
|
(values (append first-components
|
||||||
|
(list last-component))
|
||||||
|
(or (request-accept request)
|
||||||
|
(list 'text/html)))))))
|
||||||
|
|
||||||
(define (file-extension file-name)
|
(define (file-extension file-name)
|
||||||
(last (string-split file-name #\.)))
|
(last (string-split file-name #\.)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue