Browse Source

Add panel configuration and make page more flexible

master
Sean King 1 month ago
parent
commit
f982b6091d
Signed by: seanking GPG Key ID: 778810DE76B9460F
10 changed files with 142 additions and 7 deletions
  1. +8
    -0
      assets/css/tabs.scss
  2. +20
    -2
      config/config.exs
  3. +50
    -0
      lib/fuck_gab/scrubber.ex
  4. +2
    -1
      lib/fuck_gab_web/controllers/page_controller.ex
  5. +14
    -3
      lib/fuck_gab_web/templates/page/index.html.eex
  6. +10
    -0
      lib/fuck_gab_web/templates/panel/panel.html.eex
  7. +3
    -0
      lib/fuck_gab_web/views/panel_view.ex
  8. +2
    -1
      mix.exs
  9. +4
    -0
      mix.lock
  10. +29
    -0
      test/fuck_gab/scrubber_test.exs

+ 8
- 0
assets/css/tabs.scss View File

@ -40,6 +40,14 @@
p {
margin-bottom: 1rem;
}
ul {
list-style: disc inside;
}
li {
margin-bottom: 0.5rem;
}
}
.tab-item {

+ 20
- 2
config/config.exs View File

@ -9,10 +9,12 @@ use Mix.Config
config :fuck_gab, :site,
name: "Fuck Gab!",
description:
"You may be here because you're sick of Gab's shit. Well, no worries. You're not the only one.
description: %{
content: "You may be here because you're sick of Gab's shit. Well, no worries. You're not the only one.
And there are plenty of alternatives to Gab out there because there's this amazing thing called the fediverse.
Here's a list of some alternatives on the fediverse that you can try out.",
display: true
},
brand_color: "ce2121",
footer_nav_items: [
%{
@ -31,6 +33,22 @@ config :fuck_gab, :site,
"Have an instance you would like to add to this list? Feel free to suggest it below. All we ask
is that the instance does not actively encourage or allow activity and content illegal in the United States
to occur."
},
panels: %{
above_suggestion_form: [
%{
title: "Want to start your own instance instead?",
content: """
<p>Check out some of this documentation to help you get started:</p>
<ul>
<li><a href="https://docs.pleroma.social/backend/installation/debian_based_en">How to install Pleroma on a Debian/Ubuntu server</a></li>
<li><a href="https://docs.soapbox.pub/frontend/installing/">How to install the Soapbox frontend for Pleroma</a></li>
<li><a href="https://docs.joinmastodon.org/admin/install/">How to install Mastodon</a></li>
<li><a href="https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md">How to install and setup Misskey</a></li>
</ul>
"""
}
]
}
config :fuck_gab,

+ 50
- 0
lib/fuck_gab/scrubber.ex View File

@ -0,0 +1,50 @@
defmodule FuckGab.Scrubber do
@moduledoc """
Sanitizes panel content for display.
"""
require FastSanitize.Sanitizer.Meta
alias FastSanitize.Sanitizer.Meta
Meta.strip_comments()
Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], ["http", "https"])
Meta.allow_tag_with_this_attribute_values(:a, "class", [
"hashtag",
"u-url",
"mention",
"u-url mention",
"mention u-url"
])
Meta.allow_tag_with_this_attribute_values(:a, "rel", [
"tag",
"nofollow",
"noopener",
"noreferrer",
"ugc"
])
Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
Meta.allow_tag_with_these_attributes(:abbr, ["title"])
Meta.allow_tag_with_these_attributes(:b, [])
Meta.allow_tag_with_these_attributes(:blockquote, [])
Meta.allow_tag_with_these_attributes(:br, [])
Meta.allow_tag_with_these_attributes(:code, [])
Meta.allow_tag_with_these_attributes(:del, [])
Meta.allow_tag_with_these_attributes(:em, [])
Meta.allow_tag_with_these_attributes(:i, [])
Meta.allow_tag_with_these_attributes(:li, [])
Meta.allow_tag_with_these_attributes(:ol, [])
Meta.allow_tag_with_these_attributes(:p, [])
Meta.allow_tag_with_these_attributes(:pre, [])
Meta.allow_tag_with_these_attributes(:strong, [])
Meta.allow_tag_with_these_attributes(:sub, [])
Meta.allow_tag_with_these_attributes(:sup, [])
Meta.allow_tag_with_these_attributes(:u, [])
Meta.allow_tag_with_these_attributes(:ul, [])
Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
Meta.allow_tag_with_these_attributes(:span, [])
Meta.strip_everything_not_covered()
end

