Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/blog post markdown html #236

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading