filter updates & figure fixups
This commit is contained in:
parent
9ec847179c
commit
cb4649c2e2
5 changed files with 54 additions and 18 deletions
|
@ -6,26 +6,28 @@ author: rhiannon morris <rhi@rhiannon.website>
|
||||||
maintainer: rhiannon morris <rhi@rhiannon.website>
|
maintainer: rhiannon morris <rhi@rhiannon.website>
|
||||||
|
|
||||||
common deps
|
common deps
|
||||||
default-language: Haskell2010
|
default-language: GHC2024
|
||||||
default-extensions:
|
default-extensions:
|
||||||
BlockArguments,
|
BlockArguments,
|
||||||
DuplicateRecordFields,
|
DuplicateRecordFields,
|
||||||
OverloadedStrings,
|
OverloadedStrings,
|
||||||
OverloadedLists,
|
OverloadedLists,
|
||||||
NamedFieldPuns,
|
|
||||||
NondecreasingIndentation,
|
NondecreasingIndentation,
|
||||||
RecordWildCards,
|
RecordWildCards,
|
||||||
ViewPatterns
|
ViewPatterns
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.14.2.0 && < 4.18,
|
base >= 4.14.2.0 && < 4.21,
|
||||||
|
mtl,
|
||||||
HsYAML ^>= 0.2.1.0,
|
HsYAML ^>= 0.2.1.0,
|
||||||
bytestring ^>= 0.11.4.0,
|
bytestring ^>= 0.11.4.0,
|
||||||
containers ^>= 0.6.4.1,
|
containers ^>= 0.6.4.1,
|
||||||
filemanip,
|
filemanip,
|
||||||
filepath ^>= 1.4.2.1,
|
filepath ^>= 1.4.2.1,
|
||||||
pandoc-types ^>= 1.23,
|
pandoc-types ^>= 1.23,
|
||||||
text ^>= 1.2.4.1,
|
text >= 2 && < 2.2,
|
||||||
time ^>= 1.9.3
|
time ^>= 1.9.3
|
||||||
|
build-tool-depends:
|
||||||
|
langfilter:langfilter
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
common exe
|
common exe
|
||||||
|
@ -58,3 +60,8 @@ executable slug-tags
|
||||||
import: deps, exe
|
import: deps, exe
|
||||||
hs-source-dirs: .
|
hs-source-dirs: .
|
||||||
main-is: slug-tags.hs
|
main-is: slug-tags.hs
|
||||||
|
|
||||||
|
executable fix-figures
|
||||||
|
import: deps, exe
|
||||||
|
hs-source-dirs: .
|
||||||
|
main-is: fix-figures.hs
|
||||||
|
|
15
blog-meta/fix-figures.hs
Normal file
15
blog-meta/fix-figures.hs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import Text.Pandoc.JSON
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = toJSONFilter $ expandable . shaped where
|
||||||
|
expandable (Figure attr@(_, cs, _) cap [Plain img@[Image _ _ t]])
|
||||||
|
| "expandable" `elem` cs = Figure attr cap $ [Plain [Link blank img t]]
|
||||||
|
expandable b = b
|
||||||
|
|
||||||
|
blank = ("", [], [("target", "_blank")])
|
||||||
|
|
||||||
|
shaped (Figure (i, cs, as) cap [Plain img@[Image _ _ (url, _)]])
|
||||||
|
| "shaped" `elem` cs =
|
||||||
|
let shape = "shape-outside: url(" <> url <> ")" in
|
||||||
|
Figure (i, cs, ("style", shape) : as) cap [Plain img]
|
||||||
|
shaped b = b
|
|
@ -2,16 +2,26 @@ import Text.Pandoc.Definition
|
||||||
import qualified Data.Map.Strict as Map
|
import qualified Data.Map.Strict as Map
|
||||||
import Text.Pandoc.JSON
|
import Text.Pandoc.JSON
|
||||||
import Misc
|
import Misc
|
||||||
|
import Control.Monad.Writer
|
||||||
|
import Data.Monoid
|
||||||
|
|
||||||
-- | replaces the @date@ field, which starts in YYYY-MM-DD format, with
|
-- | replaces the @date@ field, which starts in YYYY-MM-DD format, with
|
||||||
-- something prettier
|
-- something prettier
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = toJSONFilter \(Pandoc (Meta m) body) -> do
|
main = toJSONFilter \(Meta m) -> do
|
||||||
m' <- Map.alterF reformat "date" m
|
(res', mdate) <- run $ Map.alterF reformat' "date" m
|
||||||
pure $ Pandoc (Meta m') body
|
let res = maybe m (\d -> Map.insert "date-iso" d res') mdate
|
||||||
|
pure $ Meta res
|
||||||
|
|
||||||
reformat :: Maybe MetaValue -> IO (Maybe MetaValue)
|
type T = WriterT (Alt Maybe MetaValue) IO
|
||||||
reformat Nothing = pure Nothing
|
|
||||||
reformat (Just (toText -> Just txt)) =
|
run :: T a -> IO (a, Maybe MetaValue)
|
||||||
Just . MetaString . showDate <$> parseIsoDate txt
|
run = fmap (fmap getAlt) . runWriterT
|
||||||
reformat (Just d) = fail $ "date is\n" <> show d <> "\nwanted a string"
|
|
||||||
|
reformat' :: Maybe MetaValue -> T (Maybe MetaValue)
|
||||||
|
reformat' Nothing = pure Nothing
|
||||||
|
reformat' (Just d) = do tell $ pure d; Just <$> reformat d
|
||||||
|
|
||||||
|
reformat :: MetaValue -> T MetaValue
|
||||||
|
reformat (toText -> Just txt) = MetaString . showDate <$> parseIsoDate txt
|
||||||
|
reformat d = fail $ "date is\n" <> show d <> "\nwanted a string"
|
||||||
|
|
|
@ -99,6 +99,7 @@ data PostInfo =
|
||||||
file :: FilePath,
|
file :: FilePath,
|
||||||
title :: Text, -- ^ post @title@
|
title :: Text, -- ^ post @title@
|
||||||
date :: IsoDate, -- ^ post @date@
|
date :: IsoDate, -- ^ post @date@
|
||||||
|
dateStr :: Text, -- ^ post @date@, but as text
|
||||||
tags :: [Text], -- ^ post @tags@
|
tags :: [Text], -- ^ post @tags@
|
||||||
summary :: Maybe Text -- ^ post @summary@ (optional)
|
summary :: Maybe Text -- ^ post @summary@ (optional)
|
||||||
}
|
}
|
||||||
|
@ -116,6 +117,7 @@ getInfo dir file = do
|
||||||
Info <$> pure file'
|
Info <$> pure file'
|
||||||
<*> m .: "title"
|
<*> m .: "title"
|
||||||
<*> m .: "date"
|
<*> m .: "date"
|
||||||
|
<*> m .: "date"
|
||||||
<*> m .: "tags" .!= []
|
<*> m .: "tags" .!= []
|
||||||
<*> m .:? "summary"
|
<*> m .:? "summary"
|
||||||
|
|
||||||
|
@ -123,6 +125,7 @@ instance YAML.ToYAML PostInfo where
|
||||||
toYAML (Info {..}) = YAML.obj
|
toYAML (Info {..}) = YAML.obj
|
||||||
["date" ##= showDate date,
|
["date" ##= showDate date,
|
||||||
"date-rss" ##= rssDate date,
|
"date-rss" ##= rssDate date,
|
||||||
|
"date-iso" ##= dateStr,
|
||||||
"title" ##= title,
|
"title" ##= title,
|
||||||
"tags" ##= tags,
|
"tags" ##= tags,
|
||||||
"file" ##= htmlFile file,
|
"file" ##= htmlFile file,
|
||||||
|
|
|
@ -4,13 +4,13 @@ packages:
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://git.rhiannon.website/rhi/lang.git
|
location: https://git.rhiannon.website/rhi/lang.git
|
||||||
tag: 3cd2c59be2195e5b2e79e4a90c80bd6015c1f0bd
|
tag: a7bbfd5035adf67e128e030e3ba47c6fb8ed3be5
|
||||||
subdir: langfilter
|
subdir: langfilter
|
||||||
|
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://git.rhiannon.website/rhi/lang.git
|
location: https://git.rhiannon.website/rhi/lang.git
|
||||||
tag: 3cd2c59be2195e5b2e79e4a90c80bd6015c1f0bd
|
tag: a7bbfd5035adf67e128e030e3ba47c6fb8ed3be5
|
||||||
subdir: laantas-script
|
subdir: laantas-script
|
||||||
|
|
||||||
source-repository-package
|
source-repository-package
|
||||||
|
@ -20,10 +20,11 @@ source-repository-package
|
||||||
|
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://git.rhiannon.website/rhi/svg-builder
|
location: https://git.rhiannon.website/rhi/svg-builder.git
|
||||||
tag: 1cbcd594d3009f9fd71f253b52ac82673bf5482e
|
tag: 9c09fcea4ac316dd5e0709b40f85952047070bf1
|
||||||
|
|
||||||
allow-newer: *
|
|
||||||
|
|
||||||
constraints:
|
constraints:
|
||||||
pandoc-types == 1.23.1
|
pandoc-types == 1.23.1
|
||||||
|
|
||||||
|
shared: False
|
||||||
|
executable-dynamic: False
|
||||||
|
|
Loading…
Add table
Reference in a new issue