tag search for activities, more tags in browse cloud, link between activity and browse tags

This commit is contained in:
Kyle Drake 2024-09-04 12:19:48 -05:00
parent 137f8af60b
commit 581756e110
8 changed files with 86 additions and 35 deletions

8
app.rb
View file

@ -92,6 +92,14 @@ before do
params[:page] = '1' params[:page] = '1'
end end
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 end
after do after do

View file

@ -3,15 +3,52 @@ get '/activity' do
@page = params[:page] || 1 @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)
if current_site query2 = Event
blocking_site_ids = current_site.blocking_site_ids .join(:sites, id: :actioning_site_id)
@pagination_dataset.exclude(events__site_id: blocking_site_ids).exclude(events__actioning_site_id: blocking_site_ids) .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
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
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 end
@pagination_dataset = @pagination_dataset.paginate @page.to_i, Event::GLOBAL_PAGINATION_LENGTH @pagination_dataset = ds.paginate @page.to_i, Event::GLOBAL_PAGINATION_LENGTH
@events = @pagination_dataset.all @events = @pagination_dataset.all
erb :'activity' erb :'activity'
end end

View file

@ -2,12 +2,6 @@ get '/browse/?' do
@page = params[:page] @page = params[:page]
@page = 1 if @page.not_an_integer? @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? if is_education?
ds = education_sites_dataset ds = education_sites_dataset
else else

View file

@ -16,6 +16,7 @@ class Event < Sequel::Model
PAGINATION_LENGTH = 10 PAGINATION_LENGTH = 10
GLOBAL_PAGINATION_LENGTH = 20 GLOBAL_PAGINATION_LENGTH = 20
GLOBAL_SCORE_LIMIT = 2 GLOBAL_SCORE_LIMIT = 2
ACTIVITY_TAG_SCORE_LIMIT = 0.2
def undeleted_comments_count def undeleted_comments_count
comments_dataset.exclude(is_deleted: true).count comments_dataset.exclude(is_deleted: true).count
@ -40,14 +41,6 @@ class Event < Sequel::Model
order(:events__created_at.desc) order(:events__created_at.desc)
end 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) def created_by?(site)
return true if actioning_site_id == site.id return true if actioning_site_id == site.id
false false

View file

@ -24,7 +24,6 @@
} }
} }
.single-Col{ .single-Col{
max-width:800px;
} }
// About page // About page

9
views/_browse_tags.erb Normal file
View 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>&nbsp;&nbsp;
<% end %>
</p>
</div>

View file

@ -1,10 +1,27 @@
<div class="header-Outro"> <div class="header-Outro with-columns browse-page">
<div class="row content single-Col"> <div class="row content">
<h1>Latest Activity on Neocities</h1> <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>
</div> </div>
<div style="margin-left:auto; margin-right:auto; max-width:800px;"> <div>
<div class="content single-Col misc-page" style="float:left;"> <div class="content single-Col misc-page">
<% if !signed_in? %> <% if !signed_in? %>
<div class="welcome"> <div class="welcome">
<h4>All the latest Neocities site news!</h4> <h4>All the latest Neocities site news!</h4>
@ -15,5 +32,6 @@
<% end %> <% end %>
<%== erb :'_news', locals: {current_site: nil, events: @events} %> <%== erb :'_news', locals: {current_site: nil, events: @events} %>
<%== erb :'_browse_tags' %>
</div> </div>
</div> </div>

View file

@ -3,6 +3,7 @@
<div class="col col-100"> <div class="col col-100">
<% if params[:tag] %> <% if params[:tag] %>
<h1><a href="/browse">Websites</a> > <%= params[:tag] %></h1> <h1><a href="/browse">Websites</a> > <%= params[:tag] %></h1>
<h4><a href="/activity?tag=<%= params[:tag]%>">Activity</a></h4>
<% else %> <% else %>
<h1>Sites on Neocities</h1> <h1>Sites on Neocities</h1>
<% end %> <% end %>
@ -142,15 +143,7 @@
<% end %> <% end %>
<% unless is_education? %> <% unless is_education? %>
<div class="row content misc"> <%== erb :_browse_tags %>
<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>&nbsp;&nbsp;
<% end %>
</p>
</div>
<div class="row content misc"> <div class="row content misc">
<h3>Text Search</h3> <h3>Text Search</h3>
<form id="searchForm" method="GET" action="https://duckduckgo.com" class="content" onsubmit="return addSiteToSearch()"> <form id="searchForm" method="GET" action="https://duckduckgo.com" class="content" onsubmit="return addSiteToSearch()">