This commit is contained in:
Douglas Christensen 2025-02-01 03:47:34 -05:00 committed by GitHub
commit b638038c23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View file

@ -499,6 +499,14 @@ class Site < Sequel::Model
FileUtils.cp template_file_path('robots.txt'), tmpfile.path
files << {filename: 'robots.txt', tempfile: tmpfile}
tmpfile = Tempfile.new '.feedignore'
tmpfile.write "# Use .feedignore to prevent certain files from showing up in the update feed.\n"
tmpfile.write "# You can name specific files, or use the * wildcard.\n\n# Ignore this file\n.feedignore\n\n"
tmpfile.write "# Ignore all files in the test/ directory\ntest/*"
tmpfile.write "\n\n"
tmpfile.close
files << {filename: '.feedignore', tempfile: tmpfile}
store_files files, new_install: true
end
@ -1903,6 +1911,27 @@ class Site < Sequel::Model
true
end
def feedignore_patterns
return @feedignore_patterns if defined?(@feedignore_patterns)
feedignore_path = current_files_path('.feedignore')
if File.exist?(feedignore_path)
@feedignore_patterns = File.readlines(feedignore_path).map(&:strip).reject { |line| line.empty? || line.start_with?('#') }
else
@feedignore_patterns = []
end
@feedignore_patterns
end
def should_ignore_from_feed?(path)
return false if feedignore_patterns.empty?
feedignore_patterns.any? do |pattern|
# Convert glob pattern to regex
regex = Regexp.new("^#{pattern.gsub('*', '.*').gsub('?', '.')}$")
path.match?(regex)
end
end
private
def store_file(path, uploaded, opts={})

View file

@ -7,10 +7,14 @@ class SiteChange < Sequel::Model
one_to_many :site_change_files
def site_change_filenames(limit=6)
site_change_files_dataset.select(:filename).limit(limit).order(:created_at.desc).all.collect {|f| f.filename}.sort_by {|f| f.match('html') ? 0 : 1}
filenames = site_change_files_dataset.select(:filename).limit(limit).order(:created_at.desc).all.collect {|f| f.filename}
filenames = filenames.reject { |f| site.should_ignore_from_feed?(f) }
filenames.sort_by {|f| f.match('html') ? 0 : 1}
end
def self.record(site, filename)
return if site.should_ignore_from_feed?(filename)
site_change = filter(site_id: site.id).order(:created_at.desc).first
if site_change.nil? || site_change.created_at+NEW_CHANGE_TIMEOUT < Time.now