FIX: Further improvements for plugin list (#24622)

Followup e37fb3042d

* Automatically remove the prefix `Discourse ` from all the plugin titles to avoid repetition
* Remove the :discourse_dev: icon from the author. Consider a "By Discourse" with no labels as official
* We add a `label` metadata to plugin.rb
  * Only plugins made by us in `discourse` and `discourse-org` GitHub organizations will show these in the list
* Make the plugin author font size a little smaller
* Make the commit sha look like a link so it's more obvious it goes to the code

Also I added some validation and truncation for plugin metadata
parsing since currently you can put absolutely anything in there
and it will show on the plugin list.
This commit is contained in:
Martin Brennan
2023-11-30 10:53:17 +10:00
committed by GitHub
parent bcb7e86c24
commit c58cd697d2
7 changed files with 98 additions and 32 deletions

View File

@@ -111,10 +111,28 @@ class Plugin::Metadata
required_version
transpile_js
meta_topic_id
experimental
label
]
attr_accessor(*FIELDS)
MAX_FIELD_LENGTHS ||= {
name: 75,
about: 350,
authors: 200,
contact_emails: 200,
url: 500,
label: 20,
}
def meta_topic_id=(value)
@meta_topic_id =
begin
Integer(value)
rescue StandardError
nil
end
end
def self.parse(text)
metadata = self.new
text.each_line { |line| break unless metadata.parse_line(line) }
@@ -130,12 +148,17 @@ class Plugin::Metadata
unless line.empty?
return false unless line[0] == "#"
attribute, *description = line[1..-1].split(":")
attribute, *value = line[1..-1].split(":")
description = description.join(":")
value = value.join(":")
attribute = attribute.strip.gsub(/ /, "_").to_sym
self.public_send("#{attribute}=", description.strip) if FIELDS.include?(attribute)
if FIELDS.include?(attribute)
self.public_send(
"#{attribute}=",
value.strip.truncate(MAX_FIELD_LENGTHS[attribute] || 1000),
)
end
end
true