Commit a7d15ffb authored by Fabien Maniere's avatar Fabien Maniere

test: adding tiles to manage external links

parent bc9dfdcf
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveGeneric #-}
module Tile where
import GHC.Generics
import qualified Data.Aeson as Aeson
import qualified Data.Yaml as Yaml
import Hakyll
import Data.Binary
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
data Tile = Tile
{ tileTitle :: String
, tileURL :: String
, tileImageURL :: String
, tileDescription :: String
} deriving (Eq, Show, Generic)
instance Binary Tile where
put Tile{..} = do
put tileTitle
put tileURL
put tileImageURL
put tileDescription
get = Tile <$> get <*> get <*> get <*> get
instance Writable Tile where
write path Item{..} =
BL.writeFile path $ Aeson.encode itemBody
instance Aeson.FromJSON Tile
instance Aeson.ToJSON Tile
parseTileM :: MonadFail m => BS.ByteString -> m Tile
parseTileM body =
case Yaml.decodeEither' body of
Left err -> fail $ "failed to parse tile file: " <> show err
Right parsed -> pure parsed
...@@ -48,22 +48,26 @@ section .card * { ...@@ -48,22 +48,26 @@ section .card * {
transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
} }
section .card:hover { .panel-articles .card:hover,
#section-connect .card:hover {
border: 1px solid var(--bs-primary); border: 1px solid var(--bs-primary);
cursor: pointer; cursor: pointer;
} }
section .card:hover .card-title { .panel-articles .card:hover .card-title,
#section-connect .card:hover .card-title {
color: var(--bs-primary); color: var(--bs-primary);
} }
.card-header { .card-header {
border-bottom: 0; border-bottom: 0;
} }
.card { .panel-articles .card,
#section-connect .card {
position: relative; position: relative;
} }
.card a.btn::before { .panel-articles .card a.btn::before,
#section-connect .card a.btn::before {
content: ""; content: "";
position: absolute; position: absolute;
top: 0px; top: 0px;
......
...@@ -5,7 +5,14 @@ cabal-version: >= 1.10 ...@@ -5,7 +5,14 @@ cabal-version: >= 1.10
executable site executable site
main-is: site.hs main-is: site.hs
other-modules: Tile
build-depends: base == 4.* build-depends: base == 4.*
, hakyll == 4.16.* , hakyll == 4.16.*
, aeson
, binary
, bytestring
, filepath
, time
, yaml
ghc-options: -threaded -rtsopts -with-rtsopts=-N ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010 default-language: Haskell2010
...@@ -178,11 +178,65 @@ keywords: gargantext, libre, fiable, transparent, intelligible, écosystème, d ...@@ -178,11 +178,65 @@ keywords: gargantext, libre, fiable, transparent, intelligible, écosystème, d
<div class="container"> <div class="container">
<div class="row align-items-center justify-content-around px-3"> <div class="row align-items-center justify-content-around px-3">
<div class="col"> <div class="col">
<h2 class=" section-title pb-3"><i class="fa fa-question-circle text-garg-gradient" aria-hidden="true"></i> <span class="text-garg-gradient"> Découvrir GarganText</span></h2> <h2 class="section-title pb-3"><i class="fa fa-question-circle text-garg-gradient" aria-hidden="true"></i> <span class="text-garg-gradient"> Découvrir GarganText</span></h2>
<div class="section-content"> <div class="section-content">
<h3 class="my-4 pb-1 fs-4 border-bottom border-primary">En bref</h3>
<div class="row row-cols-1 row-cols-lg-3 g-4">
<div class="col">
<div class="card key-number h-100">
<a class="btn btn-lg btn-success" href="https://gitlab.iscpif.fr/gargantext/main" target="_blank">
<i class="fa fa-flag fa-2x pull-left"></i> GarganText
<br>Frontend v0.0.7.1.6.5
<br>Backend v0.0.7.1.6.5
</a>
</div>
</div>
</div>
<div class="row row-cols-1 row-cols-lg-3 g-4">
<div class="col">
<div class="card key-number h-100">
<div class="row g-0">
<div class="col">
<div class="card-body text-center text-garg-secondary fw-bold">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x text-garg-gradient"></i>
<i class="fa icon-ecosystem fa-stack-1x fa-inverse pt-2"></i>
</span>
<p class="card-text mb-0 fs-2">15 000 utilisateurs</p>
<p class="card-text fs-3">12 instances</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row row-cols-1 row-cols-lg-3 g-4">
<div class="col">
<div class="card key-number h-100">
<div class="row g-0">
<div class="col">
<div class="card-body text-center text-garg-secondary fw-bold">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x text-garg-gradient"></i>
<i class="fa fa-server fa-stack-1x fa-inverse"></i>
</span>
<p class="card-text mb-0 fs-1">12</p>
<p class="card-text fs-3">instances</p>
</div>
</div>
</div>
</div>
</div>
</div>
<h3 class="my-4 pb-1 fs-4 border-bottom border-primary">Présentation</h3> <h3 class="my-4 pb-1 fs-4 border-bottom border-primary">Présentation</h3>
$partial("templates/tiles.html")$
<div class="row row-cols-1 row-cols-lg-2 g-4"> <div class="row row-cols-1 row-cols-lg-2 g-4">
<div class="col"> <div class="col">
<div class="card h-100" style=""> <div class="card h-100" style="">
......
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
import Data.Aeson
import qualified Data.ByteString.Lazy as BL
import Data.Monoid (mappend) import Data.Monoid (mappend)
import Data.Time.Calendar
import Data.Time.Clock
import Hakyll import Hakyll
import Hakyll.Core.Compiler
import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Provider
import System.FilePath.Posix
import Tile
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
main :: IO () main :: IO ()
main = hakyllWith config $ do main = do
ctx <- mkContext
hakyllWith config $ do
match "tiles/*.yaml" $ do
compile parseTileCompiler
create ["tiles.json"] $ do
route idRoute
compile $ do
tiles <- loadAll @Tile "tiles/*.yaml"
item <- (makeItem . BL.unpack . encode . map itemBody) tiles
saveSnapshot "_final" item
pure item
match ("js/*" .||. "images/*" .||. "favicon/*" .||. "css/fonts/*") $ do match ("js/*" .||. "images/*" .||. "favicon/*" .||. "css/fonts/*") $ do
route idRoute route idRoute
compile copyFileCompiler compile copyFileCompiler
match "css/*" $ do match "css/*" $ do
route idRoute route idRoute
compile compressCssCompiler compile compressCssCompiler
-- match (fromList ["about.rst", "contact.markdown"]) $ do -- match (fromList ["about.rst", "contact.markdown"]) $ do
-- route $ setExtension "html" -- route $ setExtension "html"
...@@ -44,17 +68,22 @@ main = hakyllWith config $ do ...@@ -44,17 +68,22 @@ main = hakyllWith config $ do
match "index.html" $ do match "index.html" $ do
route idRoute route idRoute
compile $ do compile $ do
posts <- recentFirst =<< loadAll "posts/*" tiles <- loadAll @Tile "tiles/*.yaml"
let indexCtx = let
listField "posts" postCtx (return posts) `mappend` indexCtx = listField "tiles" tileContext (pure tiles) `mappend`
defaultContext ctx
defCompiler indexCtx
getResourceBody -- posts <- recentFirst =<< loadAll "posts/*"
>>= applyAsTemplate indexCtx -- let indexCtx =
>>= loadAndApplyTemplate "templates/default.html" indexCtx -- listField "posts" postCtx (return posts) `mappend`
>>= relativizeUrls -- defaultContext
-- getResourceBody
-- >>= applyAsTemplate indexCtx
-- >>= loadAndApplyTemplate "templates/default.html" indexCtx
-- >>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler match "templates/*" $ compile templateBodyCompiler
...@@ -62,14 +91,49 @@ main = hakyllWith config $ do ...@@ -62,14 +91,49 @@ main = hakyllWith config $ do
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
postCtx :: Context String postCtx :: Context String
postCtx = postCtx =
dateField "date" "%B %e, %Y" `mappend` dateField "date" "%B %e, %Y" `mappend`
defaultContext defaultContext
config :: Configuration config :: Configuration
config = defaultConfiguration config = defaultConfiguration
{ previewPort = 7000 { previewPort = 7000
, deployCommand = "sudo rsync --checksum --delete -chavzPpr \ , deployCommand = "sudo rsync --checksum --delete -chavzPpr \
\_site/* \ \_site/* \
\/var/www/html/gargantext-org \ \/var/www/html/gargantext-org \
\&& sudo chown -R www-data: /var/www/html/gargantext-org" \&& sudo chown -R www-data: /var/www/html/gargantext-org"
} }
\ No newline at end of file
parseTileCompiler :: Compiler (Item Tile)
parseTileCompiler = do
identifier <- getUnderlying
provider <- compilerProvider <$> compilerAsk
body <- unsafeCompiler $ BL.readFile (resourceFilePath provider identifier)
tile <- parseTileM (BL.toStrict body)
makeItem tile
defCompiler :: Context String -> Compiler (Item String)
defCompiler ctx = getResourceBody
>>= applyAsTemplate ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
mkContext :: IO (Context String)
mkContext = do
(year, _, _) <- toGregorian . utctDay <$> getCurrentTime
return $ constField "year" (show year)
<> dropIndexHtml
<> defaultContext
dropIndexHtml :: Context a
dropIndexHtml = mapContext transform (urlField "url") where
transform url = case splitFileName url of
(p, "index.html") -> takeDirectory p
_ -> url
tileContext :: Context Tile
tileContext =
mconcat [ field "tileTitle" (pure . tileTitle . itemBody)
, field "tileURL" (pure . tileURL . itemBody)
, field "tileImageURL" (pure . tileImageURL . itemBody)
, field "tileDescription" (pure . tileDescription . itemBody)
]
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<footer class="bg-green justify-content-center align-items-center text-center p-4 mt-5"> <footer class="bg-green justify-content-center align-items-center text-center p-4 mt-5">
<div class="footer-bottom text-light text-center py-5 "><a href="https://gitlab.iscpif.fr/gargantext/main/raw/master/LICENSE" target="_blank" class="text-light">Mentions légales <i class="fa fa-external-link " aria-hidden="true"></i></a> - © GarganText 2024</div> <div class="footer-bottom text-light text-center py-5 "><a href="https://gitlab.iscpif.fr/gargantext/main/raw/master/LICENSE" target="_blank" class="text-light">Mentions légales <i class="fa fa-external-link " aria-hidden="true"></i></a> - © GarganText $year$</div>
<ul class="logos list-unstyled list-inline"> <ul class="logos list-unstyled list-inline">
<li class="list-inline-item"><a href="https://www.cnrs.fr" target="_blank" class="footer-link"><img src="/images/logo-cnrs-white.png" alt="CNRS - Centre national de la recherche scientifique" class="logo logo-iscpif"></a></li> <li class="list-inline-item"><a href="https://www.cnrs.fr" target="_blank" class="footer-link"><img src="/images/logo-cnrs-white.png" alt="CNRS - Centre national de la recherche scientifique" class="logo logo-iscpif"></a></li>
<a class="list-inline-item"><a href="https://iscpif.fr" target="_blank" class="footer-link"><img src="/images/logo-iscpif.png" alt="ISCPIF - Institut des systèmes complexes Paris Ile-de-France" class="logo logo-cnrs"></a></li> <a class="list-inline-item"><a href="https://iscpif.fr" target="_blank" class="footer-link"><img src="/images/logo-iscpif.png" alt="ISCPIF - Institut des systèmes complexes Paris Ile-de-France" class="logo logo-cnrs"></a></li>
......
<div class="row row-cols-1 row-cols-lg-2 g-4">
$for(tiles)$
<div class="col">
<div class="card h-100" style="">
<div class="row g-0">
<div class="img-wrapper col-md-5">
<img src="$tileImageURL$" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-7">
<div class="card-body">
<h5 class="card-title">$tileTitle$</h5>
<p class="card-text">$tileDescription$</p>
<p class="card-text"><small class="text-muted">$tileURL$ <i class="fa fa-external-link " aria-hidden="true"></i></small></p>
<a href="$tileURL$" target="_blank" class="btn btn-primary">Voir <i class="fa fa-external-link " aria-hidden="true"></i></a>
</div>
</div>
</div>
</div>
</div>
$endfor$
</div>
---
tileTitle: Test tile 2
tileURL: https://iscpif.fr/projects/gargantext/
tileImageURL: images/preview-project-iscpif.png
tileDescription: |
Page projet sur le site de l'Institut des systèmes complexes de Paris-&Icirc;le-France.
tileDate:
\ No newline at end of file
---
tileTitle: GarganText - Le projet
tileURL: https://iscpif.fr/projects/gargantext/
tileImageURL: images/preview-project-iscpif.png
tileDescription: |
Page projet sur le site de l'Institut des systèmes complexes de Paris-&Icirc;le-France.
tileDate:
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment