From 27215982e6f7744634eefa7ebb1a101b66903ff2 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 21 May 2020 19:17:56 -0700 Subject: [PATCH] help.html: copy image resources to output directory. This helps avoid needing so many different static responders in webapps.help, and makes the documentation more self-contained. --- basis/help/html/html.factor | 26 +++++++++++--------------- extra/webapps/help/help.factor | 4 +--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/basis/help/html/html.factor b/basis/help/html/html.factor index 426847aea1..3a6b65b152 100644 --- a/basis/help/html/html.factor +++ b/basis/help/html/html.factor @@ -143,25 +143,20 @@ M: pathname url-of ] [ drop ] if ] each classes sort-values css-classes body ; -: img@2x ( body -- body' ) +: retina-image ( path -- path' ) + "@2x" over subseq? [ "." split1-last "@2x." glue ] unless ; + +: ?copy-file ( from to -- ) + dup exists? [ 2drop ] [ copy-file ] if ; + +: cache-images ( body -- body' ) dup [ dup xml-chunk? [ seq>> [ T{ name { main "img" } } over tag-named? [ dup "src" attr - - ! use @2x retina images - "@2x" over subseq? [ - "." split1-last "@2x." glue - ] unless - - ! src mapping for webapps.help - "vocab:definitions/icons/" ?head - [ "/icons/" prepend ] when - - "vocab:ui/tools/error-list/icons/" ?head - [ "/icons2/" prepend ] when - + retina-image dup file-name + [ ?copy-file ] keep "src" set-attr ] [ drop ] if ] deep-each @@ -171,7 +166,8 @@ M: pathname url-of : help>html ( topic -- xml ) [ article-title " - Factor Documentation" append ] [ - [ print-topic ] with-html-writer css-styles-to-classes img@2x + [ print-topic ] with-html-writer + css-styles-to-classes cache-images [ help-stylesheet help-meta prepend help-navbar ] dip [XML
<->
<->
XML] ] bi simple-page ; diff --git a/extra/webapps/help/help.factor b/extra/webapps/help/help.factor index e09dee4c87..f0af5fb4ba 100644 --- a/extra/webapps/help/help.factor +++ b/extra/webapps/help/help.factor @@ -39,9 +39,7 @@ TUPLE: help-webapp < dispatcher ; help-webapp new-dispatcher "" add-responder help-dir "search" add-responder - help-dir "content" add-responder - "resource:basis/definitions/icons/" "icons" add-responder - "resource:basis/ui/tools/error-list/icons/" "icons2" add-responder ; + help-dir "content" add-responder ; : run-help-webapp ( -- ) "docs" cache-file