From af64776403c52b48431e9ae6cc1858fb4053630c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 20 Mar 2014 17:26:43 -0600 Subject: [PATCH] plt-web: add `#:generate?` argument to `site` --- pkgs/plt-web-pkgs/plt-web-doc/plt-web.scrbl | 10 ++++++++-- pkgs/plt-web-pkgs/plt-web-lib/indexes.rkt | 4 +++- pkgs/plt-web-pkgs/plt-web-lib/layout.rkt | 6 ++++-- pkgs/plt-web-pkgs/plt-web-lib/resources.rkt | 19 +++++++++++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pkgs/plt-web-pkgs/plt-web-doc/plt-web.scrbl b/pkgs/plt-web-pkgs/plt-web-doc/plt-web.scrbl index fa2ad28738..12d1ed2310 100644 --- a/pkgs/plt-web-pkgs/plt-web-doc/plt-web.scrbl +++ b/pkgs/plt-web-pkgs/plt-web-doc/plt-web.scrbl @@ -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 diff --git a/pkgs/plt-web-pkgs/plt-web-lib/indexes.rkt b/pkgs/plt-web-pkgs/plt-web-lib/indexes.rkt index 657fac8fb3..66862ef270 100644 --- a/pkgs/plt-web-pkgs/plt-web-lib/indexes.rkt +++ b/pkgs/plt-web-pkgs/plt-web-lib/indexes.rkt @@ -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)]) diff --git a/pkgs/plt-web-pkgs/plt-web-lib/layout.rkt b/pkgs/plt-web-pkgs/plt-web-lib/layout.rkt index bb77f1020f..89c833c7f2 100644 --- a/pkgs/plt-web-pkgs/plt-web-lib/layout.rkt +++ b/pkgs/plt-web-pkgs/plt-web-lib/layout.rkt @@ -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 diff --git a/pkgs/plt-web-pkgs/plt-web-lib/resources.rkt b/pkgs/plt-web-pkgs/plt-web-lib/resources.rkt index 844696916d..1ad3cf9f73 100644 --- a/pkgs/plt-web-pkgs/plt-web-lib/resources.rkt +++ b/pkgs/plt-web-pkgs/plt-web-lib/resources.rkt @@ -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)