5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 20:26:22 +00:00

encontrar todos los idiomas

This commit is contained in:
f 2022-04-23 18:56:34 -03:00
parent bfdd90088f
commit 0c34613cb5

View file

@ -13,7 +13,7 @@
class UriCollectionJob < PeriodicJob class UriCollectionJob < PeriodicJob
# Ignoramos imágenes porque suelen ser demasiadas y no aportan a las # Ignoramos imágenes porque suelen ser demasiadas y no aportan a las
# estadísticas. # estadísticas.
IMAGES = %w[.png .jpg .jpeg .gif .webp].freeze IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze
STAT_NAME = 'uri_collection_job' STAT_NAME = 'uri_collection_job'
def perform(site_id:, once: true) def perform(site_id:, once: true)
@ -91,18 +91,46 @@ class UriCollectionJob < PeriodicJob
# #
# @return [Array] # @return [Array]
def uris def uris
@uris ||= Dir.chdir destination do @uris ||=
(Dir.glob('**/*.html') + Dir.glob('public/**/*').reject do |p| locales.map do |locale|
File.directory? p uri = "/#{locale}/".squeeze('/')
end.reject do |p| dir = File.join(destination, locale)
p = p.downcase
IMAGES.any? do |i| files(dir).map do |f|
p.end_with? i uri + f
end end
end).map do |uri| end.flatten(2)
"/#{uri}"
end end
# @return [Array]
def locales
@locales ||= ['', site.locales.map(&:to_s)].flatten(1)
end
# @param :dir [String]
# @return [Array]
def files(dir)
Dir.chdir(dir) do
pages = Dir.glob('**/*.html')
files = Dir.glob('public/**/*')
files = remove_directories files
files = remove_images files
[pages, files].flatten(1)
end
end
# @param :files [Array]
# @return [Array]
def remove_directories(files)
files.reject do |f|
File.directory? f
end
end
def remove_images(files)
files.reject do |f|
IMAGES.include? File.extname(f).downcase
end end
end end
end end