代码拉取完成,页面将自动刷新
# frozen_string_literal: true
# name: discourse-yearly-review
# about: Creates an automated Year in Review summary topic
# version: 0.2
# author: Simon Cossar
# url: https://github.com/discourse/discourse-yearly-review
enabled_site_setting :yearly_review_enabled
register_asset "stylesheets/yearly_review.scss"
after_initialize do
module ::YearlyReview
PLUGIN_NAME = "yearly-review"
POST_CUSTOM_FIELD ||= "yearly_review"
def self.current_year
Time.now.year
end
def self.last_year
current_year - 1
end
end
::ActionController::Base.prepend_view_path File.expand_path(
"../app/views/yearly-review",
__FILE__,
)
["../../discourse-yearly-review/app/jobs/yearly_review.rb"].each do |path|
load File.expand_path(path, __FILE__)
end
require_dependency "email/styles"
Email::Styles.register_plugin_style do |doc|
doc.css("[data-review-topic-users] table").each { |element| element["width"] = "100%" }
doc.css("[data-review-featured-topics] table").each { |element| element["width"] = "100%" }
doc
.css("[data-review-topic-users] th")
.each do |element|
element["style"] = "text-align: left;padding-bottom: 12px;"
element["width"] = "50%"
end
doc
.css("[data-review-featured-topics] th")
.each { |element| element["style"] = "text-align: left;padding-bottom: 12px;" }
doc
.css("[data-review-featured-topics] th:first-child")
.each { |element| element["width"] = "15%" }
doc
.css("[data-review-featured-topics] th:nth-child(2)")
.each { |element| element["width"] = "60%" }
doc
.css("[data-review-featured-topics] th:last-child")
.each { |element| element["width"] = "25%" }
doc
.css("[data-review-topic-users] td")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["valign"] = "top"
end
doc
.css("[data-review-featured-topics] td")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["valign"] = "top"
end
doc
.css("[data-review-topic-users] td table td:first-child")
.each do |element|
element["style"] = "padding-bottom: 6px;"
element["width"] = "25"
end
doc
.css("[data-review-topic-users] td table td:nth-child(2)")
.each { |element| element["style"] = "padding-left: 4px;padding-bottom: 6px;" }
end
DiscourseEvent.on(:username_changed) do |old_username, new_username|
Post
.joins(:_custom_fields)
.where(
"post_custom_fields.name = ? AND posts.raw LIKE ?",
YearlyReview::POST_CUSTOM_FIELD,
"%/#{old_username}/%",
)
.update_all(
"raw = REPLACE(raw, '/#{old_username}/', '/#{new_username}/'), baked_version = NULL",
)
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。