follow/followings fixes, general cleanups

This commit is contained in:
Kyle Drake 2014-05-19 18:31:46 +02:00
parent ad9ac1e68d
commit 264e4becea
6 changed files with 41 additions and 24 deletions

2
app.rb
View file

@ -76,6 +76,8 @@ end
post '/site/:sitename/comment' do |sitename| post '/site/:sitename/comment' do |sitename|
require_login require_login
redirect "/site/#{sitename}" if params[:message].empty?
site = Site[username: sitename] site = Site[username: sitename]
DB.transaction do DB.transaction do

View file

@ -1,3 +1,12 @@
class Tag < Sequel::Model class Tag < Sequel::Model
many_to_many :sites many_to_many :sites
end
def before_create
super
values[:name].downcase!
end
def self.create_unless_exists(name)
dataset.filter(name: name).first || create(name: name)
end
end

View file

@ -1,12 +1,25 @@
<% if (!is_current_site && site.followings_dataset.count > 0) || is_current_site %> <% if (!is_current_site && site.followings_dataset.count > 0) || is_current_site %>
<h3>Following</h3> <h3><%= is_current_site ? 'You follow' : 'This site follows' %></h3>
<div class="following"> <div class="following">
<% if site.followings_dataset.count == 0 %> <% if site.followings_dataset.count == 0 %>
<p>You are not following any sites yet. Add some by <a href="/browse">browsing sites</a> or looking at your tags. <p>You are not following any sites yet. Add some by <a href="/browse">browsing sites</a> or looking at your tags.
<% else %> <% else %>
<% site.followings.each do |following| %> <% site.followings.each do |following| %>
<a href="/site/<%= site.username %>"><img src="<%= site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a> <a href="/site/<%= following.site.username %>"><img src="<%= site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
<% if (!is_current_site && site.follows_dataset.count > 0) || is_current_site %>
<h3>Followers</h3>
<div class="following">
<% if site.follows_dataset.count == 0 %>
No followers yet.
<% else %>
<% site.follows.each do |follow| %>
<a href="/site/<%= follow.actioning_site.username %>"><img src="<%= follow.actioning_site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a>
<% end %>
<% end %>
</div>
<% end %>

View file

@ -4,7 +4,7 @@
<p>You don't have any tags yet. <a href="#">Add some!</a> <p>You don't have any tags yet. <a href="#">Add some!</a>
<% else %> <% else %>
<% site.tags.each do |tag| %> <% site.tags.each do |tag| %>
<a class="tag" href="/tags/<%= tag.name %>"><%= tag.name %></a> <a class="tag" href="/browse?tag=<%== Rack::Utils.escape tag.name %>"><%= tag.name %></a>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -33,7 +33,7 @@
<a class="tag" href="http://neocities.org">Art</a> <a class="tag" href="http://neocities.org">Art</a>
<a class="tag" href="http://neocities.org">Cooking</a> <a class="tag" href="http://neocities.org">Cooking</a>
</div> </div>
<div class="site-suggestion"> <div class="site-suggestion">
<div class="site-portrait"> <div class="site-portrait">
<a href="http://dragonquest.neocities.org"> <a href="http://dragonquest.neocities.org">
@ -45,7 +45,7 @@
<a class="tag" href="http://neocities.org">Anime</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">Art</a>
</div> </div>
<div class="site-suggestion"> <div class="site-suggestion">
<div class="site-portrait"> <div class="site-portrait">
<a href="http://dragonquest.neocities.org"> <a href="http://dragonquest.neocities.org">
@ -56,7 +56,7 @@
<a class="tag" href="http://neocities.org">Games</a> <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">Anime</a>
</div> </div>
<div class="site-suggestion"> <div class="site-suggestion">
<div class="site-portrait"> <div class="site-portrait">
<a href="http://dragonquest.neocities.org"> <a href="http://dragonquest.neocities.org">
@ -66,7 +66,7 @@
</div> </div>
<a class="tag" href="http://neocities.org">Games</a> <a class="tag" href="http://neocities.org">Games</a>
</div> </div>
<div class="site-suggestion"> <div class="site-suggestion">
<div class="site-portrait"> <div class="site-portrait">
<a href="http://dragonquest.neocities.org"> <a href="http://dragonquest.neocities.org">
@ -77,7 +77,7 @@
<a class="tag" href="http://neocities.org">Games</a> <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">Anime</a>
</div> </div>
<div class="site-suggestion"> <div class="site-suggestion">
<div class="site-portrait"> <div class="site-portrait">
<a href="http://dragonquest.neocities.org"> <a href="http://dragonquest.neocities.org">
@ -92,7 +92,7 @@
</div> </div>
<div class="col col-33"> <div class="col col-33">
<p class="site-url"><a href="//<%= site.username %>.neocities.org" target="_blank"><%= site.username %>.neocities.org</a></p> <p class="site-url"><a href="//<%= current_site.username %>.neocities.org" target="_blank"><%= site.username %>.neocities.org</a></p>
<div class="stats"> <div class="stats">
<div class="col col-50"> <div class="col col-50">
<% if site.updated_at %> <% if site.updated_at %>
@ -120,4 +120,4 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -69,16 +69,17 @@
<span>Last updated</span> <span>Last updated</span>
<strong> <strong>
<% if site.updated_at.nil? %> <% if site.updated_at.nil? %>
Just Created <%= site.created_at.ago.downcase %>
<% else %> <% else %>
<%= site.updated_at.ago.downcase %> <%= site.updated_at.ago.downcase %>
<% end %> <% end %>
</strong> </strong>
</div> </div>
<div class="stat"><span>Total updates</span><strong><%= site.changed_count %></strong></div> <div class="stat"><span>Number of updates</span><strong><%= site.changed_count %></strong></div>
<div class="stat"><span>Created</span><strong><%= site.created_at.strftime('%B %-d, %Y') %></strong></div> <div class="stat"><span>Created</span><strong><%= site.created_at.strftime('%B %-d, %Y') %></strong></div>
</div> </div>
<!--
<h3>Archives</h3> <h3>Archives</h3>
<div class="archives"> <div class="archives">
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a> <a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
@ -87,15 +88,7 @@
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a> <a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
<a href="" class="more">See all versions</a> <a href="" class="more">See all versions</a>
</div> </div>
-->
<% if site.followings_dataset.count < 0 %>
<h3>Following</h3>
<div class="following">
<% site.followings.each do |following| %>
<a href="#"><img src="<%= site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a>
<% end %>
</div>
<% end %>
<%== erb :'_follows', layout: false, locals: {site: site, is_current_site: site == current_site} %> <%== erb :'_follows', layout: false, locals: {site: site, is_current_site: site == current_site} %>