Skip to content

Commit

Permalink
Feat/blog post markdown html (#236)
Browse files Browse the repository at this point in the history
* feat: added earmark

* feat: added redirect if post not exist

* feat: added noticia style

* sanitize input html

dessa forma n é possível fazer ataques de XSS ou injetar código HTML/JS malicioso

---------

Co-authored-by: zoeyrinha <[email protected]>
  • Loading branch information
SoraAsc and zoedsoupe committed Dec 3, 2024
1 parent 9588dae commit 2f4fc27
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
75 changes: 75 additions & 0 deletions assets/css/noticias.scss
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,78 @@
margin-top: 20px;
}
}

.noticia {
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 220px;
}

.noticia h1 {
margin-bottom: 30px;
line-height: 46px;
font-weight: 700;
}

.noticia .noticia-descricao h2 {
color: #0064C8;
font-size: 32px;
line-height: 38px;
font-weight: 700;
margin-top: 60px;
margin-bottom: 30px;
}

.noticia .noticia-descricao h3 {
font-size: 24px;
line-height: 28px;
font-weight: 700;
color: #404040;
margin-bottom: 30px;
}

.noticia .noticia-descricao strong em {
text-decoration: underline;
color: #0064C8;
font-weight: 400;
font-style: normal;
}

.noticia .noticia-descricao p {
font-size: 16px;
color: #404040;
margin-bottom: 40px;
}


.noticia .noticia-descricao p a {
font-weight: 700;
line-height: 24px;
color: #0064C8;
}

.noticia .noticia-descricao p a::after {
content: "";
display: inline-block;
color: inherit;
font-size: 0.8em;
position: relative;
transform: rotate(-45deg);
bottom: 2px;
}

.noticia .noticia-descricao p a:hover {
text-decoration-line: underline;
}

.noticia .noticia-descricao img {
width: 100%;
border-radius: 16px;
}

@media (max-width: 768px) {
.noticia {
padding: 40px;
}
}
30 changes: 30 additions & 0 deletions lib/pescarte_web/live/blog/post_live/show.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule PescarteWeb.Blog.PostLive.Show do
use PescarteWeb, :live_view

alias Pescarte.Blog.Post
alias PescarteWeb.Markdown

@impl true
def mount(%{"id" => id}, _session, socket) do
case Post.get_post(id) do
{:ok, post} -> {:ok, assign(socket, post: post)}
_ -> {:ok, push_navigate(socket, to: "/noticias")}
end
end

@impl true
def render(assigns) do
~H"""
<div class="noticia">
<h1 class="text-4xl leading-10 font-bold text-blue-100"><%= @post.titulo %></h1>
<div class="noticia-descricao"><%= raw(Markdown.to_html(@post.conteudo)) %></div>
<DesignSystem.link href="/noticias" class="text-sm font-semibold">
<.button style="primary">
<Lucideicons.arrow_left class="text-white-100" /> Voltar para Notícias
</.button>
</DesignSystem.link>
</div>
<PescarteWeb.DesignSystem.GetInTouch.render />
"""
end
end
11 changes: 11 additions & 0 deletions lib/pescarte_web/markdown/markdown.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule PescarteWeb.Markdown do
@moduledoc """
Módulo responsável por converter markdown para HTML.
"""

alias Earmark

def to_html(markdown) do
Earmark.as_html!(markdown, escape: true)
end
end
1 change: 1 addition & 0 deletions lib/pescarte_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ defmodule PescarteWeb.Router do
get "/noti7", Noti7Controller, :show
get "/noti8", Noti8Controller, :show
get "/noti9", Noti9Controller, :show
live "/:id", Blog.PostLive.Show
end

scope "/publicacoes" do
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ defmodule Pescarte.MixProject do
{:dialyxir, "~> 1.3", only: [:dev], runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
# {:ex_doc, "> 0.0.0", only: [:dev, :test], runtime: false},
{:git_hooks, "~> 0.8.0-pre0", only: [:dev], runtime: false}
{:git_hooks, "~> 0.8.0-pre0", only: [:dev], runtime: false},
{:earmark, "~> 1.4"}
]
end

Expand Down

0 comments on commit 2f4fc27

Please sign in to comment.