summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pages/calendar-day.mustache17
-rw-r--r--pages/calendar.mustache17
-rw-r--r--pages/index.mustache10
-rw-r--r--pages/log.mustache17
-rw-r--r--pages/partials/footer.mustache4
-rw-r--r--pages/partials/header.mustache6
-rw-r--r--pages/partials/headmeta.mustache4
-rw-r--r--src/Pages.hs38
-rw-r--r--src/Pages/TH.hs2
9 files changed, 60 insertions, 55 deletions
diff --git a/pages/calendar-day.mustache b/pages/calendar-day.mustache
index f47a41b..5cf8078 100644
--- a/pages/calendar-day.mustache
+++ b/pages/calendar-day.mustache
@@ -1,21 +1,13 @@
<!doctype html>
<html lang="en">
<head>
- <meta charset="utf-8">
+ {{> headmeta}}
<title>{{channel}} {{date}} ({{network}}) - tirclogv</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="/style.css">
<script src="/log.js"></script>
- <link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<div id="gridwrapper" data-page="withheader">
- <header>
- <a href="/" class="hdritem hdritem-home">Home</a>
- {{network}}/{{channel}}:
- <a href="/log/{{&alias}}" class="hdritem hdritem-view">Logs</a>
- <a href="/cal/{{&alias}}" class="hdritem hdritem-view">Calendar</a>
- </header>
+ {{> header}}
<main>
<h1>Logs on {{date}} ({{network}}/{{channel}})</h1>
<div class="pagepicker">
@@ -40,10 +32,7 @@
</tbody></table>
<p>All times are in UTC on {{date}}.</p>
</main>
- <footer>
- <a href="https://git.tomsmeding.com/tirclogv">tirclogv</a> &mdash; An IRC log viewer by
- <a href="https://tomsmeding.com">Tom Smeding</a>.
- </footer>
+ {{> footer}}
</div>
</body>
</html>
diff --git a/pages/calendar.mustache b/pages/calendar.mustache
index c65849d..2ea5ca4 100644
--- a/pages/calendar.mustache
+++ b/pages/calendar.mustache
@@ -1,20 +1,12 @@
<!doctype html>
<html lang="en">
<head>
- <meta charset="utf-8">
+ {{> headmeta}}
<title>Calendar {{channel}} ({{network}}) - tirclogv</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="/style.css">
- <link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<div id="gridwrapper" data-page="withheader">
- <header>
- <a href="/" class="hdritem hdritem-home">Home</a>
- {{network}}/{{channel}}:
- <a href="/log/{{&alias}}" class="hdritem hdritem-view">Logs</a>
- <a href="/cal/{{&alias}}" class="hdritem hdritem-view">Calendar</a>
- </header>
+ {{> header}}
<main>
<h1>Calendar: {{network}}/{{channel}}</h1>
{{#years}}
@@ -51,10 +43,7 @@
</tbody></table>
{{/years}}
</main>
- <footer>
- <a href="https://git.tomsmeding.com/tirclogv">tirclogv</a> &mdash; An IRC log viewer by
- <a href="https://tomsmeding.com">Tom Smeding</a>.
- </footer>
+ {{> footer}}
</div>
</body>
</html>
diff --git a/pages/index.mustache b/pages/index.mustache
index 8811d7f..4e461c0 100644
--- a/pages/index.mustache
+++ b/pages/index.mustache
@@ -1,11 +1,8 @@
<!doctype html>
<html lang="en">
<head>
- <meta charset="utf-8">
+ {{> headmeta}}
<title>tirclogv</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="/style.css">
- <link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<div id="gridwrapper" data-page="index">
@@ -18,10 +15,7 @@
{{/channels}}
{{/networks}}
</main>
- <footer>
- <a href="https://git.tomsmeding.com/tirclogv">tirclogv</a> &mdash; An IRC log viewer by
- <a href="https://tomsmeding.com">Tom Smeding</a>.
- </footer>
+ {{> footer}}
</div>
</body>
</html>
diff --git a/pages/log.mustache b/pages/log.mustache
index 10a99cf..8e3d800 100644
--- a/pages/log.mustache
+++ b/pages/log.mustache
@@ -1,21 +1,13 @@
<!doctype html>
<html lang="en">
<head>
- <meta charset="utf-8">
+ {{> headmeta}}
<title>{{channel}} ({{network}}) - tirclogv</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="/style.css">
<script src="/log.js"></script>
- <link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<div id="gridwrapper" data-page="withheader">
- <header>
- <a href="/" class="hdritem hdritem-home">Home</a>
- {{network}}/{{channel}}:
- <a href="/log/{{&alias}}" class="hdritem hdritem-view">Logs</a>
- <a href="/cal/{{&alias}}" class="hdritem hdritem-view">Calendar</a>
- </header>
+ {{> header}}
<main>
<h1>Logs: {{network}}/{{channel}}</h1>
<div class="pagepicker">
@@ -92,10 +84,7 @@
</div>
<p>All times are in UTC.</p>
</main>
- <footer>
- <a href="https://git.tomsmeding.com/tirclogv">tirclogv</a> &mdash; An IRC log viewer by
- <a href="https://tomsmeding.com">Tom Smeding</a>.
- </footer>
+ {{> footer}}
</div>
</body>
</html>
diff --git a/pages/partials/footer.mustache b/pages/partials/footer.mustache
new file mode 100644
index 0000000..2f3a6a4
--- /dev/null
+++ b/pages/partials/footer.mustache
@@ -0,0 +1,4 @@
+ <footer>
+ <a href="https://git.tomsmeding.com/tirclogv">tirclogv</a> &mdash; An IRC log viewer by
+ <a href="https://tomsmeding.com">Tom Smeding</a>.
+ </footer>
diff --git a/pages/partials/header.mustache b/pages/partials/header.mustache
new file mode 100644
index 0000000..af71312
--- /dev/null
+++ b/pages/partials/header.mustache
@@ -0,0 +1,6 @@
+ <header>
+ <a href="/" class="hdritem hdritem-home">Home</a>
+ {{network}}/{{channel}}:
+ <a href="/log/{{&alias}}" class="hdritem hdritem-view">Logs</a>
+ <a href="/cal/{{&alias}}" class="hdritem hdritem-view">Calendar</a>
+ </header>
diff --git a/pages/partials/headmeta.mustache b/pages/partials/headmeta.mustache
new file mode 100644
index 0000000..425084a
--- /dev/null
+++ b/pages/partials/headmeta.mustache
@@ -0,0 +1,4 @@
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="/style.css">
+ <link rel="icon" type="image/png" href="/favicon.png">
diff --git a/src/Pages.hs b/src/Pages.hs
index 8bd7514..fa7660b 100644
--- a/src/Pages.hs
+++ b/src/Pages.hs
@@ -4,12 +4,15 @@
{-# LANGUAGE TemplateHaskell #-}
module Pages where
+import Control.Monad (forM)
import Control.Monad.IO.Class (liftIO)
+import Data.List (find)
import Data.Text (Text)
import Data.Text.IO qualified as T
import Language.Haskell.TH.Syntax (addDependentFile)
-import System.Directory (makeAbsolute)
+import System.Directory (makeAbsolute, listDirectory)
import Text.Mustache.Compile qualified as M
+import Text.Mustache.Types qualified as M
import Pages.TH
@@ -104,14 +107,41 @@ data EventData tm dttm = EventData
, message :: Text
}
-$(do let readTemplate name = do
+$(do let dropSuffix suf str =
+ let (actualSuf, rstr) = splitAt (length suf) (reverse str)
+ in if actualSuf == reverse suf then reverse rstr else str
+ let inlinePartials :: [M.Template] -> M.Template -> M.Template
+ inlinePartials ps (M.Template topname ast _) = M.Template topname (concatMap go ast) mempty
+ where
+ go :: M.Node Text -> [M.Node Text]
+ go n@M.TextBlock{} = [n]
+ go (M.Section named nodes) = [M.Section named (concatMap go nodes)]
+ go (M.InvertedSection named nodes) = [M.InvertedSection named (concatMap go nodes)]
+ go n@M.Variable{} = [n]
+ -- sorry for the lost indent
+ go (M.Partial _indent partialname) =
+ case find ((== partialname) . M.name) ps of
+ Just (M.Template _ ast' _) -> concatMap go ast'
+ Nothing -> error $ "Partial not found: " ++ partialname
+ partialFiles <- liftIO $ listDirectory "pages/partials"
+ partials <- forM partialFiles $ \fname -> do
+ path <- liftIO $ makeAbsolute ("pages/partials/" ++ fname)
+ tplSrc <- liftIO $ T.readFile path
+ addDependentFile path
+ let name = dropSuffix ".mustache" fname
+ case M.compileTemplate name tplSrc of
+ Right tpl -> return tpl
+ Left err -> fail $ "Reading " ++ path ++ ": " ++ show err
+ let makeDecs name dataname = do
path <- liftIO $ makeAbsolute ("pages/" ++ name ++ ".mustache")
tplSrc <- liftIO $ T.readFile path
addDependentFile path
- case M.compileTemplate name tplSrc of
+ tpl <- case M.compileTemplate name tplSrc of
Right tpl -> return tpl
Left err -> fail $ "Reading " ++ path ++ ": " ++ show err
- concat <$> mapM (\(name, ty) -> (`makeRender` ty) =<< readTemplate name)
+ let tpl' = inlinePartials partials tpl
+ makeRender tpl' dataname
+ concat <$> mapM (uncurry makeDecs)
[("log", ''LogData)
,("calendar-day", ''CalendarDayData)
,("index", ''IndexData)
diff --git a/src/Pages/TH.hs b/src/Pages/TH.hs
index 2967761..c16075b 100644
--- a/src/Pages/TH.hs
+++ b/src/Pages/TH.hs
@@ -194,7 +194,7 @@ renderNodes dats buf (node : nodes) = do
Just (VQInt, _) -> fail $ "Int value in inverted section scrutinee " ++ show named
Just (VQUnit, _) -> fail $ "() value in inverted section scrutinee " ++ show named
Nothing -> fail $ "Inverted section scrutinee not found: " ++ show named
- M.Partial _ _ -> fail "TODO partials"
+ M.Partial _ _ -> fail $ "Unresolved partial in template: " ++ show node
renderNodes dats (ExpensiveExp buf') nodes