From ceb898747ad287e83fe18f81a955c186b7abac8e Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 4 Feb 2025 06:53:26 -0600 Subject: Fixing templates + aliases --- src/Hakyll/Alias.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Prolog.hs | 3 +++ templates/default.html | 21 ++++++++++++++------- www/templates/paper.html | 34 ++++++++++++++++++++++++++++++++++ www/templates/prints.html | 15 +++++++++++++++ 5 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 src/Hakyll/Alias.hs create mode 100644 www/templates/paper.html create mode 100644 www/templates/prints.html diff --git a/src/Hakyll/Alias.hs b/src/Hakyll/Alias.hs new file mode 100644 index 0000000..b127a05 --- /dev/null +++ b/src/Hakyll/Alias.hs @@ -0,0 +1,42 @@ +module Hakyll.Alias where + +import Prolog +import Data.HashSet qualified as HS + + +newtype Aliased a x = Aliased { unAliased :: Either a x } + deriving newtype (Binary, Eq, Foldable, Functor, Generic, Generic1, Hashable, Ord, Show, Traversable) + +class (Eq a, Hashable a) => ToAliases x a where + toAliases :: x -> HashSet a + +instance Hashable a => ToAliases a a where + toAliases = HM.singleton + +instance (Eq a, Hashable a) => ToAliases (HashSet a) a where + toAliases = id + +instance ToAliases x a => ToAliases [x] a where + toAliases = foldMap toAliases + + +class FromAlias a x where + fromAlias :: MonadThrow m => a -> m x + +instance FromAlias a a where + fromAlias = pure + +instance (FromAlias a x, FromAlias b x) => FromAlias (Either a b) x where + fromAlias = either fromAlias fromAlias + +instance FromAlias a x => FromAlias (Aliased a x) x where + fromAlias = fromAlias . unAliased + +newtype NoAlias a =NoAlias a + deriving (Eq, Show) + +instance Show a => Exception (NoAlias a) where + displayException (NoAlias a) = show a <> " is not an alias" + +missingAlias :: MonadThrow m => a -> m b +missingAlias = throwM . NoAlias diff --git a/src/Prolog.hs b/src/Prolog.hs index a6ac1b5..bb464f5 100644 --- a/src/Prolog.hs +++ b/src/Prolog.hs @@ -216,3 +216,6 @@ instance ToMarkup URI where instance ToValue URI where toValue = toValue . show preEscapedToValue = preEscapedToValue . show + +instance MonadThrow Compiler where + throwM = throwError . pure . displayException diff --git a/templates/default.html b/templates/default.html index 124a2f2..4aeffd6 100644 --- a/templates/default.html +++ b/templates/default.html @@ -2,11 +2,7 @@ $title$ - $if(author)$ - - $else$ - - $endif$ + @@ -17,7 +13,10 @@ $endif$ $if(math)$ - $partial("templates/math.html")$ + + + + $endif$ @@ -34,7 +33,15 @@
- $partial("templates/nav.html")$ +
diff --git a/www/templates/paper.html b/www/templates/paper.html new file mode 100644 index 0000000..0a19137 --- /dev/null +++ b/www/templates/paper.html @@ -0,0 +1,34 @@ +
+
+ $title$ +
+
+
    + $for(authors)$ +
  • $alias(author)$
  • + $endfor$ +
+
+ $if(abstract)$ +
+ +
+ $endif$ +
+
    + $if(submitted)$ +
  • Submitted
  • + $endif$ + $if(accepted)$ +
  • $journal$ (Accepted)
  • + $endif$ + $if(published)$ +
  • $journal$
  • +
  • $pubdate$
  • + $endif$ + $if(abstract)$$endif$ +
+
+
diff --git a/www/templates/prints.html b/www/templates/prints.html new file mode 100644 index 0000000..4fae26d --- /dev/null +++ b/www/templates/prints.html @@ -0,0 +1,15 @@ +
+
    + $if(doi)$ +
  • doi
  • + $endif$ + + $if(arxiv)$ +
  • arXiv
  • + $endif$ + + $if(pdf)$ +
  • pdf
  • + $endif$ +
+
-- cgit v1.2.3