From e7ec361dc06db48540938665351f01bdbdbe6bdd Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 25 Feb 2024 08:55:47 +1100 Subject: [PATCH] Specific decoration for statuses on index page --- slices/main/decorators/statuses/decorator.rb | 22 +++++++++++++++++++ .../main/templates/shared/_status.html.slim | 2 +- slices/main/views/statuses/index.rb | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 slices/main/decorators/statuses/decorator.rb diff --git a/slices/main/decorators/statuses/decorator.rb b/slices/main/decorators/statuses/decorator.rb new file mode 100644 index 0000000..91155e7 --- /dev/null +++ b/slices/main/decorators/statuses/decorator.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: false + +# auto_register: false + +require "rexml/parsers/pullparser" +require "sanitize" +require "nokogiri" + +module Main + module Decorators + module Statuses + class Decorator < Main::Decorators::Posts::Decorator + def raw_content + Sanitize.fragment(content, + elements: ["img", "p"], + attributes: {"img" => ["alt", "src", "title"]} + ) + end + end + end + end +end diff --git a/slices/main/templates/shared/_status.html.slim b/slices/main/templates/shared/_status.html.slim index e0767ae..8cdc566 100644 --- a/slices/main/templates/shared/_status.html.slim +++ b/slices/main/templates/shared/_status.html.slim @@ -1,7 +1,7 @@ div class="mb-8 h-entry border border-gray-200 m-2 p-4 bg-gray-50 hover:bg-gray-100 dark:border-slate-800 dark:bg-slate-900 dark:hover:bg-slate-950 hover:dark:border-slate-900 rounded" a class="border-b-2 border-transparent hover:border-blue-600 hover:border-b-2" href="/post/#{post.slug}" div class="e-content prose-p:mb-0 prose-img:my-2 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200 prose-a:dark:text-gray-100 mb-4 prose-img:rounded" - == " 💬 #{post.content}" + == " 💬 #{post.raw_content}" div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1" -post.photos.each do |photo| img class="w-32 h-32 object-cover rounded" src=photo["value"] diff --git a/slices/main/views/statuses/index.rb b/slices/main/views/statuses/index.rb index fc7d879..1874d9b 100644 --- a/slices/main/views/statuses/index.rb +++ b/slices/main/views/statuses/index.rb @@ -6,7 +6,7 @@ module Main expose :posts do post_repo.statuses_listing.map do |post| - Decorators::Posts::Decorator.new(post) + Decorators::Statuses::Decorator.new(post) end end end