plt-web: add #:generate? argument to site

This commit is contained in:
Matthew Flatt 2014-03-20 17:26:43 -06:00
parent 43af294068
commit af64776403
4 changed files with 28 additions and 11 deletions

View File

@ -36,6 +36,7 @@ relative directory is mapped to a destination URL via
@defproc[(site [dir path-string?]
[#:url url (or/c string? #f) #f]
[#:always-abs-url? always-abs-url? any/c #t]
[#:generate? generate? any/c #t]
[#:share-from share-from (or/c site? #f) #f]
[#:page-style? page-style? any/c #t]
[#:page-headers page-headers outputable/c null]
@ -57,6 +58,9 @@ is registered with a @racket['abs] flag, so that (in @tech{deployment
mode}) references within a site are relative to the site root, as
opposed to relative to the referencing resource.
If @racket[generate?] is @racket[#f], then resources for the site
(such as icons or CSS files) are not generated.
If @racket[share-from] is a site, then resources generated for the
site (such as icons or CSS files) are used when as possible for the
new site.
@ -223,12 +227,14 @@ site root.}
@defproc[(index-site [site site?]) index-site?]
@defproc[(index-page [isite index-site?]
[path (or/c 'same relative-path?)]
[content (listof (cons/c path-string? (or/c exact-integer? 'dir)))])
[content (listof (cons/c path-string? (or/c exact-integer? 'dir)))]
[#:html-only? html-only? any/c #f])
outputable/c]
)]{
The @racket[index-page] function registers an individual
@filepath{index.html} file for the given index site, where an index
@filepath{index.html} file (or returns its content if
@racket[html-only?] is true) for the given index site, where an index
site is created once for a given site (to register support
resources, such as icons). The @filepath{index.html} file is
generated for the subdirectory indicated by @racket[path]. The index

View File

@ -15,12 +15,14 @@
(struct index-site (site file-icon folder-icon))
(define (index-page is dir content)
(define (index-page is dir content
#:html-only? [html-only? #f])
(page #:site (index-site-site is)
#:file (if (eq? dir 'same)
"index.html"
(path->string (build-path dir "index.html")))
#:title "Index"
#:html-only? html-only?
@columns[10 #:row? #t]{
@table{@(for/list ([p+k (in-list content)])
(define p (let ([p (car p+k)])

View File

@ -289,7 +289,8 @@
#:page-headers [headers null]
#:page-style? [page-style? #t]
#:meta? [meta? page-style?]
#:share-from [given-sharing-site #f])
#:share-from [given-sharing-site #f]
#:generate? [generate? #t])
(when url
(registered-url-roots (cons (list* dir
url
@ -305,7 +306,8 @@
(define the-site
(make-site dir (delay
(make-resources
(make-resource-files
(make-resource-files
generate?
(λ (id . content)
(page* #:id id
#:site the-site

View File

@ -19,17 +19,24 @@
;; they can be #t (the default) for the standard ones, or some text that gets
;; added to the standard contents -- which is the user-agent line and the
;; ErrorDocument respectively.
(define (make-resource-files page dir robots htaccess page-style? meta? sharing?)
(define (make-resource-files generate? page dir robots htaccess page-style? meta? sharing?)
;; the default target argument duplicate the behavior in "utils.rkt"
(define (copyfile file [target (basename file)])
(list target (copyfile-resource (build-path resources-dir file) (web-path dir target))))
(list target
(if generate?
(copyfile-resource (build-path resources-dir file) (web-path dir target))
(resource (web-path dir target) #f))))
(define (writefile file . contents)
(list file (resource (web-path dir file)
(file-writer output (list contents "\n")))))
(list file
(resource (web-path dir file)
(and generate?
(file-writer output (list contents "\n"))))))
(define (pagefile file . contents)
(list file
(apply page (string->symbol (regexp-replace #rx"[.]html$" file ""))
contents)))
(if generate?
(apply page (string->symbol (regexp-replace #rx"[.]html$" file ""))
contents)
(resource (web-path dir file) #f))))
`(,@(if (not sharing?)
(list (copyfile "logo-and-text.png" "logo-and-text.png"))
null)