Add plausible

This commit is contained in:
Donovan Daniels 2024-07-14 13:48:12 -05:00
parent f47b32c5bc
commit 671162f6a2
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
13 changed files with 69 additions and 16 deletions

View File

@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
before_action :initialize_session
before_action :normalize_search
before_action :set_common_headers
helper_method :site_domain, :assets_path, :safe_site_name, :site_title, :site_color, :controller_param, :action_param, :body_class, :stimulus_class
helper_method :plausible_domain, :site_domain, :assets_path, :safe_site_name, :site_title, :site_color, :controller_param, :action_param, :body_class, :stimulus_class
skip_before_action :verify_authenticity_token
rescue_from Exception, with: :rescue_exception
@ -29,6 +29,10 @@ class ApplicationController < ActionController::Base
CurrentUser.ip_addr = request.remote_ip
end
def plausible_domain
nil
end
def site_domain
"unknown"
end

View File

@ -6,6 +6,10 @@ module ButtsAreCool
ButtsAreCoolRoutes::DOMAIN
end
def plausible_domain
"butts-are.cool"
end
def site_title
"Butts Are Cool"
end

View File

@ -6,6 +6,10 @@ module E621Ws
E621WsRoutes::DOMAIN
end
def plausible_domain
"e621.ws"
end
def assets_path
E621WsRoutes::DOMAIN
end

View File

@ -6,6 +6,10 @@ module FurryCool
FurryCoolRoutes::DOMAIN
end
def plausible_domain
"furry.cool"
end
def site_title
"Donovan_DMC"
end

View File

@ -6,6 +6,10 @@ module MaidboyeCafe
MaidboyeCafeRoutes::DOMAIN
end
def plausible_domain
"maidboye.cafe"
end
def site_title
"Maid Boye"
end

View File

@ -6,6 +6,10 @@ module OceanicWs
OceanicWsRoutes::DOMAIN
end
def plausible_domain
"oceanic.ws"
end
def site_title
"Oceanic"
end

View File

@ -6,6 +6,10 @@ module YiffMedia
YiffMediaRoutes::DOMAIN
end
def plausible_domain
"yiff.media"
end
def site_title
"YiffyAPI"
end

View File

@ -12,6 +12,10 @@ module YiffRest
YiffRestRoutes::DOMAIN
end
def plausible_domain
"yiff.rest"
end
def site_title
"YiffyAPI"
end

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
module YiffRocks
class ApplicationController < YiffRest::ApplicationController
def site_domain
YiffRocksRoutes::DOMAIN
end
def plausible_domain
"yiff.rocks"
end
def site_title
"Yiff Rocks - URL Shortener"
end
def assets_path
YiffMediaRoutes::DOMAIN
end
end
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
module YiffRocks
class HomeController < YiffRest::ApplicationController
class HomeController < ApplicationController
include ::ApplicationController::ReadonlyMethods
before_action :handle_ratelimit, only: %i[create update destroy]
before_action :validate_api_key_required, only: %i[create update destroy]
@ -61,18 +61,6 @@ module YiffRocks
private
def site_domain
YiffRocksRoutes::DOMAIN
end
def site_title
"Yiff Rocks - URL Shortener"
end
def assets_path
YiffMediaRoutes::DOMAIN
end
def short_url_params(context = nil)
permitted_params = %i[url credit creator_name]
permitted_params += %i[code] if context == :create

View File

@ -1,6 +1,6 @@
interface Window {
Stimulus: import("@hotwired/stimulus").Application
Stimulus: import("@hotwired/stimulus").Application;
jQuery: JQueryStatic;
$: JQueryStatic;
}

View File

@ -7,6 +7,9 @@
<meta charset="utf-8">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<% if Websites.config.enable_analytics && plausible_domain.present? %>
<%= Websites.config.plausible_script(plausible_domain).html_safe %>
<% end %>
<% if content_for(:html_head) %>
<%= yield :html_head %>
<% end %>

View File

@ -199,7 +199,8 @@ module Websites
].join("; "),
"Content-Security-Policy": [
"default-src 'self' #{domain} *.#{domain}",
"script-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://static.cloudflareinsights.com",
"script-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://static.cloudflareinsights.com https://plausible.furry.computer",
"connect-src 'self' https://plausible.furry.computer",
"style-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://fonts.googleapis.com",
"img-src 'self' https: data:",
"font-src 'self' https: data:",
@ -267,6 +268,14 @@ module Websites
def exceptions_domain
end
def enable_analytics
Rails.env.production?
end
def plausible_script(domain)
%(<script defer data-domain="#{domain}" src="https://plausible.furry.computer/js/script.js"></script>)
end
end
class EnvironmentConfiguration