mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
tag search for activities, more tags in browse cloud, link between activity and browse tags
This commit is contained in:
parent
137f8af60b
commit
581756e110
8 changed files with 86 additions and 35 deletions
8
app.rb
8
app.rb
|
@ -92,6 +92,14 @@ before do
|
|||
params[:page] = '1'
|
||||
end
|
||||
end
|
||||
|
||||
if params[:tag]
|
||||
begin
|
||||
params.delete 'tag' if params[:tag].nil? || !params[:tag].is_a?(String) || params[:tag].strip.empty? || params[:tag].match?(Tag::INVALID_TAG_REGEX)
|
||||
rescue Encoding::CompatibilityError
|
||||
params.delete 'tag'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
|
@ -3,14 +3,51 @@ get '/activity' do
|
|||
|
||||
@page = params[:page] || 1
|
||||
|
||||
@pagination_dataset = Event.global_dataset
|
||||
if params[:tag]
|
||||
query1 = Event
|
||||
.join(:sites, id: :site_id)
|
||||
.join(:sites_tags, site_id: :id)
|
||||
.join(:tags, id: :tag_id)
|
||||
.where(tags__name: params[:tag])
|
||||
.where(events__is_deleted: false, sites__is_deleted: false)
|
||||
.where{sites__score > Event::ACTIVITY_TAG_SCORE_LIMIT}
|
||||
.where(sites__is_nsfw: false)
|
||||
.where(follow_id: nil)
|
||||
.select_all(:events)
|
||||
|
||||
query2 = Event
|
||||
.join(:sites, id: :actioning_site_id)
|
||||
.join(:sites_tags, site_id: :id)
|
||||
.join(:tags, id: :tag_id)
|
||||
.where(tags__name: params[:tag])
|
||||
.where(events__is_deleted: false, sites__is_deleted: false)
|
||||
.where{sites__score > Event::ACTIVITY_TAG_SCORE_LIMIT}
|
||||
.where(sites__is_nsfw: false)
|
||||
.where(follow_id: nil)
|
||||
.select_all(:events)
|
||||
|
||||
if current_site
|
||||
blocking_site_ids = current_site.blocking_site_ids
|
||||
@pagination_dataset.exclude(events__site_id: blocking_site_ids).exclude(events__actioning_site_id: blocking_site_ids)
|
||||
query1 = query1.where(Sequel.|({events__site_id: nil}, ~{events__site_id: blocking_site_ids})).where(Sequel.|({events__actioning_site_id: nil}, ~{events__actioning_site_id: blocking_site_ids}))
|
||||
query2 = query2.where(Sequel.|({events__site_id: nil}, ~{events__site_id: blocking_site_ids})).where(Sequel.|({events__actioning_site_id: nil}, ~{events__actioning_site_id: blocking_site_ids}))
|
||||
end
|
||||
|
||||
@pagination_dataset = @pagination_dataset.paginate @page.to_i, Event::GLOBAL_PAGINATION_LENGTH
|
||||
ds = query1.union(query2, all: true).order(Sequel.desc(:created_at))
|
||||
else
|
||||
ds = Event.news_feed_default_dataset.exclude(sites__is_nsfw: true)
|
||||
|
||||
if current_site
|
||||
blocking_site_ids = current_site.blocking_site_ids
|
||||
ds = ds.where(Sequel.|({events__site_id: nil}, ~{events__site_id: blocking_site_ids})).where(Sequel.|({events__actioning_site_id: nil}, ~{events__actioning_site_id: blocking_site_ids}))
|
||||
end
|
||||
|
||||
ds = ds.where(
|
||||
Sequel.expr(Sequel[:sites][:score] > Event::GLOBAL_SCORE_LIMIT) |
|
||||
Sequel.expr(Sequel[:actioning_sites][:score] > Event::GLOBAL_SCORE_LIMIT)
|
||||
)
|
||||
end
|
||||
|
||||
@pagination_dataset = ds.paginate @page.to_i, Event::GLOBAL_PAGINATION_LENGTH
|
||||
@events = @pagination_dataset.all
|
||||
|
||||
erb :'activity'
|
||||
|
|
|
@ -2,12 +2,6 @@ get '/browse/?' do
|
|||
@page = params[:page]
|
||||
@page = 1 if @page.not_an_integer?
|
||||
|
||||
begin
|
||||
params.delete 'tag' if params[:tag].nil? || !params[:tag].is_a?(String) || params[:tag].strip.empty? || params[:tag].match?(Tag::INVALID_TAG_REGEX)
|
||||
rescue Encoding::CompatibilityError
|
||||
params.delete 'tag'
|
||||
end
|
||||
|
||||
if is_education?
|
||||
ds = education_sites_dataset
|
||||
else
|
||||
|
|
|
@ -16,6 +16,7 @@ class Event < Sequel::Model
|
|||
PAGINATION_LENGTH = 10
|
||||
GLOBAL_PAGINATION_LENGTH = 20
|
||||
GLOBAL_SCORE_LIMIT = 2
|
||||
ACTIVITY_TAG_SCORE_LIMIT = 0.2
|
||||
|
||||
def undeleted_comments_count
|
||||
comments_dataset.exclude(is_deleted: true).count
|
||||
|
@ -40,14 +41,6 @@ class Event < Sequel::Model
|
|||
order(:events__created_at.desc)
|
||||
end
|
||||
|
||||
def self.global_dataset
|
||||
news_feed_default_dataset.where(
|
||||
Sequel.expr(Sequel[:sites][:score] > GLOBAL_SCORE_LIMIT) |
|
||||
Sequel.expr(Sequel[:actioning_sites][:score] > GLOBAL_SCORE_LIMIT)
|
||||
).
|
||||
exclude(sites__is_nsfw: true)
|
||||
end
|
||||
|
||||
def created_by?(site)
|
||||
return true if actioning_site_id == site.id
|
||||
false
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
}
|
||||
}
|
||||
.single-Col{
|
||||
max-width:800px;
|
||||
}
|
||||
|
||||
// About page
|
||||
|
|
9
views/_browse_tags.erb
Normal file
9
views/_browse_tags.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<div class="row content misc">
|
||||
<h3>Popular Tags</h3>
|
||||
<p class="tagcloud">
|
||||
<% Tag.popular_names(1000).each_with_index do |tag,i| %>
|
||||
<% i = (((i+1).to_f/1000) * 10).to_i %>
|
||||
<a class="tag<%= i %>" href="<%= request.path %>?tag=<%= Rack::Utils.escape tag[:name] %>"><%= tag[:name] %></a>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
|
@ -1,10 +1,27 @@
|
|||
<div class="header-Outro">
|
||||
<div class="row content single-Col">
|
||||
<div class="header-Outro with-columns browse-page">
|
||||
<div class="row content">
|
||||
<div class="col col-100">
|
||||
<% if params[:tag] %>
|
||||
<h1><a href="/activity">Latest Activity</a> > <%= params[:tag] %></h1>
|
||||
<h4><a href="/browse?tag=<%= params[:tag]%>">Sites</a></h4>
|
||||
<% else %>
|
||||
<h1>Latest Activity on Neocities</h1>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col col-100 filter">
|
||||
<form action="/activity" method="GET">
|
||||
<fieldset class="grouping">
|
||||
<label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
|
||||
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto">
|
||||
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-left:auto; margin-right:auto; max-width:800px;">
|
||||
<div class="content single-Col misc-page" style="float:left;">
|
||||
</div>
|
||||
<div>
|
||||
<div class="content single-Col misc-page">
|
||||
<% if !signed_in? %>
|
||||
<div class="welcome">
|
||||
<h4>All the latest Neocities site news!</h4>
|
||||
|
@ -15,5 +32,6 @@
|
|||
<% end %>
|
||||
|
||||
<%== erb :'_news', locals: {current_site: nil, events: @events} %>
|
||||
<%== erb :'_browse_tags' %>
|
||||
</div>
|
||||
</div>
|
|
@ -3,6 +3,7 @@
|
|||
<div class="col col-100">
|
||||
<% if params[:tag] %>
|
||||
<h1><a href="/browse">Websites</a> > <%= params[:tag] %></h1>
|
||||
<h4><a href="/activity?tag=<%= params[:tag]%>">Activity</a></h4>
|
||||
<% else %>
|
||||
<h1>Sites on Neocities</h1>
|
||||
<% end %>
|
||||
|
@ -142,15 +143,7 @@
|
|||
<% end %>
|
||||
|
||||
<% unless is_education? %>
|
||||
<div class="row content misc">
|
||||
<h3>Popular Tags</h3>
|
||||
<p class="tagcloud">
|
||||
<% Tag.popular_names(100).each_with_index do |tag,i| %>
|
||||
<% i = (((i+1).to_f/100) * 10).to_i %>
|
||||
<a class="tag<%= i %>" href="/browse?tag=<%= Rack::Utils.escape tag[:name] %>"><%= tag[:name] %></a>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
<%== erb :_browse_tags %>
|
||||
<div class="row content misc">
|
||||
<h3>Text Search</h3>
|
||||
<form id="searchForm" method="GET" action="https://duckduckgo.com" class="content" onsubmit="return addSiteToSearch()">
|
||||
|
|
Loading…
Add table
Reference in a new issue