mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
shorten titles, DRY up url generation
This commit is contained in:
parent
c512b579ce
commit
50d0e9d4db
9 changed files with 66 additions and 31 deletions
|
@ -2,4 +2,13 @@ class String
|
|||
def empty?
|
||||
strip == '' ? true : false
|
||||
end
|
||||
|
||||
def shorten(length, usedots=true)
|
||||
if usedots
|
||||
return self if self.length < length
|
||||
"#{self[0..length-3]}..."
|
||||
else
|
||||
self[0..length]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'tilt'
|
||||
require 'rss'
|
||||
require 'nokogiri'
|
||||
|
||||
class Site < Sequel::Model
|
||||
include Sequel::ParanoidDelete
|
||||
|
@ -61,6 +62,8 @@ class Site < Sequel::Model
|
|||
|
||||
BANNED_TIME = 2592000 # 30 days in seconds
|
||||
|
||||
TITLE_MAX = 100
|
||||
|
||||
many_to_one :server
|
||||
|
||||
many_to_many :tags
|
||||
|
@ -256,6 +259,15 @@ class Site < Sequel::Model
|
|||
return false
|
||||
end
|
||||
|
||||
if filename == 'index.html'
|
||||
new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text
|
||||
|
||||
if new_title.length < TITLE_MAX
|
||||
self.title = new_title
|
||||
save_changes(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
FileUtils.mv uploaded.path, file_path(filename)
|
||||
File.chmod(0640, file_path(filename))
|
||||
|
||||
|
@ -509,8 +521,16 @@ class Site < Sequel::Model
|
|||
Event.filter(site_id: following_ids+[self.id]).order(:created_at.desc).limit(limit, offset).all
|
||||
end
|
||||
|
||||
def host
|
||||
domain ? domain : "#{username}.neocities.org"
|
||||
end
|
||||
|
||||
def title
|
||||
values[:title] || "#{values[:username]}.neocities.org"
|
||||
if values[:title].nil? || values[:title].empty?
|
||||
domain ? domain : "#{username}.neocities.org"
|
||||
else
|
||||
values[:title]
|
||||
end
|
||||
end
|
||||
|
||||
def hits_english
|
||||
|
|
|
@ -13,29 +13,32 @@
|
|||
<div class="news-item follow">
|
||||
<div class="title">
|
||||
<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> is following <a href="/site/<%= event_site_username %>" class="user"><%= event_site_username %></a>.<span class="date"><%= event.created_at.ago %></span>
|
||||
<% actioning_site = event.actioning_site_dataset.select(:username, :title, :domain).first %>
|
||||
<% event_site = event.site_dataset.select(:username, :title, :domain).first %>
|
||||
<a href="/site/<%= actioning_site.username %>" class="user" title="<%= actioning_site.title %>"><%= actioning_site.title.shorten(40) %></a>
|
||||
is following
|
||||
<a href="/site/<%= event_site.username %>" class="user" title="<%= event_site.title %>"><%= event_site.title.shorten(40) %></a>
|
||||
<span class="date"><%= event.created_at.ago %></span>
|
||||
</div>
|
||||
<% elsif event.site_change_id %>
|
||||
<div class="news-item update">
|
||||
<div class="title">
|
||||
<div class="icon"></div>
|
||||
<% event_site_username = event.site_dataset.select(:username).first.username %>
|
||||
<a href="http://<%= event_site_username %>.neocities.org" class="user"><%= event_site_username %>.neocities.org</a> has been updated. <span class="date"><%= event.created_at.ago %></span>
|
||||
<% event_site = event.site_dataset.select(:username, :title, :domain).first %>
|
||||
<a href="//<%= event_site.host %>" class="user"><%= event_site.title %></a> has been updated. <span class="date"><%= event.created_at.ago %></span>
|
||||
</div>
|
||||
<% site_change_filenames = event.site_change.site_change_filenames %>
|
||||
<% unless site_change_filenames.empty? %>
|
||||
<div class="content">
|
||||
<div class="files">
|
||||
<% event.site_change.site_change_filenames.each do |f| %>
|
||||
<% site_change_filenames.each do |f| %>
|
||||
<div class="file">
|
||||
<div class="html-thumbnail <%= site_change_file_display_class f %>">
|
||||
<a href="http://<%= site.username %>.neocities.org/<%= f %>">
|
||||
<a href="//<%= event_site.host %>/<%= f %>">
|
||||
<% if site_change_file_display_class(f) == 'html' %>
|
||||
<img src="<%= site.screenshot_url(f, '90x63') %>">
|
||||
<img src="<%= event_site.screenshot_url(f, '90x63') %>">
|
||||
<% elsif site_change_file_display_class(f) == 'image' %>
|
||||
<img src="<%= site.thumbnail_url(f, '90x63') %>">
|
||||
<img src="<%= event_site.thumbnail_url(f, '90x63') %>">
|
||||
<% elsif site_change_file_display_class(f) == 'misc' %>
|
||||
<span class="misc-icon">
|
||||
<%= File.extname(f).sub('.', '') %>
|
||||
|
@ -70,7 +73,7 @@
|
|||
<a href="#" class="comment_like" id="comment_<%= comment.id %>_like" data-placement="bottom" data-toggle="tooltip" data-original-title="<%= comment.liking_site_names.join('<br>') %>" onclick="Comment.toggleLike(<%= comment.id %>, '<%= csrf_token %>'); return false"><%= comment.site_likes?(current_site) ? 'Unlike' : 'Like' %><%= comment_likes_count > 0 ? " (#{comment_likes_count})" : '' %></a>
|
||||
<% else %>
|
||||
<% if comment_likes_count > 0 %>
|
||||
<%= comment_likes_count %> <%= comment_likes_count == 1 ? 'like' : 'likes' %>
|
||||
<%= comment_likes_count %> <%= comment_likes_count == 1 ? 'like' : 'likes' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<a href="#" id="like" data-placement="bottom" data-toggle="tooltip" data-original-title="<%= event.liking_site_names.join('<br>') %>" onclick="new Like(<%= event.id %>, '<%= csrf_token %>').toggleLike(); return false"><%= event.site_likes?(current_site) ? 'Unlike' : 'Like' %><%= event_likes_count > 0 ? " (#{event_likes_count})" : '' %></a>
|
||||
<% else %>
|
||||
<% if event_likes_count > 0 %>
|
||||
<%= event_likes_count %> <%= event_likes_count == 1 ? 'like' : 'likes' %>
|
||||
<%= event_likes_count %> <%= event_likes_count == 1 ? 'like' : 'likes' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if current_site %>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<li><a href="https://github.com/neocities/neocities-node" target="_blank">Node.js / JavaScript</a></li>
|
||||
<li><a href="https://github.com/aergonaut/neocitizen" target="_blank">Ruby</a> - contributed by <a href="https://twitter.com/aergonaut" target="_blank">Chris Fung</a></li>
|
||||
<li><a href="https://github.com/peterhellberg/neocities" target="_blank">Go</a> - contributed by <a href="https://twitter.com/peterhellberg" target="_blank">Peter Hellberg</a></li>
|
||||
<li><a href="https://github.com/seankross/neocities" target="_blank">R (statistical language)</a> - contributed by <a href="https://twitter.com/seankross">Sean Kross</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
<hr>
|
||||
|
|
|
@ -61,14 +61,14 @@
|
|||
<ul class="row website-Gallery content int-Gall">
|
||||
<% @sites.each do |site| %>
|
||||
<li>
|
||||
<a href="http://<%= site.username %>.neocities.org" class="neo-Screen-Shot" target="_blank" title="Website of <%= site.username %>">
|
||||
<a href="//<%= site.host %>" class="neo-Screen-Shot" target="_blank" title="<%= site.title %>">
|
||||
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '270x162') %>) no-repeat;">
|
||||
<img src="/img/placeholder.png" alt="<%= site.username %>" />
|
||||
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
||||
</span>
|
||||
</a>
|
||||
<div>
|
||||
<span>
|
||||
<center><a href="http://<%= site.username %>.neocities.org"><%= site.title %></a>
|
||||
<center><a href="//<%= site.host %>" title="<%= site.title %>"><%= site.title.shorten(35) %></a>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -36,13 +36,15 @@
|
|||
</div>
|
||||
|
||||
<div class="col col-50">
|
||||
<h2 class="eps">My Website</h2>
|
||||
<p class="site-url" style="margin-top: -9px;"><a href="http://<%= current_site.username %>.neocities.org" target="_blank">http://<%= current_site.username %>.neocities.org</a></p>
|
||||
<h2 class="eps"><%= current_site.title %></h2>
|
||||
<p class="site-url" style="margin-top: -9px;"><a href="//<%= current_site.host %>" target="_blank"><%= current_site.host %></a></p>
|
||||
<ul>
|
||||
<% if current_site.updated_at %>
|
||||
<li>Last updated <%= current_site.updated_at.ago.downcase %></li>
|
||||
<% end %>
|
||||
<li>Using <strong><%= current_site.space_percentage_used %>% (<%= current_site.used_space_in_megabytes %>MB) of your <%= current_site.maximum_space_in_megabytes %> MB</strong>. <% if !current_site.supporter? %>Need more space? <a href="/plan">Become a Supporter!</a><% end %></li>
|
||||
<li>Using <strong><%= current_site.space_percentage_used %>% (<%= current_site.used_space_in_megabytes %>MB) of your <%= current_site.maximum_space_in_megabytes %> MB</strong>.
|
||||
<br>
|
||||
<% if !current_site.supporter? %>Need more space? <a href="/plan">Become a Supporter!</a><% end %></li>
|
||||
<li><strong><%= current_site.hits.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %></strong> hits</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<% @suggestions.each do |suggested_site| %>
|
||||
<div class="site-suggestion">
|
||||
<div class="site-portrait">
|
||||
<a href="http://<%= suggested_site.username %>.neocities.org">
|
||||
<a href="//<%= suggested_site.host %>">
|
||||
<img src="<%= suggested_site.screenshot_url('index.html', '270x162') %>">
|
||||
</a>
|
||||
<span class="caption">
|
||||
|
@ -49,7 +49,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col col-33">
|
||||
<p class="site-url"><a href="//<%= current_site.username %>.neocities.org" target="_blank"><%= site.username %>.neocities.org</a></p>
|
||||
<p class="site-url"><a href="//<%= current_site.host %>" target="_blank"><%= site.title %></a></p>
|
||||
<div class="stats">
|
||||
<div class="col col-50">
|
||||
<% if site.updated_at %>
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
<div class="col col-50 signup-Area large">
|
||||
<div class="signup-Form">
|
||||
<fieldset class="content">
|
||||
<a href="http://<%= site.username %>.neocities.org"><img class="screenshot" src="<%= site.screenshot_url('index.html', '348x205') %>" style="width: 358px;height: 215px;"></a>
|
||||
<a href="//<%= site.host %>"><img class="screenshot" src="<%= site.screenshot_url('index.html', '348x205') %>" style="width: 358px;height: 215px;"></a>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-50">
|
||||
<h2 class="eps title-with-badge"><span><%= site.title %></span> <% if site.supporter? && !site.ended_supporter? %><a href="/plan" class="supporter-badge" title="Neocities Supporter"></a> <% end %></h2>
|
||||
<p class="site-url"><a href="http://<%= site.username %>.neocities.org">http://<%= site.username %>.neocities.org</a></p>
|
||||
<p class="site-url"><a href="//<%= site.host %>"><%= site.host %></a></p>
|
||||
<div class="stats">
|
||||
<div class="stat"><strong><%= site.hits_english %></strong> <span>hits</span></div>
|
||||
<div class="stat"><strong><%= site.follows_dataset.count %></strong> <span>followers</span></div>
|
||||
|
@ -43,19 +43,19 @@
|
|||
|
||||
<a href="/site/<%= site.username %>.rss"><span>RSS/Atom Feed</span></a>
|
||||
<br>
|
||||
<a href="http://facebook.com/sharer.php?u=<%= Rack::Utils.build_query(u: "http://#{site.username}.neocities.org") %>" target="_blank">Facebook</a>
|
||||
<a href="http://facebook.com/sharer.php?u=<%= Rack::Utils.build_query(u: "http://#{site.host}") %>" target="_blank">Facebook</a>
|
||||
<br>
|
||||
<a href="https://twitter.com/intent/tweet?<%= Rack::Utils.build_query(text: "This site is awesome: http://#{site.username}.neocities.org") %>">Twitter</a>
|
||||
<a href="https://twitter.com/intent/tweet?<%= Rack::Utils.build_query(text: "#{site.title}: http://#{site.host}") %>">Twitter</a>
|
||||
<br>
|
||||
<a href="http://www.reddit.com/submit?<%= Rack::Utils.build_query(title: "#{site.username}.neocities.org", url: "http://#{site.username}.neocities.org" )%>" target="_blank">Reddit</a>
|
||||
<a href="http://www.reddit.com/submit?<%= Rack::Utils.build_query(title: "#{site.title}", url: "http://#{site.host}" )%>" target="_blank">Reddit</a>
|
||||
<br>
|
||||
<a href="http://www.tumblr.com/share?<%= Rack::Utils.build_query(v: 3, u: "http://#{site.username}.neocities.org", t: "#{site.username}.neocities.org") %>" target="_blank">Tumblr</a>
|
||||
<a href="http://www.tumblr.com/share?<%= Rack::Utils.build_query(v: 3, u: "http://#{site.host}", t: "#{site.title}") %>" target="_blank">Tumblr</a>
|
||||
<br>
|
||||
<a href="http://www.stumbleupon.com/submit?<%= Rack::Utils.build_query(url: "http://#{site.username}.neocities.org", title: "#{site.username}.neocities.org") %>" target="_blank">StumbleUpon</a>
|
||||
<a href="http://www.stumbleupon.com/submit?<%= Rack::Utils.build_query(url: "http://#{site.host}", title: "#{site.title}") %>" target="_blank">StumbleUpon</a>
|
||||
<br>
|
||||
<a href="http://del.icio.us/post?<%= Rack::Utils.build_query(url: "http://#{site.username}.neocities.org", title: "#{site.username}.neocities.org") %>" target="_blank">Del.ici.ous</a>
|
||||
<a href="http://del.icio.us/post?<%= Rack::Utils.build_query(url: "http://#{site.host}", title: "#{site.title}") %>" target="_blank">Del.ici.ous</a>
|
||||
<br>
|
||||
<a href="https://plus.google.com/share?<%= Rack::Utils.build_query(url: "http://#{site.username}.neocities.org") %>" target="_blank">Google+</a>
|
||||
<a href="https://plus.google.com/share?<%= Rack::Utils.build_query(url: "http://#{site.host}") %>" target="_blank">Google+</a>
|
||||
'>
|
||||
<span>Share</span></a>
|
||||
</div>
|
||||
|
@ -115,7 +115,7 @@
|
|||
<% if site != current_site %>
|
||||
<div class="report">
|
||||
<a href="#report" data-toggle="modal">Report</a> |
|
||||
<% if current_site.is_blocking?(site) %>
|
||||
<% if current_site && current_site.is_blocking?(site) %>
|
||||
<a href="#">Unblock</a>
|
||||
<% else %>
|
||||
<a href="#block" data-toggle="modal">Block</a>
|
||||
|
|
Loading…
Add table
Reference in a new issue