Compare commits

..

No commits in common. "6c3f4f3031c703abce35e91875bb51138159497f" and "931d9c44831f26e908eff49f5ecdc3ab13242d7d" have entirely different histories.

4 changed files with 22 additions and 34 deletions

View file

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

View file

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

View file

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

View file

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