mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
News Feed
This commit is contained in:
parent
70a58176fa
commit
fa35da3c12
5 changed files with 46 additions and 76 deletions
3
app.rb
3
app.rb
|
@ -87,7 +87,9 @@ get '/site/:username' do |username|
|
|||
if current_site && (site.is_blocking?(current_site) || current_site.is_blocking?(site))
|
||||
not_found
|
||||
end
|
||||
|
||||
@title = site.title
|
||||
@latest_events = site.latest_events
|
||||
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
||||
end
|
||||
|
||||
|
@ -125,6 +127,7 @@ end
|
|||
get '/?' do
|
||||
if current_site
|
||||
require_login
|
||||
@suggestions = current_site.suggestions
|
||||
halt erb :'home', locals: {site: current_site}
|
||||
end
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ class Site < Sequel::Model
|
|||
}
|
||||
end
|
||||
|
||||
=begin
|
||||
def follows_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
|
@ -209,6 +210,7 @@ class Site < Sequel::Model
|
|||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
=end
|
||||
|
||||
def blocking_site_ids
|
||||
@blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id}
|
||||
|
@ -493,8 +495,13 @@ class Site < Sequel::Model
|
|||
'Supporter Plan'
|
||||
end
|
||||
|
||||
def latest_events
|
||||
events_dataset.order(:id.desc).limit(10).all
|
||||
def latest_events(limit=10, offset=0)
|
||||
events_dataset.order(:created_at.desc).limit(limit, offset).all
|
||||
end
|
||||
|
||||
def news_feed(limit=10, offset=0)
|
||||
following_ids = self.followings_dataset.select(:site_id).all.collect {|f| f.site_id}
|
||||
Event.filter(site_id: following_ids+[self.id]).order(:created_at.desc).limit(limit, offset).all
|
||||
end
|
||||
|
||||
def title
|
||||
|
@ -523,6 +530,10 @@ class Site < Sequel::Model
|
|||
end
|
||||
end
|
||||
|
||||
def suggestions(limit=8, offset=0)
|
||||
Site.where(tags: tags).limit(limit, offset).order(:updated_at.desc).all
|
||||
end
|
||||
|
||||
def screenshot_path(filename, resolution)
|
||||
File.join(SCREENSHOTS_ROOT, values[:username], "#{filename}.#{resolution}.jpg")
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<div class="icon"></div>
|
||||
<% actioning_site_username = event.actioning_site_dataset.select(:username).first.username %>
|
||||
<% event_site_username = event.site_dataset.select(:username).first.username %>
|
||||
<a href="/site/<%= actioning_site_username %>" class="user"><%= actioning_site_username %></a> followed <a href="/site/<%= event_site_username %>" class="user"><%= event_site_username %>'s</a> website<span class="date"><%= event.created_at.ago %></span>
|
||||
<a href="/site/<%= actioning_site_username %>" class="user"><%= actioning_site_username %></a> is following <a href="/site/<%= event_site_username %>" class="user"><%= event_site_username %></a>.<span class="date"><%= event.created_at.ago %></span>
|
||||
</div>
|
||||
<% elsif event.site_change_id %>
|
||||
<div class="news-item update">
|
||||
|
|
|
@ -15,79 +15,36 @@
|
|||
<div class="content misc-page columns right-col">
|
||||
<div class="col-left">
|
||||
<div class="col col-66">
|
||||
<% if current_site.followings_dataset.count == 0 %>
|
||||
<% if current_site.followings_dataset.count > 0 %>
|
||||
<%== erb :'_news', layout: false, locals: {site: current_site, events: current_site.news_feed} %>
|
||||
<% else %>
|
||||
<div class="welcome">
|
||||
<h4>Welcome to your Neocities news feed!</h4>
|
||||
<p>You aren't following any websites yet! Once you do, updates will show up here and you can like and comment on them. Here are some website suggestions based on your tags, or <a href="/browse">check out all the sites on Neocities!</a></p>
|
||||
<p>
|
||||
You aren't following any websites yet! Once you do, updates will show up here and you can like and comment on them.
|
||||
|
||||
<% if @suggestions.length > 0 %>
|
||||
Here are some website suggestions based on your tags, or <a href="/browse">check out all the sites on Neocities!</a>
|
||||
<% else %>
|
||||
Want to find some sites to follow? <a href="/browse">Check out all the sites on Neocities!</a>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
<a class="tag" href="http://neocities.org">Anime</a>
|
||||
<a class="tag" href="http://neocities.org">Art</a>
|
||||
<a class="tag" href="http://neocities.org">Cooking</a>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
<a class="tag" href="http://neocities.org">Anime</a>
|
||||
<a class="tag" href="http://neocities.org">Art</a>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
<a class="tag" href="http://neocities.org">Anime</a>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
<a class="tag" href="http://neocities.org">Anime</a>
|
||||
</div>
|
||||
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://dragonquest.neocities.org">
|
||||
<img src="https://neocities.org/site_screenshots/nintendosv/index.html.270x162.jpg">
|
||||
<span class="caption">dragonquest</span>
|
||||
</a>
|
||||
</div>
|
||||
<a class="tag" href="http://neocities.org">Games</a>
|
||||
</div>
|
||||
|
||||
<% @suggestions.each do |suggested_site| %>
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://<%= suggested_site.username %>.neocities.org">
|
||||
<img src="<%= suggested_site.screenshot_url('index.html', '270x162') %>">
|
||||
</a>
|
||||
<span class="caption">
|
||||
<a href="/site/<%= suggested_site.username %>"><%= suggested_site.title %></a></span>
|
||||
</div>
|
||||
<% suggested_site.tags.each do |tag| %>
|
||||
<a class="tag" href="/browse?tag=<%= Rack::Utils.escape tag.name %>"><%= tag.name %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -76,18 +76,17 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<% latest_events = site.latest_events %>
|
||||
<% if latest_events.empty? %>
|
||||
<% if @latest_events.empty? %>
|
||||
<div>
|
||||
<p>No recent activity.</p>
|
||||
<% if site == current_site %>
|
||||
<% if @site == current_site %>
|
||||
<p>
|
||||
You should <a href="/dashboard">update your site</a>!
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<%== erb :'_news', layout: false, locals: {site: site, events: latest_events} %>
|
||||
<%== erb :'_news', layout: false, locals: {site: @site, events: @latest_events} %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue