mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
further refinements to browse, fix broken test
This commit is contained in:
parent
18102eb76b
commit
4fc5698d0e
5 changed files with 50 additions and 51 deletions
|
@ -301,5 +301,9 @@ get '/admin/masquerade/:username' do
|
|||
end
|
||||
|
||||
def require_admin
|
||||
redirect '/' unless signed_in? && current_site.is_admin
|
||||
redirect '/' unless is_admin?
|
||||
end
|
||||
|
||||
def is_admin?
|
||||
signed_in? && current_site.is_admin
|
||||
end
|
|
@ -63,47 +63,46 @@ def browse_sites_dataset
|
|||
return ds
|
||||
end
|
||||
|
||||
params[:sort_by] ||= 'followers'
|
||||
params[:sort_by] ||= 'special_sauce'
|
||||
|
||||
case params[:sort_by]
|
||||
when 'special_sauce'
|
||||
ds = ds.where{score > 1}
|
||||
ds = ds.order(:score.desc, :follow_count.desc, :views.desc, :site_updated_at.desc)
|
||||
when 'supporters'
|
||||
ds = ds.where sites__id: Site.supporter_ids
|
||||
ds = ds.order :follow_count.desc, :views.desc, :site_updated_at.desc
|
||||
#when 'featured'
|
||||
# ds = ds.exclude featured_at: nil
|
||||
# ds = ds.order :featured_at.desc
|
||||
#when 'hits'
|
||||
# ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
# ds = ds.order(:hits.desc, :site_updated_at.desc)
|
||||
#when 'most_views'
|
||||
# ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
# ds = ds.order(:views.desc, :site_updated_at.desc)
|
||||
#when 'least_views'
|
||||
# ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
# ds = ds.order(:views.asc, :site_updated_at.desc)
|
||||
when 'newest'
|
||||
ds = ds.order(:created_at.desc, :views.desc)
|
||||
#when 'oldest'
|
||||
# ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
# ds = ds.order(:created_at, :views.desc)
|
||||
ds = ds.where{score > 1} unless params[:tag]
|
||||
ds = ds.order :score.desc, :follow_count.desc, :views.desc, :site_updated_at.desc
|
||||
when 'random'
|
||||
ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
ds = ds.where{score > 5}
|
||||
ds = ds.where{score > 3} unless params[:tag]
|
||||
puts params.inspect
|
||||
ds = ds.order(Sequel.lit('RANDOM()'))
|
||||
#ds = ds.where 'random() < 0.01'
|
||||
when 'most_followed'
|
||||
ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS}
|
||||
ds = ds.where{follow_count > Site::BROWSE_FOLLOWER_MINIMUM_FOLLOWS}
|
||||
ds = ds.where{updated_at > Site::BROWSE_FOLLOWER_UPDATED_AT_CUTOFF.ago} unless params[:tag]
|
||||
ds = ds.order :follow_count.desc, :score.desc, :updated_at.desc
|
||||
when 'last_updated'
|
||||
ds = ds.where{score > 5}
|
||||
ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS}
|
||||
params[:sort_by] = 'last_updated'
|
||||
ds = ds.exclude(site_updated_at: nil)
|
||||
ds = ds.order(:site_updated_at.desc)
|
||||
ds = ds.where{score > 3} unless params[:tag]
|
||||
ds = ds.exclude site_updated_at: nil
|
||||
ds = ds.order :site_updated_at.desc
|
||||
when 'newest'
|
||||
ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} unless is_admin?
|
||||
ds = ds.exclude site_updated_at: nil
|
||||
ds = ds.order :created_at.desc, :views.desc
|
||||
when 'oldest'
|
||||
ds = ds.where{score > 0.4} unless params[:tag]
|
||||
ds = ds.exclude site_updated_at: nil
|
||||
ds = ds.order(:created_at, :views.desc)
|
||||
when 'hits'
|
||||
ds = ds.where{score > 1}
|
||||
ds = ds.order(:hits.desc, :site_updated_at.desc)
|
||||
when 'views'
|
||||
ds = ds.where{score > 3}
|
||||
ds = ds.order(:views.desc, :site_updated_at.desc)
|
||||
when 'featured'
|
||||
ds = ds.exclude featured_at: nil
|
||||
ds = ds.order :featured_at.desc
|
||||
when 'tipping_enabled'
|
||||
ds = ds.where tipping_enabled: true
|
||||
ds = ds.where("(tipping_paypal is not null and tipping_paypal != '') or (tipping_bitcoin is not null and tipping_bitcoin != '')")
|
||||
ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS}
|
||||
ds = ds.where{score > 1} unless params[:tag]
|
||||
ds = ds.group :sites__id
|
||||
ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc
|
||||
when 'blocks'
|
||||
|
@ -112,11 +111,6 @@ def browse_sites_dataset
|
|||
ds = ds.inner_join :blocks, :site_id => :id
|
||||
ds = ds.group :sites__id
|
||||
ds = ds.order :total.desc
|
||||
when 'followers'
|
||||
params[:sort_by] = 'followers'
|
||||
ds = ds.where{follow_count > 0}
|
||||
ds = ds.where{updated_at > 9.months.ago}
|
||||
ds = ds.order :follow_count.desc, :score.desc, :updated_at.desc
|
||||
end
|
||||
|
||||
ds = ds.where ['sites.is_nsfw = ?', (params[:is_nsfw] == 'true' ? true : false)]
|
||||
|
|
|
@ -84,6 +84,8 @@ class Site < Sequel::Model
|
|||
|
||||
BROWSE_MINIMUM_VIEWS = 100
|
||||
BROWSE_MINIMUM_FOLLOWER_VIEWS = 10_000
|
||||
BROWSE_FOLLOWER_UPDATED_AT_CUTOFF = 9.months
|
||||
BROWSE_FOLLOWER_MINIMUM_FOLLOWS = 0
|
||||
|
||||
SCREENSHOT_DELAY_SECONDS = 30
|
||||
SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50']
|
||||
|
|
|
@ -68,7 +68,7 @@ describe 'site page' do
|
|||
describe 'blocking' do
|
||||
before do
|
||||
@tag = SecureRandom.hex 10
|
||||
@blocked_site = Fabricate :site, new_tags_string: @tag, created_at: 2.weeks.ago, site_changed: true, views: Site::BROWSE_MINIMUM_FOLLOWER_VIEWS+1
|
||||
@blocked_site = Fabricate :site, new_tags_string: @tag, created_at: 1.year.ago, site_changed: true, views: Site::BROWSE_MINIMUM_FOLLOWER_VIEWS+1, follow_count: Site::BROWSE_FOLLOWER_MINIMUM_FOLLOWS+1
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
|
@ -15,18 +15,17 @@
|
|||
<label class="text-Label" for="sort_by">Sort by:</label>
|
||||
<div class="select-Container">
|
||||
<select name="sort_by" id="sort_by" class="input-Select">
|
||||
<option value="followers" <%= params[:sort_by] == 'followers' ? 'selected' : '' %>>Most Followed</option>\
|
||||
<option value="special_sauce" <%= params[:sort_by] == 'special_sauce' ? 'selected' : '' %>>Special Sauce</option>
|
||||
<option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
|
||||
<option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
|
||||
<option value="supporters" <%= params[:sort_by] == 'supporters' ? 'selected' : '' %>>Neocities Supporters</option>
|
||||
<!-- <option value="featured" <%= params[:sort_by] == 'featured' ? 'selected' : '' %>>Featured</option> -->
|
||||
<option value="tipping_enabled" <%= params[:sort_by] == 'tipping_enabled' ? 'selected' : '' %>>Accepting Tips</option>
|
||||
<!-- <option value="most_views" <%= params[:sort_by] == 'most_views' ? 'selected' : '' %>>Most Views</option> -->
|
||||
<!-- <option value="least_views" <%= params[:sort_by] == 'least_views' ? 'selected' : '' %>>Least Views</option> -->
|
||||
<!-- <option value="hits" <%= params[:sort_by] == 'hits' ? 'selected' : '' %>>Most Hits</option> -->
|
||||
<option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
|
||||
<!-- <option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option> -->
|
||||
<option value="special_sauce" <%= params[:sort_by] == 'special_sauce' ? 'selected' : '' %>>Special Sauce</option>
|
||||
<option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
|
||||
<option value="most_followed" <%= params[:sort_by] == 'most_followed' ? 'selected' : '' %>>Most Followed</option>
|
||||
<option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
|
||||
<option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Views</option>
|
||||
<option value="tipping_enabled" <%= params[:sort_by] == 'tipping_enabled' ? 'selected' : '' %>>Tipping Enabled</option>
|
||||
<% if signed_in? %>
|
||||
<option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
|
||||
<% end %>
|
||||
<option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option>
|
||||
<!-- <option value="robots" <%= params[:sort_by] == 'robots' ? 'selected' : '' %>>Robots</option> -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue