mirror of
https://gitlab.com/upRootNutrition/website.git
synced 2025-06-16 20:35:13 -05:00
115 lines
2.9 KiB
Elm
Executable file
115 lines
2.9 KiB
Elm
Executable file
module Config.Helpers.Articles.Article exposing (..)
|
|
|
|
import Config.Data.Identity exposing (pageNames)
|
|
import Config.Helpers.Articles.Markdown
|
|
exposing
|
|
( articleImage
|
|
, renderDeviceMarkdown
|
|
, renderDeviceMarkdownNoToc
|
|
)
|
|
import Config.Helpers.Articles.Types exposing (References)
|
|
import Config.Helpers.Cards.Inner.Text exposing (detailFormat)
|
|
import Config.Helpers.Viewport exposing (resetViewport)
|
|
import Config.Pages.Blog.Types exposing (BlogArticle)
|
|
import Config.Style.Colour.Helpers
|
|
exposing
|
|
( ThemeColor(..)
|
|
, getThemeColor
|
|
)
|
|
import Config.Style.Transitions
|
|
exposing
|
|
( hoverFontDarkOrange
|
|
, transitionStyleFast
|
|
)
|
|
import Element as E exposing (..)
|
|
import Element.Background as B exposing (color)
|
|
import Element.Border as D exposing (width)
|
|
import Element.Font as F
|
|
exposing
|
|
( alignLeft
|
|
, bold
|
|
, color
|
|
, regular
|
|
)
|
|
|
|
|
|
contentList : BlogArticle -> List (Element msg) -> List (Element msg)
|
|
contentList article extraElements =
|
|
[ case article.articleImage of
|
|
"" ->
|
|
none
|
|
|
|
_ ->
|
|
articleImage article.articleImage
|
|
, case article.hasTableOfContents of
|
|
True ->
|
|
renderDeviceMarkdown article.articleBody
|
|
|
|
False ->
|
|
renderDeviceMarkdownNoToc article.articleBody
|
|
, case article.hasReferences of
|
|
True ->
|
|
articleReferences article
|
|
|
|
False ->
|
|
none
|
|
, detailFormat column extraElements
|
|
]
|
|
|
|
|
|
articleReferences : BlogArticle -> Element msg
|
|
articleReferences article =
|
|
column [ E.width fill, F.size 15, spacing 10 ] <|
|
|
List.map2 (\x y -> makeReference x y)
|
|
article.articleReferences
|
|
(List.range 1 (List.length article.articleReferences))
|
|
|
|
|
|
makeReference : References -> Int -> Element msg
|
|
makeReference references index =
|
|
let
|
|
comma =
|
|
", "
|
|
in
|
|
el
|
|
[ F.regular
|
|
, F.alignLeft
|
|
]
|
|
<|
|
|
paragraph []
|
|
[ newTabLink
|
|
[ F.bold
|
|
, F.color (getThemeColor TextLightOrange)
|
|
, hoverFontDarkOrange
|
|
, transitionStyleFast
|
|
]
|
|
{ url = references.link, label = text (String.fromInt index ++ ". ") }
|
|
, text (references.author ++ comma)
|
|
, text (references.title ++ comma)
|
|
, text (references.journal ++ comma)
|
|
, text references.year
|
|
]
|
|
|
|
|
|
extractFirstWords : String -> String
|
|
extractFirstWords text =
|
|
let
|
|
words =
|
|
text
|
|
|> String.split " "
|
|
|> List.filter (not << String.isEmpty)
|
|
|
|
truncatedWords =
|
|
List.take 80 words
|
|
|
|
wasTextTruncated =
|
|
List.length words > 80
|
|
|
|
result =
|
|
String.join " " truncatedWords
|
|
in
|
|
if wasTextTruncated then
|
|
result ++ "..."
|
|
|
|
else
|
|
result
|