+ 2
- 1
lib/fuck_gab_web/controllers/page_controller.ex View File

@ -10,7 +10,8 @@ defmodule FuckGabWeb.PageController do
site_description: FuckGab.Config.get([:site, :description]),
brand_color: Chameleon.convert(brand_color_config, Chameleon.HSL),
site_footer_nav_items: FuckGab.Config.get([:site, :footer_nav_items]),
copyright: FuckGab.Config.get([:site, :copyright])
copyright: FuckGab.Config.get([:site, :copyright]),
panels: FuckGab.Config.get([:site, :panels])
}
render(conn, "index.html", assigns)

+ 14
- 3
lib/fuck_gab_web/templates/page/index.html.eex View File

@ -1,5 +1,16 @@
<section class="home-page__top">
<p class="description"><%= @site_description %></p>
</section>
<%= if @site_description.display == true do %>
<section class="home-page__top">
<p class="description"><%= @site_description.content %></p>
</section>
<% end %>
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:above_explore] do
render_many panels, FuckGabWeb.PanelView, "panel.html"
end %>
<%= live_render(@conn, FuckGabWeb.DirectoryLive) %>
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:above_suggestion_form] do
render_many panels, FuckGabWeb.PanelView, "panel.html"
end %>
<%= live_render(@conn, FuckGabWeb.SuggestionForm) %>
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:below_suggestion_form] do
render_many panels, FuckGabWeb.PanelView, "panel.html"
end %>

+ 10
- 0
lib/fuck_gab_web/templates/panel/panel.html.eex View File

@ -0,0 +1,10 @@
<section class="tab">
<div class="tab-header">
<h3 class="tab-title"><%= @panel.title %></h3>
</div>
<div class="tab-content">
<%= with {:ok, content} <- FastSanitize.Sanitizer.scrub(@panel.content, FuckGab.Scrubber) do
raw(content)
end %>
</div>
</section>

+ 3
- 0
lib/fuck_gab_web/views/panel_view.ex View File

@ -0,0 +1,3 @@
defmodule FuckGabWeb.PanelView do
use FuckGabWeb, :view
end

+ 2
- 1
mix.exs View File

@ -69,7 +69,8 @@ defmodule FuckGab.MixProject do
git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
{:calendar, "~> 1.0"},
{:plug_crypto, "~> 1.2"}
{:plug_crypto, "~> 1.2"},
{:fast_sanitize, "~> 0.2.2"}
]
end

+ 4
- 0
mix.lock View File

