5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 18:26:21 +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
# Ignoramos imágenes porque suelen ser demasiadas y no aportan a las
# estadísticas.
IMAGES = %w[.png .jpg .jpeg .gif .webp].freeze
IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze
STAT_NAME = 'uri_collection_job'
def perform(site_id:, once: true)
@ -91,18 +91,46 @@ class UriCollectionJob < PeriodicJob
#
# @return [Array]
def uris
@uris ||= Dir.chdir destination do
(Dir.glob('**/*.html') + Dir.glob('public/**/*').reject do |p|
File.directory? p
end.reject do |p|
p = p.downcase
@uris ||=
locales.map do |locale|
uri = "/#{locale}/".squeeze('/')
dir = File.join(destination, locale)
IMAGES.any? do |i|
p.end_with? i
end
end).map do |uri|
"/#{uri}"
files(dir).map do |f|
uri + f
end
end.flatten(2)
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