This commit is contained in:
Kyle Drake 2013-06-23 19:53:26 -07:00
commit ed240b44f4
8 changed files with 23 additions and 7 deletions

View file

@ -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

2
app.rb
View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -3,7 +3,7 @@
div
h1 Web Sites on NeoCities
p If you like a site, don't forget to bookmark it!<br>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" <strong>#{site.hits} visits</strong>, 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

View file

@ -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.

View file

@ -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.
p The requested page was not found.