From e727dab3092f4f2bff17d8228084a812baa80163 Mon Sep 17 00:00:00 2001
From: Marcos Dias <57465032+SoraAsc@users.noreply.github.com>
Date: Sat, 2 Nov 2024 20:08:48 -0300
Subject: [PATCH 1/4] feat: added earmark
---
lib/pescarte_web/live/blog/post_live/show.ex | 22 ++++++++++++++++++++
lib/pescarte_web/markdown/markdown.ex | 11 ++++++++++
lib/pescarte_web/router.ex | 1 +
mix.exs | 3 ++-
4 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 lib/pescarte_web/live/blog/post_live/show.ex
create mode 100644 lib/pescarte_web/markdown/markdown.ex
diff --git a/lib/pescarte_web/live/blog/post_live/show.ex b/lib/pescarte_web/live/blog/post_live/show.ex
new file mode 100644
index 00000000..f66ed4f3
--- /dev/null
+++ b/lib/pescarte_web/live/blog/post_live/show.ex
@@ -0,0 +1,22 @@
+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
+ {status, post} = Post.get_post(id)
+ {:ok, assign(socket, :post, post)}
+ end
+
+ @impl true
+ def render(assigns) do
+ ~H"""
+
+
<%= @post.titulo %>
+
<%= raw(Markdown.to_html(@post.conteudo)) %>
+
+ """
+ end
+end
diff --git a/lib/pescarte_web/markdown/markdown.ex b/lib/pescarte_web/markdown/markdown.ex
new file mode 100644
index 00000000..5bc847ad
--- /dev/null
+++ b/lib/pescarte_web/markdown/markdown.ex
@@ -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)
+ end
+end
diff --git a/lib/pescarte_web/router.ex b/lib/pescarte_web/router.ex
index 9af5f9b6..40a396e4 100644
--- a/lib/pescarte_web/router.ex
+++ b/lib/pescarte_web/router.ex
@@ -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
diff --git a/mix.exs b/mix.exs
index 7a8b7042..6703ac6e 100644
--- a/mix.exs
+++ b/mix.exs
@@ -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
From 7075849e4981cc2bd95a1d1c1be7c040130b225a Mon Sep 17 00:00:00 2001
From: Marcos Dias <57465032+SoraAsc@users.noreply.github.com>
Date: Sat, 2 Nov 2024 20:27:45 -0300
Subject: [PATCH 2/4] feat: added redirect if post not exist
---
lib/pescarte_web/live/blog/post_live/show.ex | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/pescarte_web/live/blog/post_live/show.ex b/lib/pescarte_web/live/blog/post_live/show.ex
index f66ed4f3..42009c15 100644
--- a/lib/pescarte_web/live/blog/post_live/show.ex
+++ b/lib/pescarte_web/live/blog/post_live/show.ex
@@ -6,8 +6,10 @@ defmodule PescarteWeb.Blog.PostLive.Show do
@impl true
def mount(%{"id" => id}, _session, socket) do
- {status, post} = Post.get_post(id)
- {:ok, assign(socket, :post, post)}
+ case Post.get_post(id) do
+ {:ok, post} -> {:ok, assign(socket, post: post)}
+ _ -> {:ok, push_navigate(socket, to: "/noticias")}
+ end
end
@impl true
From 336094d1dd4fcaa6213c37e712fc2c0fdde13b7a Mon Sep 17 00:00:00 2001
From: Marcos Dias <57465032+SoraAsc@users.noreply.github.com>
Date: Thu, 21 Nov 2024 12:16:23 -0300
Subject: [PATCH 3/4] feat: added noticia style
---
assets/css/noticias.scss | 75 ++++++++++++++++++++
lib/pescarte_web/live/blog/post_live/show.ex | 12 +++-
2 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/assets/css/noticias.scss b/assets/css/noticias.scss
index e96b0367..b8779238 100644
--- a/assets/css/noticias.scss
+++ b/assets/css/noticias.scss
@@ -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;
+ }
+}
diff --git a/lib/pescarte_web/live/blog/post_live/show.ex b/lib/pescarte_web/live/blog/post_live/show.ex
index 42009c15..c0aaa772 100644
--- a/lib/pescarte_web/live/blog/post_live/show.ex
+++ b/lib/pescarte_web/live/blog/post_live/show.ex
@@ -15,10 +15,16 @@ defmodule PescarteWeb.Blog.PostLive.Show do
@impl true
def render(assigns) do
~H"""
-
-
<%= @post.titulo %>
-
<%= raw(Markdown.to_html(@post.conteudo)) %>
+
+
<%= @post.titulo %>
+
<%= raw(Markdown.to_html(@post.conteudo)) %>
+
+ <.button style="primary">
+ Voltar para Notícias
+
+
+
"""
end
end
From 06c445829cf88463fff905561edfac5b41c972d3 Mon Sep 17 00:00:00 2001
From: zoeyrinha
Date: Tue, 3 Dec 2024 13:58:24 -0300
Subject: [PATCH 4/4] sanitize input html
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
dessa forma n é possível fazer ataques de XSS ou injetar código HTML/JS malicioso
---
lib/pescarte_web/markdown/markdown.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/pescarte_web/markdown/markdown.ex b/lib/pescarte_web/markdown/markdown.ex
index 5bc847ad..3fd9840c 100644
--- a/lib/pescarte_web/markdown/markdown.ex
+++ b/lib/pescarte_web/markdown/markdown.ex
@@ -6,6 +6,6 @@ defmodule PescarteWeb.Markdown do
alias Earmark
def to_html(markdown) do
- Earmark.as_html!(markdown)
+ Earmark.as_html!(markdown, escape: true)
end
end