mirror of
https://github.com/avinal/avinal.github.io.git
synced 2026-07-03 23:30:09 +05:30
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/url": "1.0.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.3"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
module Blog exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (class, datetime)
|
||||
|
||||
|
||||
|
||||
-- MODEL
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ blog : Blog
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- Blog Post
|
||||
|
||||
|
||||
type alias Blog =
|
||||
{ title : String
|
||||
, url : String
|
||||
, description : String
|
||||
, content : String
|
||||
, category : String
|
||||
, tags : List String
|
||||
, date : String
|
||||
}
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
view model =
|
||||
div [ class "max-width mx-auto px3 ltr" ]
|
||||
[ div [ class "content index py4" ]
|
||||
[ article [ class "post" ]
|
||||
[ h1 [ class "posttitle" ] [ text model.blog.title ]
|
||||
, div [ class "meta" ]
|
||||
[ div [ class "article-tag" ]
|
||||
[ a [ class "tag-link" ] [ text "tag" ] ]
|
||||
]
|
||||
, div [ class "content" ] [ text model.blog.content ]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
type Msg
|
||||
= Nothing
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( { blog =
|
||||
{ title = "My First Blog Post"
|
||||
, url = "my-first-blog-post"
|
||||
, description = "This is my first blog post"
|
||||
, content = "This is the content of my first blog post"
|
||||
, category = "blog"
|
||||
, tags = [ "elm", "blog" ]
|
||||
, date = "2018-01-01"
|
||||
}
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Blog as Blog
|
||||
import Browser exposing (Document)
|
||||
import Browser.Navigation as Nav
|
||||
import Html exposing (Html, a, div, footer, header, img, li, text, ul)
|
||||
import Html.Attributes exposing (class, href, src)
|
||||
import Html.Lazy exposing (lazy)
|
||||
import Splash as Splash
|
||||
import Static as Static
|
||||
import Terminal as Terminal
|
||||
import Url exposing (Url)
|
||||
import Url.Parser as Parser exposing ((</>), Parser, s)
|
||||
|
||||
|
||||
|
||||
--MODEL
|
||||
|
||||
|
||||
{-| Model design
|
||||
Model
|
||||
Page: Page that currently is active
|
||||
-}
|
||||
type alias Model =
|
||||
{ page : Page
|
||||
, title : String
|
||||
, key : Nav.Key
|
||||
, url : Url
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- PAGE
|
||||
|
||||
|
||||
{-| Page designs
|
||||
|
||||
BlogPage: Page design for blogs
|
||||
TerminalPage: Page design for terminal
|
||||
StaticPage: Page design for static pages
|
||||
NotFound: Page design for 404 page
|
||||
|
||||
-}
|
||||
type Page
|
||||
= SplashPage Splash.Model
|
||||
| BlogPage Blog.Model
|
||||
| TerminalPage Terminal.Model
|
||||
| StaticPage Static.Model
|
||||
| NotFound
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Model -> Document Msg
|
||||
view model =
|
||||
let
|
||||
content =
|
||||
case model.page of
|
||||
SplashPage splashModel ->
|
||||
Splash.view splashModel
|
||||
|> Html.map GotSplashMsg
|
||||
|
||||
BlogPage blogs ->
|
||||
Blog.view blogs
|
||||
|> Html.map GotBlogMsg
|
||||
|
||||
TerminalPage terminal ->
|
||||
Terminal.view terminal
|
||||
|> Html.map GotTerminalMsg
|
||||
|
||||
StaticPage static ->
|
||||
Static.view static
|
||||
|> Html.map GotStaticMsg
|
||||
|
||||
NotFound ->
|
||||
text "404"
|
||||
in
|
||||
{ title = model.title
|
||||
, body =
|
||||
[ lazy viewHeader model.page
|
||||
, content
|
||||
, lazy viewFooter model.page
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= GotSplashMsg Splash.Msg
|
||||
| GotBlogMsg Blog.Msg
|
||||
| GotTerminalMsg Terminal.Msg
|
||||
| GotStaticMsg Static.Msg
|
||||
| ChangeUrl Url
|
||||
| ClickedLink Browser.UrlRequest
|
||||
|
||||
|
||||
viewHeader : Page -> Html msg
|
||||
viewHeader page =
|
||||
let
|
||||
headerContent =
|
||||
case page of
|
||||
SplashPage _ ->
|
||||
div [] []
|
||||
|
||||
_ ->
|
||||
header [ class "foo-logo" ]
|
||||
[ img [ src "logo-static.svg" ]
|
||||
[]
|
||||
]
|
||||
in
|
||||
headerContent
|
||||
|
||||
|
||||
viewFooter : Page -> Html msg
|
||||
viewFooter page =
|
||||
let
|
||||
footerContent =
|
||||
case page of
|
||||
SplashPage _ ->
|
||||
div [] []
|
||||
|
||||
_ ->
|
||||
footer [ class "foo-footer" ]
|
||||
[ ul []
|
||||
[ li []
|
||||
[ a [ href urlPrefix ] [ text "Home" ]
|
||||
]
|
||||
]
|
||||
]
|
||||
in
|
||||
footerContent
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
GotSplashMsg splashMsg ->
|
||||
case model.page of
|
||||
SplashPage splash ->
|
||||
toSplash model (Splash.update splashMsg splash)
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
GotBlogMsg blogMsg ->
|
||||
case model.page of
|
||||
BlogPage blog ->
|
||||
toBlog model (Blog.update blogMsg blog)
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
GotTerminalMsg terminalMsg ->
|
||||
case model.page of
|
||||
TerminalPage terminal ->
|
||||
toTerminal model (Terminal.update terminalMsg terminal)
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
GotStaticMsg staticMsg ->
|
||||
case model.page of
|
||||
StaticPage static ->
|
||||
toStatic model (Static.update staticMsg static)
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
ChangeUrl url ->
|
||||
updateUrl { model | url = url }
|
||||
|
||||
ClickedLink urlRequest ->
|
||||
case urlRequest of
|
||||
Browser.Internal href ->
|
||||
( model, Nav.pushUrl model.key (Url.toString href) )
|
||||
|
||||
Browser.External url ->
|
||||
( model, Nav.load url )
|
||||
|
||||
|
||||
toSplash : Model -> ( Splash.Model, Cmd Splash.Msg ) -> ( Model, Cmd Msg )
|
||||
toSplash model ( splashModel, cmd ) =
|
||||
( { model | page = SplashPage splashModel }, Cmd.map GotSplashMsg cmd )
|
||||
|
||||
|
||||
toBlog : Model -> ( Blog.Model, Cmd Blog.Msg ) -> ( Model, Cmd Msg )
|
||||
toBlog model ( blogModel, cmd ) =
|
||||
( { model | page = BlogPage blogModel }, Cmd.map GotBlogMsg cmd )
|
||||
|
||||
|
||||
toTerminal : Model -> ( Terminal.Model, Cmd Terminal.Msg ) -> ( Model, Cmd Msg )
|
||||
toTerminal model ( terminalModel, cmd ) =
|
||||
( { model | page = TerminalPage terminalModel }, Cmd.map GotTerminalMsg cmd )
|
||||
|
||||
|
||||
toStatic : Model -> ( Static.Model, Cmd Static.Msg ) -> ( Model, Cmd Msg )
|
||||
toStatic model ( staticModel, cmd ) =
|
||||
( { model | page = StaticPage staticModel }, Cmd.map GotStaticMsg cmd )
|
||||
|
||||
|
||||
init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init _ url key =
|
||||
updateUrl { url = url, page = NotFound, title = "404", key = key }
|
||||
|
||||
|
||||
|
||||
-- PARSER
|
||||
|
||||
|
||||
type Route
|
||||
= Splash
|
||||
| Blog
|
||||
| Terminal
|
||||
| Static
|
||||
|
||||
|
||||
parser : Parser (Route -> a) a
|
||||
parser =
|
||||
Parser.oneOf
|
||||
[ Parser.map Splash Parser.top
|
||||
, Parser.map Splash (s urlPrefix)
|
||||
, Parser.map Blog (s urlPrefix </> s "posts")
|
||||
, Parser.map Static (s "pages")
|
||||
, Parser.map Terminal (s "terminal")
|
||||
]
|
||||
|
||||
|
||||
updateUrl : Model -> ( Model, Cmd Msg )
|
||||
updateUrl model =
|
||||
case Parser.parse parser model.url of
|
||||
Just Splash ->
|
||||
Splash.init ()
|
||||
|> toSplash model
|
||||
|
||||
Just Blog ->
|
||||
Blog.init ()
|
||||
|> toBlog model
|
||||
|
||||
Just Terminal ->
|
||||
Terminal.init ()
|
||||
|> toTerminal model
|
||||
|
||||
Just Static ->
|
||||
Static.init ()
|
||||
|> toStatic model
|
||||
|
||||
Nothing ->
|
||||
( { model | page = NotFound }, Cmd.none )
|
||||
|
||||
|
||||
|
||||
-- ENTRYPOINT
|
||||
|
||||
|
||||
main : Program () Model Msg
|
||||
main =
|
||||
Browser.application
|
||||
{ init = init
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = \_ -> Sub.none
|
||||
, onUrlChange = ChangeUrl
|
||||
, onUrlRequest = ClickedLink
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- URLPREFIX
|
||||
|
||||
|
||||
urlPrefix : String
|
||||
urlPrefix =
|
||||
"website"
|
||||
@@ -0,0 +1,50 @@
|
||||
module Splash exposing (..)
|
||||
|
||||
import Html exposing (Html, div, img, p, text)
|
||||
import Html.Attributes exposing (alt, class, height, src, width)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ urls : List String
|
||||
, support_message : String
|
||||
, error_message : String
|
||||
}
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
view model =
|
||||
div [ class "foo-content" ]
|
||||
[ div [ class "foo-error" ]
|
||||
[ img
|
||||
[ class "foo-error__logo"
|
||||
, src "public/logo-loading.svg"
|
||||
, alt "Finding the SpaceTime"
|
||||
, width 130
|
||||
, height 130
|
||||
]
|
||||
[]
|
||||
, p [ class "foo-support__message" ] [ text model.support_message ]
|
||||
, p [ class "foo-error__message" ] [ text model.error_message ]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
type Msg
|
||||
= Nothing
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( { urls = []
|
||||
, support_message = "We are looking for the SpaceTime"
|
||||
, error_message = "We are sorry, but we can't find the SpaceTime"
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
module Static exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ title : String
|
||||
, url : String
|
||||
}
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ h1 [] [ text model.title ]
|
||||
, a [ href model.url ] [ text model.url ]
|
||||
]
|
||||
|
||||
|
||||
type Msg
|
||||
= NoOp
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
NoOp ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( Model "Hello World" "http://elm-lang.org"
|
||||
, Cmd.none
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
module Terminal exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ title : String
|
||||
, url : String
|
||||
}
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ h1 [] [ text model.title ]
|
||||
, input [ placeholder "Enter URL", onInput UrlEntered ] []
|
||||
, button [ onClick Go ] [ text "Go" ]
|
||||
, a [ href model.url ] [ text model.url ]
|
||||
]
|
||||
|
||||
|
||||
type Msg
|
||||
= UrlEntered String
|
||||
| Go
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
UrlEntered url ->
|
||||
( { model | url = url }, Cmd.none )
|
||||
|
||||
Go ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( Model "Terminal" "", Cmd.none )
|
||||
Reference in New Issue
Block a user