Compare commits

...

2 commits

Author SHA1 Message Date
Yann Esposito (Yogsototh) 6c3f4f3031
updated and mostly feature equal 2020-06-25 16:28:35 +02:00
Yann Esposito (Yogsototh) f12936254a
better templates 2020-06-25 15:27:00 +02:00
4 changed files with 34 additions and 22 deletions

View file

@ -4,7 +4,7 @@
import Protolude import Protolude
import Development.Shake import Development.Shake
import Development.Shake.Command -- import Development.Shake.Command
import Development.Shake.FilePath import Development.Shake.FilePath
import Data.Time.Format.ISO8601 (iso8601Show) import Data.Time.Format.ISO8601 (iso8601Show)
@ -62,8 +62,9 @@ optimDir = "_optim"
data BlogPost = data BlogPost =
BlogPost { postTitle :: T.Text BlogPost { postTitle :: T.Text
, postDate :: T.Text , postDate :: T.Text
, postAuthors :: [T.Text] , postAuthor :: T.Text
, postUrl :: FilePath , postUrl :: FilePath
, postSrc :: FilePath
, postTags :: [T.Text] , postTags :: [T.Text]
, postDescr :: T.Text , postDescr :: T.Text
, postToc :: Bool , postToc :: Bool
@ -79,12 +80,14 @@ getBlogpostFromMetas
getBlogpostFromMetas path toc pandoc@(Pandoc meta _) = do getBlogpostFromMetas path toc pandoc@(Pandoc meta _) = do
eitherBlogpost <- liftIO $ Pandoc.runIO $ do eitherBlogpost <- liftIO $ Pandoc.runIO $ do
title <- fmap (T.dropEnd 1) $ inlineToText $ docTitle meta title <- fmap (T.dropEnd 1) $ inlineToText $ docTitle meta
date <- fmap (T.dropAround dateEnvelope) $ inlineToText $ docDate meta date <- fmap (T.takeWhile (/= ' ') . (T.dropAround dateEnvelope)) $ inlineToText $ docDate meta
authors <- mapM inlineToText $ docAuthors meta author <- case head $ docAuthors meta of
Just m -> inlineToText m
Nothing -> return ""
let tags = tagsToList $ lookupMeta "keywords" meta let tags = tagsToList $ lookupMeta "keywords" meta
description = descr $ lookupMeta "description" meta description = descr $ lookupMeta "description" meta
liftIO $ print (lookupMeta "keywords" meta) url = "/" </> dropDirectory1 path -<.> "org"
return $ BlogPost title date authors path tags description toc pandoc return $ BlogPost title date author url path tags description toc pandoc
case eitherBlogpost of case eitherBlogpost of
Left _ -> fail "BAD" Left _ -> fail "BAD"
Right bp -> return bp Right bp -> return bp
@ -155,7 +158,7 @@ buildArchive
buildArchive getPosts getTemplate out = do buildArchive getPosts getTemplate out = do
css <- genAllDeps ["//*.css"] css <- genAllDeps ["//*.css"]
posts <- fmap sortByPostDate $ getPosts () posts <- fmap sortByPostDate $ getPosts ()
need $ css <> map postUrl posts need $ css <> map postSrc posts
let let
title :: Text title :: Text
title = "#+title: Posts" title = "#+title: Posts"
@ -170,7 +173,7 @@ buildArchive getPosts getTemplate out = do
let htmlContent = let htmlContent =
renderMustache template renderMustache template
$ object [ "title" .= postTitle bp $ object [ "title" .= postTitle bp
, "authors" .= postAuthors bp , "author" .= postAuthor bp
, "date" .= postDate bp , "date" .= postDate bp
, "tags" .= postTags bp , "tags" .= postTags bp
, "description" .= postDescr bp , "description" .= postDescr bp
@ -183,8 +186,7 @@ postInfo bp =
"- " <> date <> ": " <> orglink "- " <> date <> ": " <> orglink
where where
date = T.takeWhile (/= ' ') (postDate bp) date = T.takeWhile (/= ' ') (postDate bp)
url = toS (dropDirectory1 (postUrl bp)) orglink = "[[file:" <> (toS (postUrl bp)) <> "][" <> (postTitle bp) <> "]]"
orglink = "[[file:" <> url <> "][" <> (postTitle bp) <> "]]"
replaceLinks :: Pandoc -> Pandoc replaceLinks :: Pandoc -> Pandoc
replaceLinks = walk replaceOrgLink replaceLinks = walk replaceOrgLink
@ -196,6 +198,7 @@ replaceLinks = walk replaceOrgLink
else lnk else lnk
replaceOrgLink x = x replaceOrgLink x = x
orgContentToText :: (MonadIO m, MonadFail m) => Text -> m Text
orgContentToText org = do orgContentToText org = do
eitherResult <- liftIO $ Pandoc.runIO $ Readers.readOrg (def { readerStandalone = True }) org eitherResult <- liftIO $ Pandoc.runIO $ Readers.readOrg (def { readerStandalone = True }) org
pandoc <- case eitherResult of pandoc <- case eitherResult of
@ -206,6 +209,7 @@ orgContentToText org = do
Left _ -> fail "BAD" Left _ -> fail "BAD"
Right innerHtml -> return innerHtml Right innerHtml -> return innerHtml
postamble :: (MonadIO m, MonadFail m) => Text -> BlogPost -> m Text
postamble now bp = postamble now bp =
orgContentToText $ unlines $ orgContentToText $ unlines $
[ "@@html:<footer>@@" [ "@@html:<footer>@@"
@ -228,7 +232,7 @@ genHtml bp = do
eitherHtml <- liftIO $ eitherHtml <- liftIO $
Pandoc.runIO $ Pandoc.runIO $
Writers.writeHtml5String Writers.writeHtml5String
(def { writerTableOfContents = (postToc bp) (def { writerTableOfContents = postToc bp
, writerEmailObfuscation = ReferenceObfuscation , writerEmailObfuscation = ReferenceObfuscation
}) })
htmlBody htmlBody
@ -239,11 +243,14 @@ genHtml bp = do
footer <- postamble (toS (iso8601Show now)) bp footer <- postamble (toS (iso8601Show now)) bp
return (body <> footer) return (body <> footer)
origin :: Text
origin = "https://her.esy.fun"
genHtmlAction genHtmlAction
:: (FilePath -> Action BlogPost) :: (FilePath -> Action BlogPost)
-> (FilePath -> Action Template) -> [Char] -> Action () -> (FilePath -> Action Template) -> [Char] -> Action ()
genHtmlAction getPost getTemplate out = do genHtmlAction getPost getTemplate out = do
let isPost = takeDirectory1 (dropDirectory1 out) == "post" let isPost = takeDirectory1 (dropDirectory1 out) == "posts"
template <- getTemplate ("templates" </> if isPost then "post.mustache" else "main.mustache") template <- getTemplate ("templates" </> if isPost then "post.mustache" else "main.mustache")
let srcFile = srcDir </> (dropDirectory1 (out -<.> "org")) let srcFile = srcDir </> (dropDirectory1 (out -<.> "org"))
liftIO $ putText $ "need: " <> (toS srcFile) <> " -> " <> (toS out) liftIO $ putText $ "need: " <> (toS srcFile) <> " -> " <> (toS out)
@ -253,11 +260,14 @@ genHtmlAction getPost getTemplate out = do
let htmlContent = let htmlContent =
renderMustache template renderMustache template
$ object [ "title" .= postTitle bp $ object [ "title" .= postTitle bp
, "authors" .= postAuthors bp , "author" .= postAuthor bp
, "date" .= postDate bp , "date" .= postDate bp
, "tags" .= postTags bp , "tags" .= postTags bp
, "description" .= postDescr bp , "description" .= postDescr bp
, "body" .= innerHtml , "body" .= innerHtml
, "orgsource" .= T.pack (postUrl bp -<.> "org")
, "txtsource" .= T.pack (postUrl bp -<.> "txt")
, "permalink" .= T.pack (toS origin <> postUrl bp)
] ]
writeFile' out (toS htmlContent) writeFile' out (toS htmlContent)
@ -278,7 +288,10 @@ genAsciiAction getPost out = do
bp <- getPost srcFile bp <- getPost srcFile
innerAscii <- genAscii bp innerAscii <- genAscii bp
let preamble = postTitle bp <> "\n" let preamble = postTitle bp <> "\n"
<> postDate bp <> "\n\n" <> T.replicate (T.length (postTitle bp)) "=" <> "\n\n"
<> postAuthor bp <> "\n"
<> postDate bp <> "\n"
<> toS origin <> toS (postUrl bp) <> "\n\n"
writeFile' out (toS (preamble <> toS innerAscii)) writeFile' out (toS (preamble <> toS innerAscii))
allHtmlAction :: Action () allHtmlAction :: Action ()
@ -289,7 +302,7 @@ allHtmlAction = do
allAsciiAction :: Action () allAsciiAction :: Action ()
allAsciiAction = do allAsciiAction = do
allOrgFiles <- getDirectoryFiles srcDir ["**.org"] allOrgFiles <- getDirectoryFiles srcDir ["//*.org"]
let allAsciiFiles = map (-<.> "txt") allOrgFiles let allAsciiFiles = map (-<.> "txt") allOrgFiles
need (map build allAsciiFiles) need (map build allAsciiFiles)

View file

@ -58,6 +58,7 @@ Here is the CSS you could use:
{{{colorbox(b1,black,#a7abb5)}}} {{{colorbox(b1,black,#a7abb5)}}}
{{{colorbox(b2,black,#e5e8f0)}}} {{{colorbox(b2,black,#e5e8f0)}}}
{{{colorbox(b3,black,#f3f6fe)}}} {{{colorbox(b3,black,#f3f6fe)}}}
@@html:<br/>@@
{{{colorbox(y,white,#ad8c51)}}} {{{colorbox(y,white,#ad8c51)}}}
{{{colorbox(o,white,#a9664b)}}} {{{colorbox(o,white,#a9664b)}}}
{{{colorbox(r,white,#af6256)}}} {{{colorbox(r,white,#af6256)}}}

View file

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title> <title>{{title}}</title>
<meta name="generator" content="ystgen"> <meta name="generator" content="ystgen">
<meta name="author" content="Yann Esposito"> <meta name="author" content="{{author}}">
<meta name="keywords" content="{{#tags}}{{.}} {{/tags}}"> <meta name="keywords" content="{{#tags}}{{.}} {{/tags}}">
<link rel="stylesheet" href="/css/y.css"/> <link rel="stylesheet" href="/css/y.css"/>
<link rel="alternate" type="application/rss+xml" href="/rss.xml" /> <link rel="alternate" type="application/rss+xml" href="/rss.xml" />
@ -34,9 +34,6 @@
<div class="content"><h1>{{title}}</h1></div> <div class="content"><h1>{{title}}</h1></div>
</div> </div>
<div id="content"> <div id="content">
<div class="abstract">
{{description}}
</div>
{{{ body }}} {{{ body }}}
</div> </div>
<div id="postamble" class="status"> <div id="postamble" class="status">

View file

@ -4,9 +4,9 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title> <title>{{title}}</title>
<meta name="author" content="Yann Esposito"> <meta name="author" content="{{author}}">
<meta name="description" content="{{description}}"> <meta name="description" content="{{description}}">
<meta name="keywords" content="{{#tags}}{{.}} {{/tags}}"> <meta name="keywords" content="{{#tags}}{{.}}{{^last}} {{/last}}{{/tags}}">
<link rel="stylesheet" href="/css/y.css"/><link rel="alternate" type="application/rss+xml" href="/rss.xml" /><link rel="icon" href="/favicon.ico"> <link rel="stylesheet" href="/css/y.css"/><link rel="alternate" type="application/rss+xml" href="/rss.xml" /><link rel="icon" href="/favicon.ico">
</head> </head>
<body><input name="t" type="radio" id="l"> <body><input name="t" type="radio" id="l">
@ -30,10 +30,11 @@
</div> </div>
<div class="content"> <div class="content">
<h1>{{title}}</h1> <h1>{{title}}</h1>
<div class="author">{{authors}}<br/> <div class="author">{{author}}<br/>
<span class="article-date">{{date}}</span><br/>on <span class="article-date">{{date}}</span><br/>on
<a href="https://her.esy.fun">Yann Esposito's blog</a> - <a href="https://her.esy.fun">Yann Esposito's blog</a> -
<a href="{{orgsource}}">source</a> - <a href="{{orgsource}}">source</a> -
<a href="{{txtsource}}">txt</a> -
<a class="permalink" href="{{permalink}}">§permalink</a> <a class="permalink" href="{{permalink}}">§permalink</a>
</div> </div>
<div class="abstract"> <div class="abstract">