diff --git a/Rakefile b/Rakefile index 6a9be477..bec7be5a 100644 --- a/Rakefile +++ b/Rakefile @@ -34,3 +34,8 @@ task :parse_logs => [:environment] do end end + +desc 'Update screenshots' +task :update_screenshots => [:environment] do + Site.select(:username).filter(is_banned: false).filter(~{updated_at: nil}).order(:updated_at.desc).all.collect {|s| Backburner.enqueue ScreenshotJob, s.username } +end diff --git a/app.rb b/app.rb index c16fb9b2..c7227b5f 100644 --- a/app.rb +++ b/app.rb @@ -124,7 +124,7 @@ post '/site_files/upload' do mime_type = Magic.guess_file_mime_type params[:newfile][:tempfile].path - unless Site::VALID_MIME_TYPES.include?(mime_type) && Site::VALID_EXTENSIONS.include?(File.extname(params[:newfile][:filename]).sub(/^./, '')) + unless (Site::VALID_MIME_TYPES.include?(mime_type) || mime_type =~ /text/) && Site::VALID_EXTENSIONS.include?(File.extname(params[:newfile][:filename]).sub(/^./, '')) @errors << 'File must me one of the following: HTML, Text, Image (JPG PNG GIF JPEG SVG), JS, CSS, Markdown.' halt slim(:'site_files/new') end diff --git a/environment.rb b/environment.rb index e9069cde..a22ebf48 100644 --- a/environment.rb +++ b/environment.rb @@ -45,3 +45,9 @@ DB.loggers << Logger.new(STDOUT) if ENV['RACK_ENV'] == 'development' if ENV['RACK_ENV'] == 'development' && Server.count == 0 Server.create ip: '127.0.0.1', slots_available: 999999 end + +Backburner.configure do |config| + config.max_job_retries = 3 + config.retry_delay = 200 + config.respond_timeout = 120 +end diff --git a/files/nginx.conf b/files/nginx.conf index 7bc944cf..16280baa 100644 --- a/files/nginx.conf +++ b/files/nginx.conf @@ -31,6 +31,9 @@ http { # server_names_hash_bucket_size 64; # server_name_in_redirect off; + # Serve content as UTF-8 by default + charset utf-8; + include /etc/nginx/mime.types; default_type application/octet-stream; diff --git a/jobs/screenshot_job.rb b/jobs/screenshot_job.rb index fac1b216..6912cf3c 100644 --- a/jobs/screenshot_job.rb +++ b/jobs/screenshot_job.rb @@ -10,12 +10,12 @@ class ScreenshotJob screenshot = Tempfile.new 'neocities_screenshot' screenshot.close - caps = Selenium::WebDriver::Remote::Capabilities.htmlunit javascript_enabled: false, takesScreenshot: true + caps = Selenium::WebDriver::Remote::Capabilities.htmlunit javascript_enabled: true, takesScreenshot: true - driver = Selenium::WebDriver.for :remote, url: $config['phantomjs_url'], desired_capabilities: caps + driver = Selenium::WebDriver.for :remote, url: $config['phantomjs_url'][rand($config['phantomjs_url'].length)], desired_capabilities: caps driver.manage.window.resize_to 1280, 720 - wait = Selenium::WebDriver::Wait.new(:timeout => 5) # seconds + wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds wait.until { driver.navigate.to "http://#{username}.neocities.org" driver.save_screenshot screenshot.path diff --git a/views/browse.slim b/views/browse.slim index 756ae66e..e26ce514 100644 --- a/views/browse.slim +++ b/views/browse.slim @@ -3,7 +3,7 @@ div h1 Web Sites on NeoCities p If you like a site, don't forget to bookmark it!
Visitor counts are updated hourly. - div style="margin-bottom: 40px": .btn.btn-success Create your NeoCities site now + div style="margin-bottom: 40px": a.btn.btn-success href="/new" Create your NeoCities site now - count = 0 - @sites.each_with_index do |site,i| - if count == 0 @@ -16,7 +16,7 @@ .span1 h5: b style="margin-left: 20px": a href="http://#{site.username}.neocities.org" target="_blank" #{site.username} .span3.text-right - p style="margin-right: 20px; margin-top: 10px; font-size: 10pt" #{site.hits} visits, updated #{site.updated_at.ago} + p style="margin-right: 20px; margin-top: 10px; font-size: 10pt" #{site.hits} visits, updated #{site.updated_at.ago} a href="http://#{site.username}.neocities.org" target="_blank": img src="/site_screenshots/#{ENV['RACK_ENV'] == 'development' ? 'victoria' : site.username}.jpg" - if @page_count > 1 diff --git a/views/templates/index.slim b/views/templates/index.slim index 3e46b5d9..c43de348 100644 --- a/views/templates/index.slim +++ b/views/templates/index.slim @@ -1,6 +1,7 @@ doctype html html head + meta charset="utf-8" title #{template_site_title @site.username} - Front Page body p This is a new page! Coming soon. diff --git a/views/templates/not_found.slim b/views/templates/not_found.slim index 58178574..bfdc8e59 100644 --- a/views/templates/not_found.slim +++ b/views/templates/not_found.slim @@ -1,5 +1,6 @@ html head + meta charset="utf-8" title #{template_site_title @site.username} - Not Found body - p The requested page was not found. \ No newline at end of file + p The requested page was not found.