website/frontend/src/Config/Helpers/Articles/Article.elm

116 lines
2.9 KiB
Elm
Raw Normal View History

2024-12-18 20:11:04 -06:00
module Config.Helpers.Articles.Article exposing (..)
import Config.Data.Identity exposing (pageNames)
2025-01-02 02:33:57 -06:00
import Config.Helpers.Articles.Markdown
2024-12-18 20:11:04 -06:00
exposing
2025-01-02 02:33:57 -06:00
( articleImage
, renderDeviceMarkdown
, renderDeviceMarkdownNoToc
2024-12-18 20:11:04 -06:00
)
2025-01-02 02:33:57 -06:00
import Config.Helpers.Articles.Types exposing (References)
import Config.Helpers.Cards.Inner.Text exposing (detailFormat)
2024-12-18 20:11:04 -06:00
import Config.Helpers.Viewport exposing (resetViewport)
import Config.Pages.Blog.Types exposing (BlogArticle)
2025-01-02 02:33:57 -06:00
import Config.Style.Colour.Helpers
exposing
( ThemeColor(..)
, getThemeColor
)
2024-12-18 20:11:04 -06:00
import Config.Style.Transitions
exposing
( hoverFontDarkOrange
, transitionStyleFast
)
import Element as E exposing (..)
2025-01-02 02:33:57 -06:00
import Element.Background as B exposing (color)
import Element.Border as D exposing (width)
2024-12-18 20:11:04 -06:00
import Element.Font as F
2025-01-02 02:33:57 -06:00
exposing
( alignLeft
, bold
, color
, regular
)
2024-12-18 20:11:04 -06:00
2024-12-28 18:42:47 -06:00
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
2024-12-28 18:42:47 -06:00
, detailFormat column extraElements
]
2024-12-18 20:11:04 -06:00
articleReferences : BlogArticle -> Element msg
articleReferences article =
2025-01-02 02:33:57 -06:00
column [ E.width fill, F.size 15, spacing 10 ] <|
2024-12-28 18:42:47 -06:00
List.map2 (\x y -> makeReference x y)
article.articleReferences
(List.range 1 (List.length article.articleReferences))
2024-12-18 20:11:04 -06:00
makeReference : References -> Int -> Element msg
makeReference references index =
2024-12-28 18:42:47 -06:00
let
comma =
", "
in
2024-12-18 20:11:04 -06:00
el
[ F.regular
, F.alignLeft
]
<|
paragraph []
[ newTabLink
[ F.bold
2025-01-02 02:33:57 -06:00
, F.color (getThemeColor TextLightOrange)
2024-12-18 20:11:04 -06:00
, hoverFontDarkOrange
, transitionStyleFast
]
{ url = references.link, label = text (String.fromInt index ++ ". ") }
2024-12-28 18:42:47 -06:00
, text (references.author ++ comma)
, text (references.title ++ comma)
, text (references.journal ++ comma)
2024-12-18 20:11:04 -06:00
, 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