1
0
mirror of https://github.com/avinal/avinal.github.io.git synced 2026-07-04 07:40:09 +05:30

cleanup and minor fixes

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
2023-01-24 16:43:32 +05:30
parent c2adcaec6c
commit b827a4b0f9
6 changed files with 19 additions and 47 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ subscriptions model =
blogTheme : String blogTheme : String
blogTheme = blogTheme =
"mt-4 prose prose-invert mx-auto lg:prose-lg prose-a:decoration-cyan-500 hover:prose-a:decoration-pink-500" "mt-4 prose prose-invert mx-auto lg:prose-lg prose-a:decoration-cyan-500 hover:prose-a:decoration-pink-500 prose-img:float-right"
view : { fromMsg : Msg -> mainMsg, content : View mainMsg, model : Model } -> View mainMsg view : { fromMsg : Msg -> mainMsg, content : View mainMsg, model : Model } -> View mainMsg
+1 -5
View File
@@ -50,7 +50,7 @@ init () =
cmd : Cmd Msg cmd : Cmd Msg
cmd = cmd =
Http.get Http.get
{ url = "https://avinal.space/content/posts/posts.json" { url = "/content/posts/posts.json"
, expect = Http.expectJson BloglistReceived (Json.list jsonMetaDecoder) , expect = Http.expectJson BloglistReceived (Json.list jsonMetaDecoder)
} }
in in
@@ -94,10 +94,6 @@ subscriptions model =
-- VIEW -- VIEW
unsplash =
"https://source.unsplash.com/random/"
view : Model -> View Msg view : Model -> View Msg
view model = view model =
let let
+8 -13
View File
@@ -63,7 +63,6 @@ init : Route { first_ : String, rest_ : List String } -> () -> ( Model, Effect M
init route () = init route () =
let let
requestUrl = requestUrl =
-- "https://gist.githubusercontent.com/avinal/a66c60362491498d114b53e8801632d6/raw/cd2fd3816f0f005fe12ebfeead8d8b1fcaafa5db/markdowntest.md"
UU.contentUrl UU.contentUrl
{ category = route.params.first_ { category = route.params.first_
, post = , post =
@@ -80,7 +79,7 @@ init route () =
( { blog = Nothing ( { blog = Nothing
, requestUrl = requestUrl , requestUrl = requestUrl
, success = False , success = False
, fragment = "" , fragment = Maybe.withDefault "" route.hash
, error = Nothing , error = Nothing
} }
, Effect.sendCmd cmd , Effect.sendCmd cmd
@@ -93,7 +92,6 @@ init route () =
type Msg type Msg
= RawMarkdownReceived (Result Http.Error String) = RawMarkdownReceived (Result Http.Error String)
| AttributeUpdate String
update : Msg -> Model -> ( Model, Effect Msg ) update : Msg -> Model -> ( Model, Effect Msg )
@@ -110,9 +108,6 @@ update msg model =
RawMarkdownReceived (Err err) -> RawMarkdownReceived (Err err) ->
( { model | success = False, error = Just (UU.errorToString err) }, Effect.none ) ( { model | success = False, error = Just (UU.errorToString err) }, Effect.none )
AttributeUpdate data ->
( model, Effect.none )
-- SUBSCRIPTIONS -- SUBSCRIPTIONS
@@ -138,7 +133,7 @@ view model =
, src blog.meta.image , src blog.meta.image
] ]
[] []
, articleNode blog.content , articleNode blog.content model.fragment
, Html.div [ class "text-center text-neutral-300 border-t border-dashed border-teal-500 p-2" ] , Html.div [ class "text-center text-neutral-300 border-t border-dashed border-teal-500 p-2" ]
[ Html.text <| "Published on " ++ blog.meta.date ++ " under " [ Html.text <| "Published on " ++ blog.meta.date ++ " under "
, Html.a [ href "https://www.mozilla.org/en-US/MPL/2.0/" ] [ Html.text "Mozilla Public License 2.0" ] , Html.a [ href "https://www.mozilla.org/en-US/MPL/2.0/" ] [ Html.text "Mozilla Public License 2.0" ]
@@ -226,10 +221,10 @@ view model =
errorView : String -> Html msg errorView : String -> Html msg
errorView error = errorView error =
Html.div Html.div
[ class "flex items-center rounded shadow-md overflow-hidden max-w-xl relative dark:bg-neutral-900 dark:text-gray-100" [ class "flex items-center rounded shadow-md overflow-hidden max-w-xl relative bg-neutral-900 text-gray-100"
] ]
[ Html.div [ Html.div
[ class "self-stretch flex items-center px-3 flex-shrink-0 dark:bg-gray-700 dark:text-pink-500" [ class "self-stretch flex items-center px-3 flex-shrink-0 bg-gray-700 text-pink-500"
] ]
[ svg [ svg
[ SvgAttr.fill "none" [ SvgAttr.fill "none"
@@ -254,7 +249,7 @@ errorView error =
] ]
[ Html.text error ] [ Html.text error ]
, Html.p , Html.p
[ class " dark:text-gray-400" [ class " text-gray-400"
] ]
[ Html.a [ Html.a
[ href "../posts" [ href "../posts"
@@ -267,10 +262,10 @@ errorView error =
] ]
articleNode : String -> Html Msg articleNode : String -> String -> Html Msg
articleNode data = articleNode data fragment =
Html.node "rendered-md" Html.node "rendered-md"
[ Html.Attributes.attribute "markdowndata" data ] [ Html.Attributes.attribute "markdowndata" data, Html.Attributes.attribute "fragment" fragment ]
[] []
-20
View File
@@ -34,26 +34,6 @@ iconLinks =
] ]
contentBase : String
contentBase =
"https://avinal.space/"
user : String
user =
"avinal"
urlPrefix : String
urlPrefix =
"avinal.github.io"
contentUrlPrefix : String
contentUrlPrefix =
contentBase ++ "/content/"
nameMatrix : Array Int nameMatrix : Array Int
nameMatrix = nameMatrix =
Array.fromList Array.fromList
+3 -3
View File
@@ -9,12 +9,12 @@ import Utils.Constants exposing (..)
categoryNtags : String -> List String -> Html msg categoryNtags : String -> List String -> Html msg
categoryNtags category tags = categoryNtags category tags =
Html.span [ class "flex flex-wrap py-6 space-x-2 border-t border-dashed border-teal-500" ] Html.span [ class "flex flex-wrap py-6 space-x-2 border-t border-dashed border-teal-500" ]
(Html.b [ class "px-3 py-1 m-1 rounded-sm hover:underline dark:bg-pink-400 dark:text-gray-900" ] (Html.b [ class "px-3 py-1 m-1 rounded-sm hover:underline bg-pink-400 text-gray-900" ]
[ Html.text category [ Html.text category
] ]
:: List.map :: List.map
(\tag -> (\tag ->
Html.i [ class "px-3 py-1 m-1 rounded-sm hover:underline dark:bg-cyan-500 dark:text-gray-900" ] Html.i [ class "px-3 py-1 m-1 rounded-sm hover:underline bg-cyan-500 text-gray-900" ]
[ Html.text tag [ Html.text tag
] ]
) )
@@ -24,7 +24,7 @@ categoryNtags category tags =
contentUrl : { category : String, post : String } -> String contentUrl : { category : String, post : String } -> String
contentUrl { category, post } = contentUrl { category, post } =
contentUrlPrefix ++ "posts/" ++ category ++ "/" ++ post ++ ".md" "/content/posts/" ++ category ++ "/" ++ post ++ ".md"
errorToString : Http.Error -> String errorToString : Http.Error -> String
+6 -5
View File
@@ -8,12 +8,10 @@ customElements.define(
connectedCallback() { connectedCallback() {
this.runMarked(); this.runMarked();
} }
attributeChangedCallback(name, oldValue, newValue) {
this.runMarked();
}
runMarked() { runMarked() {
const renderer = new marked.Renderer(); const renderer = new marked.Renderer();
const data = this.getAttribute("markdowndata"); const data = this.getAttribute("markdowndata");
const fragment = this.getAttribute("fragment");
var lead = 0; var lead = 0;
renderer.heading = (text, level) => { renderer.heading = (text, level) => {
if (level === 1) { if (level === 1) {
@@ -51,17 +49,20 @@ customElements.define(
console.warn(`Unable to find prism highlight for '${lang}'`); console.warn(`Unable to find prism highlight for '${lang}'`);
return; return;
} }
console.info("Found", lang);
return Prism.highlight(code, grammer, lang); return Prism.highlight(code, grammer, lang);
}, },
}); });
this.innerHTML = marked.parse(data); this.innerHTML = marked.parse(data);
console.log("Markdown rendering complete!"); console.log("Markdown rendering complete!");
if (fragment) {
console.log("Fragment found, scrolling to: #", fragment);
window.location = "#" + fragment;
}
} }
static get observedAttributes() { static get observedAttributes() {
return ["markdowndata"]; return ["markdowndata", "fragment"];
} }
} }
); );