source and use humanized tag names
This commit is contained in:
parent
d792ed815e
commit
8fd47d38bb
3
Types.hs
3
Types.hs
|
@ -39,6 +39,8 @@ data SiteState =
|
||||||
-- | Map of tags, assigning to each tag sequence a list of tagged page
|
-- | Map of tags, assigning to each tag sequence a list of tagged page
|
||||||
-- mounts. This one is expanded (tags imply parent categories).
|
-- mounts. This one is expanded (tags imply parent categories).
|
||||||
, _ehtags :: M.Map [String] [FilePath]
|
, _ehtags :: M.Map [String] [FilePath]
|
||||||
|
-- | Map of "short" tags to expanded human-friendly names
|
||||||
|
, _tagNames :: M.Map String String
|
||||||
-- | List of installed files (enables sharing)
|
-- | List of installed files (enables sharing)
|
||||||
, _installs :: S.Set (String, FilePath)
|
, _installs :: S.Set (String, FilePath)
|
||||||
-- | List of installed files (prevents overwriting)
|
-- | List of installed files (prevents overwriting)
|
||||||
|
@ -131,6 +133,7 @@ siteOptions' = do
|
||||||
, _redirects = M.empty
|
, _redirects = M.empty
|
||||||
, _htags = M.empty
|
, _htags = M.empty
|
||||||
, _ehtags = M.empty
|
, _ehtags = M.empty
|
||||||
|
, _tagNames = M.empty
|
||||||
, _installs = S.empty
|
, _installs = S.empty
|
||||||
, _targets = S.empty
|
, _targets = S.empty
|
||||||
, _templates = M.empty
|
, _templates = M.empty
|
||||||
|
|
|
@ -132,6 +132,11 @@ blockquote {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li.sidebox-tag {
|
||||||
|
padding-left: 1em;
|
||||||
|
text-indent: -1em;
|
||||||
|
}
|
||||||
|
|
||||||
/* search form and related stuff */
|
/* search form and related stuff */
|
||||||
|
|
||||||
.search-form-wrap {
|
.search-form-wrap {
|
||||||
|
|
|
@ -13,8 +13,7 @@ redirects:
|
||||||
- internal/internal/publication/codeCheck
|
- internal/internal/publication/codeCheck
|
||||||
tags:
|
tags:
|
||||||
- publication/ppc/code
|
- publication/ppc/code
|
||||||
- it/conventions
|
- it/license
|
||||||
- it/licensing
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# How-to: Pass a PPC code check
|
# How-to: Pass a PPC code check
|
||||||
|
|
8
cards/tagnames.yml
Normal file
8
cards/tagnames.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
"": "All"
|
||||||
|
publication: "Publication"
|
||||||
|
code: "Code"
|
||||||
|
about: "About"
|
||||||
|
license: "Licensing"
|
||||||
|
privacy: "Privacy"
|
||||||
|
it: "IT"
|
||||||
|
ppc: "Pre-Publication Check"
|
56
site.hs
56
site.hs
|
@ -7,6 +7,7 @@ import Control.Monad ((>=>), unless, when)
|
||||||
import Control.Monad.Extra (whenM)
|
import Control.Monad.Extra (whenM)
|
||||||
import Control.Monad.Trans.State.Lazy
|
import Control.Monad.Trans.State.Lazy
|
||||||
import qualified Data.Aeson as AE
|
import qualified Data.Aeson as AE
|
||||||
|
import qualified Data.Aeson.Key as K
|
||||||
import qualified Data.Aeson.KeyMap as KM
|
import qualified Data.Aeson.KeyMap as KM
|
||||||
import qualified Data.ByteString.Lazy as B
|
import qualified Data.ByteString.Lazy as B
|
||||||
import Data.Digest.Pure.SHA (sha256, showDigest)
|
import Data.Digest.Pure.SHA (sha256, showDigest)
|
||||||
|
@ -265,6 +266,42 @@ installAssets =
|
||||||
use assetDir >>=
|
use assetDir >>=
|
||||||
(io . getRecursiveContents (pure . const False) >=> traverse_ installAsset)
|
(io . getRecursiveContents (pure . const False) >=> traverse_ installAsset)
|
||||||
|
|
||||||
|
-- | Load tag names from a directory and add them to `tagNames`.
|
||||||
|
sourceTagnames :: FilePath -> Site ()
|
||||||
|
sourceTagnames fp =
|
||||||
|
io
|
||||||
|
(map (fp </>) . filter ((== "tagnames.yml") . last . splitPath) <$>
|
||||||
|
getRecursiveContents (pure . const False) fp) >>=
|
||||||
|
traverse_ sourceTagnameFile
|
||||||
|
|
||||||
|
-- | Single item for `sourceTagnames`
|
||||||
|
sourceTagnameFile :: FilePath -> Site ()
|
||||||
|
sourceTagnameFile fp = do
|
||||||
|
yml' <-
|
||||||
|
io $ do
|
||||||
|
putStrLn $ "# <- " ++ fp
|
||||||
|
Y.decodeFileEither fp
|
||||||
|
case yml' of
|
||||||
|
Left err ->
|
||||||
|
error $ "Failed to load tagnames from " ++ fp ++ ": " ++ show err
|
||||||
|
Right yml -> traverse_ add $ KM.toList (yml :: KM.KeyMap String)
|
||||||
|
where add :: (KM.Key, String) -> Site ()
|
||||||
|
add (k, v) =
|
||||||
|
let go (Just ov) =
|
||||||
|
if v == ov
|
||||||
|
then Just ov
|
||||||
|
else error
|
||||||
|
("conflicting tag names for tag " ++ K.toString k)
|
||||||
|
go Nothing = Just v
|
||||||
|
in tagNames %= M.alter go (K.toString k)
|
||||||
|
|
||||||
|
-- | Find the humanized name for a tag piece
|
||||||
|
getTagName :: String -> Site String
|
||||||
|
getTagName t = handleEmpty . maybe t id <$> use (tagNames . to (M.!? t))
|
||||||
|
where
|
||||||
|
handleEmpty "" = "all"
|
||||||
|
handleEmpty x = x
|
||||||
|
|
||||||
-- | Get all tags from the pages of the site.
|
-- | Get all tags from the pages of the site.
|
||||||
sourceTags :: Site ()
|
sourceTags :: Site ()
|
||||||
sourceTags = do
|
sourceTags = do
|
||||||
|
@ -314,10 +351,13 @@ listLink = rootUrl . ("list" </>) . tagPath
|
||||||
-- | Make metadata for printing out a single hierarchical tag (all levels clickable)
|
-- | Make metadata for printing out a single hierarchical tag (all levels clickable)
|
||||||
makeHTagMeta :: ([String] -> Site FilePath) -> [String] -> Site Y.Value
|
makeHTagMeta :: ([String] -> Site FilePath) -> [String] -> Site Y.Value
|
||||||
makeHTagMeta lf tag = do
|
makeHTagMeta lf tag = do
|
||||||
links <-
|
links <- traverse lf (inits tag)
|
||||||
zip (Y.Null : map fromString tag) . map fromString <$>
|
tags <- traverse getTagName ("" : tag)
|
||||||
traverse lf (inits tag)
|
pure . Y.array $
|
||||||
pure . Y.array $ map (\(t, p) -> Y.object [("tag", t), ("href", p)]) links
|
zipWith
|
||||||
|
(\t l -> Y.object [("tag", fromString t), ("href", fromString l)])
|
||||||
|
tags
|
||||||
|
links
|
||||||
|
|
||||||
-- | Make metadata for printing out a link to a page
|
-- | Make metadata for printing out a link to a page
|
||||||
makePageLinkMeta :: FilePath -> Site Y.Value
|
makePageLinkMeta :: FilePath -> Site Y.Value
|
||||||
|
@ -339,10 +379,11 @@ makeTagMeta tag = do
|
||||||
pagesMeta <- Y.array <$> traverse makePageLinkMeta taggedPages
|
pagesMeta <- Y.array <$> traverse makePageLinkMeta taggedPages
|
||||||
link <- tagLink tag
|
link <- tagLink tag
|
||||||
listlink <- listLink tag
|
listlink <- listLink tag
|
||||||
|
tags <- Y.array . map fromString <$> traverse getTagName tag
|
||||||
addGlobalMeta $
|
addGlobalMeta $
|
||||||
Y.object
|
Y.object
|
||||||
[ ("href", fromString link)
|
[ ("href", fromString link)
|
||||||
, ("tags", Y.array $ map fromString tag)
|
, ("tags", tags)
|
||||||
, ("htag", htagMeta)
|
, ("htag", htagMeta)
|
||||||
, ("subtags", subtagsMeta)
|
, ("subtags", subtagsMeta)
|
||||||
, ("pages", pagesMeta)
|
, ("pages", pagesMeta)
|
||||||
|
@ -353,8 +394,8 @@ makeTagMeta tag = do
|
||||||
makeHTagLinkMeta :: [String] -> Site Y.Value
|
makeHTagLinkMeta :: [String] -> Site Y.Value
|
||||||
makeHTagLinkMeta tag = do
|
makeHTagLinkMeta tag = do
|
||||||
link <- listLink tag
|
link <- listLink tag
|
||||||
pure $
|
tags <- Y.array . map fromString <$> traverse getTagName tag
|
||||||
Y.object [("href", fromString link), ("tags", Y.array $ map fromString tag)]
|
pure $ Y.object [("href", fromString link), ("tags", tags)]
|
||||||
|
|
||||||
-- | Create the structure for rendering a complete listing of one hierarchical tag.
|
-- | Create the structure for rendering a complete listing of one hierarchical tag.
|
||||||
makeListMeta :: [String] -> Site Y.Value
|
makeListMeta :: [String] -> Site Y.Value
|
||||||
|
@ -448,6 +489,7 @@ main = do
|
||||||
flip runStateT init $ do
|
flip runStateT init $ do
|
||||||
installAssets
|
installAssets
|
||||||
use sourceDirs >>= traverse sourcePages
|
use sourceDirs >>= traverse sourcePages
|
||||||
|
use sourceDirs >>= traverse sourceTagnames
|
||||||
sourceTags
|
sourceTags
|
||||||
use templateDir >>= sourceTemplates
|
use templateDir >>= sourceTemplates
|
||||||
use pages >>= traverse (uncurry installPage) . M.assocs
|
use pages >>= traverse (uncurry installPage) . M.assocs
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<div class="sidebox-values">
|
<div class="sidebox-values">
|
||||||
<ul>
|
<ul>
|
||||||
{{#htags}}
|
{{#htags}}
|
||||||
<li>{{#.}}<a href="{{href}}">{{^tag}}all{{/tag}}{{?tag}} » {{tag}}{{/tag}}{{/.}}</a></li>
|
<li class="sidebox-tag">{{#.}}<a href="{{href}}">{{^tag}}all{{/tag}}{{?tag}} » {{tag}}{{/tag}}{{/.}}</a></li>
|
||||||
{{/htags}}
|
{{/htags}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue