mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-06 22:02:12 +00:00
first commit
This commit is contained in:
parent
b42b49f984
commit
29ba2fe436
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ::DiscourseRewind
|
||||
class RewindsAssetsController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
skip_before_action :preload_json, :check_xhr, only: %i[show]
|
||||
skip_before_action :verify_authenticity_token, only: %i[show]
|
||||
|
||||
def show
|
||||
no_cookies
|
||||
|
||||
name = params[:name]
|
||||
path, content_type =
|
||||
if name == "rewind"
|
||||
%w[rewind.css text/css]
|
||||
else
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
content = File.read(DiscourseRewind.public_asset_path("css/#{path}"))
|
||||
|
||||
# note, path contains a ":version" which automatically busts the cache
|
||||
# based on file content, so this is safe
|
||||
response.headers["Last-Modified"] = 10.years.ago.httpdate
|
||||
response.headers["Content-Length"] = content.bytesize.to_s
|
||||
immutable_for 1.year
|
||||
|
||||
render plain: content, disposition: :nil, content_type: content_type
|
||||
end
|
||||
end
|
||||
end
|
16
app/controllers/discourse_rewind/rewinds_controller.rb
Normal file
16
app/controllers/discourse_rewind/rewinds_controller.rb
Normal file
@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ::DiscourseRewind
|
||||
class RewindsController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: %i[show]
|
||||
|
||||
def show
|
||||
# expires_in 1.minute, public: true
|
||||
response.headers["X-Robots-Tag"] = "noindex"
|
||||
|
||||
render "show", layout: false
|
||||
end
|
||||
end
|
||||
end
|
@ -1,11 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ::MyPluginModule
|
||||
class ExamplesController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
def index
|
||||
render json: { hello: "world" }
|
||||
end
|
||||
end
|
||||
end
|
30
app/helpers/discourse_rewind/rewinds_helper.rb
Normal file
30
app/helpers/discourse_rewind/rewinds_helper.rb
Normal file
@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
module DiscourseRewind
|
||||
module RewindsHelper
|
||||
# keeping it here for caching
|
||||
def self.rewind_asset_url(asset_name)
|
||||
if !%w[rewind.css].include?(asset_name)
|
||||
raise StandardError, "unknown asset type #{asset_name}"
|
||||
end
|
||||
|
||||
@urls ||= {}
|
||||
url = @urls[asset_name]
|
||||
p "-------------"
|
||||
# return url if url
|
||||
|
||||
content = File.read(DiscourseRewind.public_asset_path("css/#{asset_name}"))
|
||||
|
||||
p content
|
||||
sha1 = Digest::SHA1.hexdigest(content)
|
||||
|
||||
url = "/rewinds/assets/#{sha1}/#{asset_name}"
|
||||
|
||||
p @urls[asset_name] = GlobalPath.cdn_path(url)
|
||||
end
|
||||
|
||||
def rewind_asset_url(asset_name)
|
||||
DiscourseRewind::RewindsHelper.rewind_asset_url(asset_name)
|
||||
end
|
||||
end
|
||||
end
|
18
app/views/discourse_rewind/rewinds/show.html.erb
Normal file
18
app/views/discourse_rewind/rewinds/show.html.erb
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= I18n.t("discourse_rewind.title", title: "RETRO TITLE", site_name: SiteSetting.title) %></title>
|
||||
<meta property="og:title" content="<%= I18n.t("discourse_rewind.title", title: "RETRO TITLE", site_name: SiteSetting.title) %>">
|
||||
<meta property="og:description" content="DESC">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="<%= request.original_url %>">
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:title" content="<%= I18n.t("discourse_rewind.title", title: "RETRO TITLE", site_name: SiteSetting.title) %>">
|
||||
<meta name="twitter:description" content="DESC">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="stylesheet" href="<%= rewind_asset_url("rewind.css") %>">
|
||||
</head>
|
||||
<body>
|
||||
TEST
|
||||
</body>
|
||||
</html>
|
@ -3,7 +3,7 @@ en:
|
||||
admin:
|
||||
site_settings:
|
||||
categories:
|
||||
TODO_plugin_name: "Plugin Name"
|
||||
discourse_rewind: "Discourse Rewind"
|
||||
js:
|
||||
discourse_plugin_name:
|
||||
placeholder: placeholder
|
||||
discourse_rewind:
|
||||
placeholder: Discourse Rewind
|
||||
|
@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
MyPluginModule::Engine.routes.draw do
|
||||
get "/examples" => "examples#index"
|
||||
# define routes here
|
||||
DiscourseRewind::Engine.routes.draw do
|
||||
get "/rewinds/:year/:username" => "rewinds#show"
|
||||
get "/rewinds/assets/:version/:name" => "rewinds_assets#show"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.draw { mount ::MyPluginModule::Engine, at: "my-plugin" }
|
||||
Discourse::Application.routes.draw { mount ::DiscourseRewind::Engine, at: "/" }
|
||||
|
@ -1,4 +1,4 @@
|
||||
TODO_plugin_name:
|
||||
plugin_name_enabled:
|
||||
discourse_rewind:
|
||||
discourse_rewind_enabled:
|
||||
default: false
|
||||
client: true
|
||||
|
@ -1,9 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ::MyPluginModule
|
||||
module ::DiscourseRewind
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name PLUGIN_NAME
|
||||
isolate_namespace MyPluginModule
|
||||
isolate_namespace DiscourseRewind
|
||||
config.autoload_paths << File.join(config.root, "lib")
|
||||
scheduled_job_dir = "#{config.root}/app/jobs/scheduled"
|
||||
config.to_prepare do
|
18
plugin.rb
18
plugin.rb
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# name: discourse-plugin-name
|
||||
# name: discourse-rewind
|
||||
# about: TODO
|
||||
# meta_topic_id: TODO
|
||||
# version: 0.0.1
|
||||
@ -8,14 +8,16 @@
|
||||
# url: TODO
|
||||
# required_version: 2.7.0
|
||||
|
||||
enabled_site_setting :plugin_name_enabled
|
||||
enabled_site_setting :discourse_rewind_enabled
|
||||
|
||||
module ::MyPluginModule
|
||||
PLUGIN_NAME = "discourse-plugin-name"
|
||||
module ::DiscourseRewind
|
||||
PLUGIN_NAME = "discourse-rewind"
|
||||
|
||||
def self.public_asset_path(name)
|
||||
File.expand_path(File.join(__dir__, "public", name))
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "lib/my_plugin_module/engine"
|
||||
require_relative "lib/discourse_rewind/engine"
|
||||
|
||||
after_initialize do
|
||||
# Code which should run after Rails has finished booting
|
||||
end
|
||||
after_initialize {}
|
||||
|
3
public/css/rewind.css
Normal file
3
public/css/rewind.css
Normal file
@ -0,0 +1,3 @@
|
||||
body {
|
||||
background: #444;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user