diff --git a/make-pages/BuilderQQ.hs b/make-pages/BuilderQQ.hs index c7cee73..95bba6b 100644 --- a/make-pages/BuilderQQ.hs +++ b/make-pages/BuilderQQ.hs @@ -18,9 +18,15 @@ import Data.List.NonEmpty (NonEmpty, toList) data Chunk = Lit String | Var String + +-- | +-- * use @$var@ to insert a variable (instance of 'CanBuild') +-- * use @$&@ to insert nothing like @\&@ in a string (e.g. to add whitespace +-- at the start or end, or to have a variable followed by a letter +-- * use @$$@ for a literal @$@ parseB :: String -> ExpQ parseB = toExpQ . reverse . go "" [] . trim where - trim = dropWhileEnd isSpace . dropWhile (== '\n') + trim = dropWhileEnd isSpace . dropWhile isSpace go acc cs [] = addLit acc cs go acc cs ('$':'&':rest) = go acc cs rest -- $&: expands to nothing go acc cs ('$':'$':rest) = go ('$' : acc) cs rest -- $$: expands to one $ diff --git a/make-pages/GalleryPage.hs b/make-pages/GalleryPage.hs index ae2a1bd..3e9c7fb 100644 --- a/make-pages/GalleryPage.hs +++ b/make-pages/GalleryPage.hs @@ -129,8 +129,8 @@ makeFilter prefix initial tag count = [b| where id' = [b|$prefix$&_$tag'|] tag' = escId tag - checked = if HashSet.member tag initial then [b| checked|] else "" - hidden = if count <= 1 then [b| hidden|] else "" + checked = if HashSet.member tag initial then [b|$& checked|] else "" + hidden = if count <= 1 then [b|$& hidden|] else "" makeYearItems :: Bool -- ^ nsfw -> Int -- ^ year @@ -159,12 +159,12 @@ makeItem nsfw file info@(Info {bg}) = [b| title = fromMaybe info.title $ info.galleryTitle dir = takeDirectory file thumbnail = getThumb dir info - nsfw' = if nsfw && anyNsfw info then [b| nsfw|] else "" + nsfw' = if nsfw && anyNsfw info then [b|$& nsfw|] else "" tags' = fold $ intersperse ";" $ map fromText $ tagsFor nsfw info date = latestDateFor nsfw info date' = formatTooltip date year' = date.year updated' = if hasUpdatesFor nsfw info then [b|true|] else [b|false|] - bgStyle = case bg of Other col -> [b| style="background: $col"|]; _ -> "" + bgStyle = case bg of Other col -> [b|$& style="background: $col"|]; _ -> "" tooltip = [b|$title ($upd$date')|] where upd = if hasUpdatesFor nsfw info then "updated " else "" :: Builder diff --git a/make-pages/IndexPage.hs b/make-pages/IndexPage.hs index 3efce99..1b1600d 100644 --- a/make-pages/IndexPage.hs +++ b/make-pages/IndexPage.hs @@ -74,13 +74,13 @@ makeItem :: GalleryInfo -> Builder makeItem (GalleryInfo {title, desc, prefix, filters}) = [b|