mirror of
https://github.com/avinal/avinal.github.io.git
synced 2026-07-03 23:30:09 +05:30
@@ -11,7 +11,6 @@
|
|||||||
"elm/html": "1.0.0",
|
"elm/html": "1.0.0",
|
||||||
"elm/http": "2.0.0",
|
"elm/http": "2.0.0",
|
||||||
"elm/url": "1.0.0",
|
"elm/url": "1.0.0",
|
||||||
"elm-explorations/markdown": "1.0.0",
|
|
||||||
"hecrj/html-parser": "2.4.0"
|
"hecrj/html-parser": "2.4.0"
|
||||||
},
|
},
|
||||||
"indirect": {
|
"indirect": {
|
||||||
@@ -28,4 +27,4 @@
|
|||||||
"direct": {},
|
"direct": {},
|
||||||
"indirect": {}
|
"indirect": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module Base exposing (urlPrefix)
|
||||||
|
|
||||||
|
urlPrefix : String
|
||||||
|
urlPrefix =
|
||||||
|
"website"
|
||||||
+137
-47
@@ -1,12 +1,11 @@
|
|||||||
module Blog exposing (..)
|
port module Blog exposing (..)
|
||||||
|
|
||||||
|
import Base exposing (urlPrefix)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (class, placeholder, value)
|
import Html.Attributes exposing (class, href, id, style)
|
||||||
import Html.Events exposing (onClick, onInput)
|
|
||||||
import Html.Parser
|
import Html.Parser
|
||||||
import Html.Parser.Util
|
import Html.Parser.Util
|
||||||
import Http exposing (Error(..))
|
import Http exposing (Error(..))
|
||||||
import Markdown exposing (defaultOptions)
|
|
||||||
import Url exposing (Protocol(..))
|
import Url exposing (Protocol(..))
|
||||||
|
|
||||||
|
|
||||||
@@ -37,27 +36,77 @@ type alias Blog =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- PORT
|
||||||
|
|
||||||
|
|
||||||
|
port sendString : String -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div [ class "foo-interface" ]
|
div [ class "foo-interface" ]
|
||||||
[ div [ class "foo-console foo-terminal foo-active" ]
|
[ div [ class "foo-console foo-terminal foo-active" ]
|
||||||
[ div [ class "max-width mx-auto px3 ltr" ]
|
[ div [ class "main-wrapper" ]
|
||||||
[ div
|
[ viewToc model.success
|
||||||
[ class "foo-term-story" ]
|
, main_ [ class "main-content", id "content" ]
|
||||||
[ input
|
[ viewArticle ]
|
||||||
[ placeholder "Enter URL to a markdown file"
|
]
|
||||||
, value model.markDownUrl
|
]
|
||||||
, onInput StoreInput
|
]
|
||||||
]
|
|
||||||
[]
|
|
||||||
, button [ onClick GetMarkdown ] [ text "Get Markdown" ]
|
|
||||||
]
|
|
||||||
, div [ class "content index py4" ]
|
|
||||||
[ if model.success then
|
|
||||||
markdownToHtml model
|
|
||||||
|
|
||||||
else
|
|
||||||
div [ class "foo-error" ] [ text model.markDown ]
|
viewToc : Bool -> Html Msg
|
||||||
|
viewToc show =
|
||||||
|
if show then
|
||||||
|
div
|
||||||
|
[ class "toc"
|
||||||
|
, style "display"
|
||||||
|
(if show then
|
||||||
|
"block"
|
||||||
|
|
||||||
|
else
|
||||||
|
"none"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
[ aside [ class "document-toc-container" ]
|
||||||
|
[ section [ class "document-toc" ]
|
||||||
|
[ h2 [ class "document-toc-heading" ] [ text "In this page" ]
|
||||||
|
, ul
|
||||||
|
[ class "document-toc-list", id "toc-entries" ]
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
else
|
||||||
|
div [] []
|
||||||
|
|
||||||
|
|
||||||
|
viewArticle : Html Msg
|
||||||
|
viewArticle =
|
||||||
|
article
|
||||||
|
[ class "main-page-content" ]
|
||||||
|
[ div [ id "insert-here" ] []
|
||||||
|
, viewMetadata
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
viewMetadata : Html Msg
|
||||||
|
viewMetadata =
|
||||||
|
aside [ class "metadata" ]
|
||||||
|
[ div [ class "metadata-content-container" ]
|
||||||
|
[ div [ class "on-github" ]
|
||||||
|
[ h3 [] [ text "Found a problem" ]
|
||||||
|
, ul []
|
||||||
|
[ li []
|
||||||
|
[ a [ href "https://github.com/avinal" ]
|
||||||
|
[ text "open an issue" ]
|
||||||
|
]
|
||||||
|
, li []
|
||||||
|
[ a [ href "https://avinal.space" ]
|
||||||
|
[ text "Website" ]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@@ -66,29 +115,58 @@ view model =
|
|||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= GetMarkdown
|
= GetMarkdown
|
||||||
| StoreInput String
|
|
||||||
| DataReceived (Result Http.Error String)
|
| DataReceived (Result Http.Error String)
|
||||||
|
|
||||||
|
|
||||||
init : () -> ( Model, Cmd Msg )
|
init : Maybe String -> ( Model, Cmd Msg )
|
||||||
init _ =
|
init slug =
|
||||||
( { blog =
|
( { blog = initBlog
|
||||||
{ title = "My First Blog Post"
|
, markDownUrl = finalUrl slug
|
||||||
, url = "my-first-blog-post"
|
|
||||||
, description = "This is my first blog post"
|
|
||||||
, content = "This is the content of my first blog post"
|
|
||||||
, category = "category"
|
|
||||||
, tags = [ "elm", "blog" ]
|
|
||||||
, date = "2018-01-01"
|
|
||||||
}
|
|
||||||
, markDownUrl = ""
|
|
||||||
, markDown = ""
|
, markDown = ""
|
||||||
, success = True
|
, success = False
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, getMarkdown <| finalUrl slug
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
getMarkdown : String -> Cmd Msg
|
||||||
|
getMarkdown url =
|
||||||
|
Http.get
|
||||||
|
{ url = url
|
||||||
|
, expect = Http.expectString DataReceived
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
finalUrl : Maybe String -> String
|
||||||
|
finalUrl slug =
|
||||||
|
let
|
||||||
|
resolvedSlug =
|
||||||
|
Maybe.withDefault "error" slug
|
||||||
|
in
|
||||||
|
case resolvedSlug of
|
||||||
|
"error" ->
|
||||||
|
"https://raw.githubusercontent.com/avinal/avinal.space/content/posts/error.md"
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
"https://raw.githubusercontent.com/avinal/"
|
||||||
|
++ urlPrefix
|
||||||
|
++ "/content/posts/"
|
||||||
|
++ resolvedSlug
|
||||||
|
++ ".md"
|
||||||
|
|
||||||
|
|
||||||
|
initBlog : Blog
|
||||||
|
initBlog =
|
||||||
|
{ title = ""
|
||||||
|
, url = ""
|
||||||
|
, description = ""
|
||||||
|
, content = ""
|
||||||
|
, category = ""
|
||||||
|
, tags = []
|
||||||
|
, date = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
@@ -96,14 +174,11 @@ update msg model =
|
|||||||
( model, Http.get { url = model.markDownUrl, expect = Http.expectString DataReceived } )
|
( model, Http.get { url = model.markDownUrl, expect = Http.expectString DataReceived } )
|
||||||
|
|
||||||
DataReceived (Ok data) ->
|
DataReceived (Ok data) ->
|
||||||
( { model | markDown = data, success = True }, Cmd.none )
|
( { model | markDown = data, success = True }, sendString data )
|
||||||
|
|
||||||
DataReceived (Err err) ->
|
DataReceived (Err err) ->
|
||||||
( { model | success = False, markDown = errorToString err }, Cmd.none )
|
( { model | success = False, markDown = errorToString err }, Cmd.none )
|
||||||
|
|
||||||
StoreInput input ->
|
|
||||||
( { model | markDownUrl = input }, Cmd.none )
|
|
||||||
|
|
||||||
|
|
||||||
errorToString : Http.Error -> String
|
errorToString : Http.Error -> String
|
||||||
errorToString error =
|
errorToString error =
|
||||||
@@ -140,11 +215,26 @@ textToHtml text =
|
|||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
markdownToHtml : Model -> Html Msg
|
|
||||||
markdownToHtml model =
|
-- main : Program (String, String) Model Msg
|
||||||
Markdown.toHtmlWith
|
-- main =
|
||||||
{ defaultOptions
|
-- Browser.element
|
||||||
| githubFlavored = Just { tables = True, breaks = False }
|
-- { init = init
|
||||||
}
|
-- , view = view
|
||||||
[]
|
-- , update = update
|
||||||
model.markDown
|
-- , subscriptions = \_ -> Sub.none
|
||||||
|
-- }
|
||||||
|
-- div
|
||||||
|
-- [ class "foo-term-story section-content" ]
|
||||||
|
-- [ input
|
||||||
|
-- [ placeholder "Enter URL to a markdown file"
|
||||||
|
-- , value model.markDownUrl
|
||||||
|
-- , onInput StoreInput
|
||||||
|
-- ]
|
||||||
|
-- []
|
||||||
|
-- , button [ class "button secondary", onClick GetMarkdown ] [ text "Get Markdown" ]
|
||||||
|
-- , if model.success then
|
||||||
|
-- div [] []
|
||||||
|
-- else
|
||||||
|
-- div [ class "foo-error" ] [ text model.markDown ]
|
||||||
|
-- ]
|
||||||
|
|||||||
+13
-18
@@ -1,5 +1,6 @@
|
|||||||
module Main exposing (main)
|
module Main exposing (main)
|
||||||
|
|
||||||
|
import Base exposing (urlPrefix)
|
||||||
import Blog as Blog
|
import Blog as Blog
|
||||||
import Browser exposing (Document)
|
import Browser exposing (Document)
|
||||||
import Browser.Navigation as Nav
|
import Browser.Navigation as Nav
|
||||||
@@ -80,9 +81,11 @@ view model =
|
|||||||
in
|
in
|
||||||
{ title = model.title
|
{ title = model.title
|
||||||
, body =
|
, body =
|
||||||
[ lazy viewHeader model.page
|
[ div [ class "foo-content" ]
|
||||||
, content
|
[ lazy viewHeader model.page
|
||||||
, lazy viewFooter model.page
|
, content
|
||||||
|
, lazy viewFooter model.page
|
||||||
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +221,7 @@ type Route
|
|||||||
| Blog
|
| Blog
|
||||||
| Terminal
|
| Terminal
|
||||||
| Static
|
| Static
|
||||||
|
| BlogPost String String
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -230,8 +234,7 @@ parser =
|
|||||||
[ Parser.map Splash Parser.top
|
[ Parser.map Splash Parser.top
|
||||||
, Parser.map Splash (s urlPrefix)
|
, Parser.map Splash (s urlPrefix)
|
||||||
, Parser.map Blog (s urlPrefix </> s "posts")
|
, Parser.map Blog (s urlPrefix </> s "posts")
|
||||||
|
, Parser.map BlogPost (s urlPrefix </> s "posts" </> Parser.string </> Parser.string)
|
||||||
-- , Parser.map BlogPost (s urlPrefix </> s "posts" </> Parser.string </> Parser.string)
|
|
||||||
, Parser.map Static (s urlPrefix </> s "pages")
|
, Parser.map Static (s urlPrefix </> s "pages")
|
||||||
, Parser.map Terminal (s urlPrefix </> s "terminal")
|
, Parser.map Terminal (s urlPrefix </> s "terminal")
|
||||||
]
|
]
|
||||||
@@ -245,12 +248,13 @@ updateUrl model =
|
|||||||
|> toSplash model
|
|> toSplash model
|
||||||
|
|
||||||
Just Blog ->
|
Just Blog ->
|
||||||
Blog.init ()
|
Blog.init Nothing
|
||||||
|
|> toBlog model
|
||||||
|
|
||||||
|
Just (BlogPost category slug) ->
|
||||||
|
Blog.init (Just (category ++ slug))
|
||||||
|> toBlog model
|
|> toBlog model
|
||||||
|
|
||||||
-- Just (BlogPost category slug) ->
|
|
||||||
-- Blog.init { category = category, slug = slug }
|
|
||||||
-- |> toBlog model
|
|
||||||
Just Terminal ->
|
Just Terminal ->
|
||||||
Terminal.init ()
|
Terminal.init ()
|
||||||
|> toTerminal model
|
|> toTerminal model
|
||||||
@@ -278,12 +282,3 @@ main =
|
|||||||
, onUrlChange = ChangeUrl
|
, onUrlChange = ChangeUrl
|
||||||
, onUrlRequest = ClickedLink
|
, onUrlRequest = ClickedLink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- URLPREFIX
|
|
||||||
|
|
||||||
|
|
||||||
urlPrefix : String
|
|
||||||
urlPrefix =
|
|
||||||
"website"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user