DRY up file uri / index stuff a bit

This commit is contained in:
Kyle Drake 2019-10-07 15:39:25 -07:00
parent 18041d4d28
commit 4d27f625f1
2 changed files with 24 additions and 17 deletions

View file

@ -67,6 +67,8 @@ class Site < Sequel::Model
LOSSLESS_IMAGE_REGEX = /png|bmp|gif/ LOSSLESS_IMAGE_REGEX = /png|bmp|gif/
LOSSY_IMAGE_REGEX = /jpg|jpeg/ LOSSY_IMAGE_REGEX = /jpg|jpeg/
HTML_REGEX = /.html$|.htm$/ HTML_REGEX = /.html$|.htm$/
INDEX_HTML_REGEX = /\/?index.html$/
ROOT_INDEX_HTML_REGEX = /^\/?index.html$/
MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED). MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED).
SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50'] SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50']
@ -1383,6 +1385,11 @@ class Site < Sequel::Model
"#{default_schema}://#{host}" "#{default_schema}://#{host}"
end end
def file_uri(path)
path = '/' + path unless path[0] == '/'
uri + (path =~ ROOT_INDEX_HTML_REGEX ? '/' : path)
end
def title def title
begin begin
if values[:title].blank? || values[:title].strip.empty? if values[:title].blank? || values[:title].strip.empty?
@ -1527,7 +1534,7 @@ class Site < Sequel::Model
end end
def empty_index? def empty_index?
!site_files_dataset.where(path: /^\/?index.html$/).where(sha1_hash: EMPTY_FILE_HASH).first.nil? !site_files_dataset.where(path: ROOT_INDEX_HTML_REGEX).where(sha1_hash: EMPTY_FILE_HASH).first.nil?
end end
def tipping_enabled? def tipping_enabled?

View file

@ -159,7 +159,7 @@
<% if file[:is_directory] %> <% if file[:is_directory] %>
<a class="link-overlay" href="?dir=<%= Rack::Utils.escape file[:path] %>" title="View <%= file[:path] %>"></a> <a class="link-overlay" href="?dir=<%= Rack::Utils.escape file[:path] %>" title="View <%= file[:path] %>"></a>
<% else %> <% else %>
<a class="link-overlay" href="https://<%= current_site.username %>.neocities.org<%= file[:path] == '/index.html' ? '/' : file[:path] %>" title="View <%= file[:path] == '/index.html' ? 'your site' : file[:path] %>" target="_blank"></a> <a class="link-overlay" href="<%= current_site.file_uri file[:path] %>" title="View <%= file[:path] == '/index.html' ? 'your site index' : file[:path] %>" target="_blank"></a>
<% end %> <% end %>
</div> </div>
</div> </div>