diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1a40f5e..edd0fbe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/butts_are_cool/application_controller.rb b/app/controllers/butts_are_cool/application_controller.rb index 2d666fd..af5e1e3 100644 --- a/app/controllers/butts_are_cool/application_controller.rb +++ b/app/controllers/butts_are_cool/application_controller.rb @@ -6,6 +6,10 @@ module ButtsAreCool ButtsAreCoolRoutes::DOMAIN end + def plausible_domain + "butts-are.cool" + end + def site_title "Butts Are Cool" end diff --git a/app/controllers/e621_ws/application_controller.rb b/app/controllers/e621_ws/application_controller.rb index 9946c35..e84bf08 100644 --- a/app/controllers/e621_ws/application_controller.rb +++ b/app/controllers/e621_ws/application_controller.rb @@ -6,6 +6,10 @@ module E621Ws E621WsRoutes::DOMAIN end + def plausible_domain + "e621.ws" + end + def assets_path E621WsRoutes::DOMAIN end diff --git a/app/controllers/furry_cool/application_controller.rb b/app/controllers/furry_cool/application_controller.rb index 2c42476..58cf7e7 100644 --- a/app/controllers/furry_cool/application_controller.rb +++ b/app/controllers/furry_cool/application_controller.rb @@ -6,6 +6,10 @@ module FurryCool FurryCoolRoutes::DOMAIN end + def plausible_domain + "furry.cool" + end + def site_title "Donovan_DMC" end diff --git a/app/controllers/maidboye_cafe/application_controller.rb b/app/controllers/maidboye_cafe/application_controller.rb index 54ec728..b83749f 100644 --- a/app/controllers/maidboye_cafe/application_controller.rb +++ b/app/controllers/maidboye_cafe/application_controller.rb @@ -6,6 +6,10 @@ module MaidboyeCafe MaidboyeCafeRoutes::DOMAIN end + def plausible_domain + "maidboye.cafe" + end + def site_title "Maid Boye" end diff --git a/app/controllers/oceanic_ws/application_controller.rb b/app/controllers/oceanic_ws/application_controller.rb index 44a8e7d..30c2ec3 100644 --- a/app/controllers/oceanic_ws/application_controller.rb +++ b/app/controllers/oceanic_ws/application_controller.rb @@ -6,6 +6,10 @@ module OceanicWs OceanicWsRoutes::DOMAIN end + def plausible_domain + "oceanic.ws" + end + def site_title "Oceanic" end diff --git a/app/controllers/yiff_media/application_controller.rb b/app/controllers/yiff_media/application_controller.rb index 9b872e7..501124c 100644 --- a/app/controllers/yiff_media/application_controller.rb +++ b/app/controllers/yiff_media/application_controller.rb @@ -6,6 +6,10 @@ module YiffMedia YiffMediaRoutes::DOMAIN end + def plausible_domain + "yiff.media" + end + def site_title "YiffyAPI" end diff --git a/app/controllers/yiff_rest/application_controller.rb b/app/controllers/yiff_rest/application_controller.rb index fdd6e0b..b976d22 100644 --- a/app/controllers/yiff_rest/application_controller.rb +++ b/app/controllers/yiff_rest/application_controller.rb @@ -12,6 +12,10 @@ module YiffRest YiffRestRoutes::DOMAIN end + def plausible_domain + "yiff.rest" + end + def site_title "YiffyAPI" end diff --git a/app/controllers/yiff_rocks/application_controller.rb b/app/controllers/yiff_rocks/application_controller.rb new file mode 100644 index 0000000..9b95b98 --- /dev/null +++ b/app/controllers/yiff_rocks/application_controller.rb @@ -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 diff --git a/app/controllers/yiff_rocks/home_controller.rb b/app/controllers/yiff_rocks/home_controller.rb index 9e5002c..7583ae1 100644 --- a/app/controllers/yiff_rocks/home_controller.rb +++ b/app/controllers/yiff_rocks/home_controller.rb @@ -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 diff --git a/app/javascript/@types/global.d.ts b/app/javascript/@types/global.d.ts index 6d60ccc..5877b67 100644 --- a/app/javascript/@types/global.d.ts +++ b/app/javascript/@types/global.d.ts @@ -1,6 +1,6 @@ interface Window { - Stimulus: import("@hotwired/stimulus").Application + Stimulus: import("@hotwired/stimulus").Application; jQuery: JQueryStatic; $: JQueryStatic; } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 30934c1..5b87f89 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,9 @@ <%= 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 %> diff --git a/config/default_config.rb b/config/default_config.rb index 5c9aa45..0c419d5 100644 --- a/config/default_config.rb +++ b/config/default_config.rb @@ -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) + %() + end end class EnvironmentConfiguration