Skip to content

Commit

Permalink
Merge pull request #2 from dartmouth-dltg/static-pages
Browse files Browse the repository at this point in the history
Static pages
  • Loading branch information
jdshaw authored Nov 27, 2019
2 parents fa291ac + a1b810b commit 3b16f94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions backend/job_runners/aspace_sitemap_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run
@sitemap_types = @json.job['sitemap_types'].reject{|st| !AppConfig[:allowed_sitemap_types_hash].keys.include?(st)}

# setup some of our other variables
@use_slugs = AppConfig[:use_human_readable_urls] ? @json.job['sitemap_use_slugs'] : false
@use_slugs = AppConfig.has_key?(:use_human_readable_urls) && AppConfig[:use_human_readable_urls] ? @json.job['sitemap_use_slugs'] : false
default_limit = AppConfig[:aspace_sitemap_default_limit]
sitemap_limit = @json.job['sitemap_limit'].to_i
sitemap_index_base_url = @json.job['sitemap_baseurl']
Expand All @@ -26,10 +26,15 @@ def run
sitemap_index_base_url.prepend('https://')
end
refresh_freq = @json.job['sitemap_refresh_freq']
@pui_base_url = AppConfig[:public_proxy_url]
# make sure the public url ends in a "/"
unless @pui_base_url[-1] == "/"
@pui_base_url += "/"
end

# muck about with paths and filenames depending on if we are writing to the filesystem
index_filename = "aspace_sitemap_index"
sitemap_index_loc = @json.job['sitemap_use_filesys'] ? "#{AppConfig[:public_proxy_url]}/static/html/" : sitemap_index_base_url
sitemap_index_loc = @json.job['sitemap_use_filesys'] ? "#{@pui_base_url}static/html/" : sitemap_index_base_url
static_page_loc = "#{ASUtils.find_local_directories(nil, 'aspace_sitemap').shift}/public/pages/"
sitemap_filename_prefix = "aspace_sitemap_part_"

Expand Down Expand Up @@ -61,6 +66,12 @@ def run
@job.write_output('No published objects found. No sitemap generated.')
return
end

# explicitly add some 'static' pages - like the homepage!
static_pages = ["","search?reset=true"]
static_pages.each do |sp|
array.push({:loc => "#{@pui_base_url}"+sp, :lastmod => Time.now.strftime("%Y-%m-%d")})
end

# split the results set into chunks of less than the sitemap entry limit
sitemap_parts = array.each_slice(sitemap_limit).to_a
Expand Down Expand Up @@ -158,13 +169,13 @@ def fix_row(row)
if ['people','families','corporate_entities','software'].include?(row[:source])
row[:source] = "agents"
end
row[:loc] = ["#{AppConfig[:public_proxy_url]}",row[:source],row[:slug]].join("/")
row[:loc] = ["#{@pui_base_url.chop}",row[:source],row[:slug]].join("/")
else
# agents have a different location string pattern
if ['people','families','corporate_entities','software'].include?(row[:source])
row[:loc] = ["#{AppConfig[:public_proxy_url]}","agents",row[:source],row[:id]].join("/")
row[:loc] = ["#{@pui_base_url.chop}","agents",row[:source],row[:id]].join("/")
else
row[:loc] = ["#{AppConfig[:public_proxy_url]}","repositories",row[:repo_id],row[:source],row[:id]].join("/")
row[:loc] = ["#{@pui_base_url.chop}","repositories",row[:repo_id],row[:source],row[:id]].join("/")
end
end

Expand Down
2 changes: 1 addition & 1 deletion frontend/views/aspace_sitemap_job/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<span class="help-block"><%= t('aspace_sitemap_job.sitemap_refresh_freq_help') %></span>
<%= form.label_and_select "sitemap_refresh_freq", AppConfig[:sitemap_frequencies], {:field_opts => {:required => true}} %>
</div>
<% if AppConfig.has_key?(:use_human_readable_urls) %>
<% if AppConfig.has_key?(:use_human_readable_urls) && AppConfig[:use_human_readable_urls] %>
<div class="form-group">
<span class="help-block"><%= t('aspace_sitemap_job.sitemap_use_slugs_help') %></span>
<%= form.label_and_boolean "sitemap_use_slugs" %>
Expand Down
2 changes: 1 addition & 1 deletion frontend/views/aspace_sitemap_job/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<label class="col-sm-3 control-label"><%= I18n.t("aspace_sitemap_job.sitemap_refresh_freq") %></label>
<div class="col-sm-9 controls label-only"><%= job['sitemap_refresh_freq'] %></div>
</div>
<% if AppConfig.has_key?(:use_human_readable_urls) %>
<% if AppConfig.has_key?(:use_human_readable_urls) && AppConfig[:use_human_readable_urls] %>
<div class="form-group">
<label class="col-sm-3 control-label"><%= I18n.t("aspace_sitemap_job.sitemap_use_slugs") %></label>
<div class="col-sm-9 controls label-only"><%= job['sitemap_use_slugs'] %></div>
Expand Down

0 comments on commit 3b16f94

Please sign in to comment.