@ -15,9 +15,12 @@
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"ecto": {:hex, :ecto, "3.5.5", "48219a991bb86daba6e38a1e64f8cea540cded58950ff38fbc8163e062281a07", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98dd0e5e1de7f45beca6130d13116eae675db59adfa055fb79612406acf6f6f1"},
"ecto_sql": {:hex, :ecto_sql, "3.5.3", "1964df0305538364b97cc4661a2bd2b6c89d803e66e5655e4e55ff1571943efd", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d2f53592432ce17d3978feb8f43e8dc0705e288b0890caf06d449785f018061c"},
"elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"},
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
"ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"},
"excoveralls": {:hex, :excoveralls, "0.13.3", "edc5f69218f84c2bf61b3609a22ddf1cec0fbf7d1ba79e59f4c16d42ea4347ed", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cc26f48d2f68666380b83d8aafda0fffc65dafcc8d8650358e0b61f6a99b1154"},
"fast_html": {:hex, :fast_html, "2.0.4", "4910ee49f2f6b19692e3bf30bf97f1b6b7dac489cd6b0f34cd0fe3042c56ba30", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}], "hexpm", "3bb49d541dfc02ad5e425904f53376d758c09f89e521afc7d2b174b3227761ea"},
"fast_sanitize": {:hex, :fast_sanitize, "0.2.2", "3cbbaebaea6043865dfb5b4ecb0f1af066ad410a51470e353714b10c42007b81", [:mix], [{:fast_html, "~> 2.0", [hex: :fast_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.8", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "69f204db9250afa94a0d559d9110139850f57de2b081719fbafa1e9a89e94466"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"flake_id": {:hex, :flake_id, "0.1.0", "7716b086d2e405d09b647121a166498a0d93d1a623bead243e1f74216079ccb3", [:mix], [{:base62, "~> 1.2", [hex: :base62, repo: "hexpm", optional: false]}, {:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "31fc8090fde1acd267c07c36ea7365b8604055f897d3a53dd967658c691bd827"},
"floki": {:hex, :floki, "0.29.0", "b1710d8c93a2f860dc2d7adc390dd808dc2fb8f78ee562304457b75f4c640881", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "008585ce64b9f74c07d32958ec9866f4b8a124bf4da1e2941b28e41384edaaad"},
@ -33,6 +36,7 @@
"mime": {:hex, :mime, "1.4.0", "5066f14944b470286146047d2f73518cf5cca82f8e4815cf35d196b58cf07c47", [:mix], [], "hexpm", "75fa42c4228ea9a23f70f123c74ba7cece6a03b1fd474fe13f6a7a85c6ea4ff6"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"nimble_pool": {:hex, :nimble_pool, "0.1.0", "ffa9d5be27eee2b00b0c634eb649aa27f97b39186fec3c493716c2a33e784ec6", [:mix], [], "hexpm", "343a1eaa620ddcf3430a83f39f2af499fe2370390d4f785cd475b4df5acaf3f9"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"phoenix": {:hex, :phoenix, "1.5.7", "2923bb3af924f184459fe4fa4b100bd25fa6468e69b2803dfae82698269aa5e0", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "774cd64417c5a3788414fdbb2be2eb9bcd0c048d9e6ad11a0c1fd67b7c0d0978"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.2.1", "13f124cf0a3ce0f1948cf24654c7b9f2347169ff75c1123f44674afee6af3b03", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "478a1bae899cac0a6e02be1deec7e2944b7754c04e7d4107fc5a517f877743c0"},

+ 29
- 0
test/fuck_gab/scrubber_test.exs View File

@ -0,0 +1,29 @@
defmodule FuckGab.ScrubberTest do
use FuckGab.DataCase
describe "Scraper" do
test "make sure HTML Scrubber works properly" do
expected = """
<b>bold up</b>
<p>paragraphics</p>
break down<br/>
<span>spannity span, wonderful spaaan</span>
<ul><li>Unordered list stuff</li></ul>
<ol><li>ORDER! ORDER!</li></ol>
<blockquote>Blocked by the quotes</blockquote>
<abbr title="This is Sparta">Welcome to Sparta</abbr>
<code>Oh, hi! I&#39;m Cody!</code>
<del>DELET THIS!</del>
<em>Emerald</em>
<i>Mama-mia!</i>
<pre>Prepare</pre>
<strong>STRUNGGG MAN!</strong>
<sub>Subway in New York</sub>
<sup>Sup bitches!</sup>
<u>Why r u gae?</u>
"""
assert {:ok, expected} == FastSanitize.Sanitizer.scrub(expected, FuckGab.Scrubber)
end
end
end

Loading…
Cancel
Save