Fix bug with long mobilizon image names.

This commit is contained in:
Marc-AntoineA 2021-03-21 14:57:04 +01:00
parent 6ba6c2410e
commit f785b1bf42
1 changed files with 11 additions and 7 deletions

View File

@ -21,6 +21,8 @@ module Jekyll
def fetch_and_thumbnail_image(site, url, cache_dir) def fetch_and_thumbnail_image(site, url, cache_dir)
cache_name = url.gsub /[\ :\/\?=]+/, '_' cache_name = url.gsub /[\ :\/\?=]+/, '_'
point_index = cache_name.rindex('.')
cache_name = cache_name[0..[240, point_index].min()] + cache_name[point_index..cache_name.size]
cache_dir_media = File.join cache_dir, 'media' cache_dir_media = File.join cache_dir, 'media'
cache_path = File.join cache_dir_media, cache_name cache_path = File.join cache_dir_media, cache_name
@ -239,6 +241,13 @@ module Jekyll
return cache return cache
end # def generate end # def generate
def to_local_url(site, url)
url = url.gsub(/[\ :\/\?=]+/, '_')
point_index = url.rindex('.')
url = url[0..[240, point_index].min()] + url[point_index..url.size]
URI::encode(File.join site.config['mobilizon_cachedir'], "media", url)
end
def filter_events(events, tags_and_organizers) def filter_events(events, tags_and_organizers)
return events.select { |event| (tags_and_organizers.include? event['attributedTo']['preferredUsername']) || !(tags_and_organizers & (event['tags'].map { |tag| tag['slug'].downcase })).empty? || !(tags_and_organizers & (event['tags'].map { |tag| tag['title'].downcase })).empty? } return events.select { |event| (tags_and_organizers.include? event['attributedTo']['preferredUsername']) || !(tags_and_organizers & (event['tags'].map { |tag| tag['slug'].downcase })).empty? || !(tags_and_organizers & (event['tags'].map { |tag| tag['title'].downcase })).empty? }
end # def filter_events end # def filter_events
@ -301,7 +310,7 @@ module Jekyll
end end
if context["event"]["picture"] if context["event"]["picture"]
context["event"]["thumbnailurl"] = URI::encode(File.join site.config['mobilizon_cachedir'], "media", context["event"]["picture"]["url"].gsub(/[\ :\/\?=]+/, '_')) context["event"]["thumbnailurl"] = to_local_url site, context["event"]["picture"]["url"]
end end
if context["event"]["physicalAddress"] && context["event"]["physicalAddress"]["locality"] if context["event"]["physicalAddress"] && context["event"]["physicalAddress"]["locality"]
if context["event"]["physicalAddress"]["description"] == context["event"]["physicalAddress"]["locality"] if context["event"]["physicalAddress"]["description"] == context["event"]["physicalAddress"]["locality"]
@ -311,12 +320,7 @@ module Jekyll
end end
end end
if context["event"]["attributedTo"] && context["event"]["attributedTo"]["avatar"] && context["event"]["attributedTo"]["avatar"]["url"] if context["event"]["attributedTo"] && context["event"]["attributedTo"]["avatar"] && context["event"]["attributedTo"]["avatar"]["url"]
context["event"]["organizerAvatar"] = URI::encode( context["event"]["organizerAvatar"] = to_local_url site, context["event"]["attributedTo"]["avatar"]["url"]
File.join(site.config['mobilizon_cachedir'],
"media",
context["event"]["attributedTo"]["avatar"]["url"].gsub(/[\ :\/\?=]+/, '_')
)
)
end end
if context["event"]["attributedTo"] && context["event"]["attributedTo"]["name"] if context["event"]["attributedTo"] && context["event"]["attributedTo"]["name"]
context["event"]["organizer"] = context["event"]["attributedTo"]["name"] context["event"]["organizer"] = context["event"]["attributedTo"]["name"]