Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitemap & Google Scholar #379

Merged
merged 23 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d14445
Add a basic cached sitemap. Some work remaining to flesh it out
mbarnett Dec 20, 2017
408bd63
Make rubocop happy
mbarnett Dec 20, 2017
5f4d25a
Cleanup
mbarnett Dec 20, 2017
518dcb7
sitemap doesn't need to have a policy, it's always public!
pgwillia Jan 10, 2018
257aa21
sitemap should only show public items
pgwillia Jan 10, 2018
d25bdd6
add sitemap to robots.txt
pgwillia Jan 10, 2018
7cdb9d2
Replaced placeholder with updated_at now indexed in Solr
pgwillia Jan 11, 2018
8a9990f
ResourceSync [http://www.openarchives.org/rs/1.1/]
pgwillia Jan 15, 2018
6523939
https://scholar.google.ca/intl/en/scholar/inclusion.html#indexing
pgwillia Jan 15, 2018
bef291d
Merge branch 'master' into sitemap
pgwillia Jan 17, 2018
5a9dfa6
Update Google Scholar metadata & sitemap to accomodate Thesis
pgwillia Jan 17, 2018
dd8aaca
sitemap should contain less than 50,000 targets
pgwillia Jan 17, 2018
0c54ebf
WIP - notes from review and tests
pgwillia Jan 24, 2018
9617268
Merge branch 'master' into sitemap
pgwillia Jan 25, 2018
52b6f91
test that demonstrates that where visibility is not working as expected
pgwillia Jan 25, 2018
cbc98e6
Merge remote-tracking branch 'matt/composable_queries' into sitemap
pgwillia Jan 25, 2018
a2d6bf8
Make robots.txt dynamic based on ENV['RAILS_ALLOW_CRAWLERS']
pgwillia Jan 25, 2018
508dfcc
move visibility constraints test to eliminate test order issues
pgwillia Jan 25, 2018
fac6395
finish sitemap testing
pgwillia Jan 26, 2018
09e4ec4
Merge branch 'master' into sitemap
pgwillia Jan 29, 2018
c1b3344
fix test from upstream change
pgwillia Jan 29, 2018
56e4d7e
learning about rails conventions
pgwillia Jan 29, 2018
bb89c15
Merge branch 'master' into sitemap
pgwillia Jan 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ group :development, :test do
gem 'sdoc', require: false

gem 'capybara', '~> 2.17'
gem 'nokogiri'
gem 'selenium-webdriver', require: false

gem 'pry'
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
minitest-hooks
mysql2 (>= 0.3.18, < 0.5)
nokogiri
omniauth
omniauth-saml
pry
Expand Down Expand Up @@ -446,4 +447,4 @@ DEPENDENCIES
wicked

BUNDLED WITH
1.16.0
1.16.1
10 changes: 10 additions & 0 deletions app/controllers/robots_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class RobotsController < ApplicationController

skip_after_action :verify_authorized

def robots
respond_to :text
expires_in 6.hours, public: true
end

end
28 changes: 28 additions & 0 deletions app/controllers/sitemap_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class SitemapController < ApplicationController

skip_after_action :verify_authorized

def index; end

def communities
@communities = Community.all
# TODO: consider using Rollbar to catch this kind of thing
logger.warn 'communities sitemap should contain less than 50,000 targets' if @communities.count > 50_000
end

def collections
@collections = Collection.all
logger.warn 'collections sitemap should contain less than 50,000 targets' if @collections.count > 50_000
end

def items
@items = Item.public
logger.warn 'items sitemap should contain less than 50,000 targets' if @items.count > 50_000
end

def theses
@theses = Thesis.public
logger.warn 'thesis sitemap should contain less than 50,000 targets' if @theses.count > 50_000
end

end
5 changes: 5 additions & 0 deletions app/helpers/items_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ def license_link(license)
text ||= license
link_to(text, license)
end

def authors(object)
return [object.dissertant] if object.respond_to? :dissertant
return object.creators if object.respond_to? :creators
end
end
18 changes: 18 additions & 0 deletions app/models/concerns/item_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ def add_files(files)
else
File.basename(file)
end
# Store file properties in the format required by the sitemap
# for quick and easy retrieval -- nobody wants to wait 36hrs for this!
unlocked_fileset.sitemap_link = "<rs:ln \
href=\"#{Rails.application.routes.url_helpers.url_for(controller: :file_sets,
action: :download,
id: unlocked_fileset.id,
file_name: unlocked_fileset.contained_filename,
only_path: true)}\" \
rel=\"content\" \
hash=\"#{unlocked_fileset.original_file.checksum.algorithm.downcase}:"\
"#{unlocked_fileset.original_file.checksum.value}\" \
length=\"#{unlocked_fileset.original_file.size}\" \
type=\"#{unlocked_fileset.original_file.mime_type}\"\
/>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than have to escape all of these newlines, this is probably a great use-case for a heredoc: https://infinum.co/the-capsized-eight/multiline-strings-ruby-2-3-0-the-squiggly-heredoc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually more like a run-on sentence situation. There should be no newlines or extra spaces/tabs between the values. My understanding is that heredoc would maintain newlines. Is there a solution to make something like that more readable?

unlocked_fileset.save!
self.members += [unlocked_fileset]
# pull in hydra derivatives, set temp file base
Expand All @@ -134,6 +148,10 @@ def display_attribute_names
def valid_visibilities
super + [VISIBILITY_EMBARGO]
end

def public
where(visibility: JupiterCore::VISIBILITY_PUBLIC)
end
end

def doi_url
Expand Down
1 change: 1 addition & 0 deletions app/models/file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class FileSet < JupiterCore::LockedLdpObject
ldp_object_includes Hydra::Works::FileSetBehavior

has_attribute :contained_filename, ::RDF::Vocab::DC.title, solrize_for: :exact_match
has_attribute :sitemap_link, ::TERMS[:ual].sitemap_link, solrize_for: :exact_match

belongs_to :item, using_existing_association: :member_of_collections

Expand Down
13 changes: 13 additions & 0 deletions app/views/items/_google_scholar_metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Google Scholar metadata -->
<meta name="citation_title" content="<%= @item.title%>"/>
<% authors(@item).each do |author| %>
<meta name="citation_author" content="<%= author %>"/>
<% end %>
<% if @item.sort_year.present? %>
<meta name="citation_publication_date" content="<%= @item.sort_year %>"/>
<% end %>
<% if @item.file_sets.count > 0 %>
<meta name="citation_pdf_url" content="<%= fileset_uri(@item.file_sets.first, :download) %>"/>
<% end %>
<meta name="dc.identifier" content="<%= @item.doi %>"/>
<meta name="citation_doi" content="<%= @item.doi %>"/>
4 changes: 4 additions & 0 deletions app/views/items/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% content_for :head do %>
<%= render partial: 'google_scholar_metadata' %>
<% end %>

<% page_title(@item.title) %>

<%# Breadcrumbs here are for 'Home->Search->Item' %>
Expand Down
7 changes: 7 additions & 0 deletions app/views/robots/robots.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
Sitemap: https://era.library.ualberta.ca/sitemap.xml

<% unless Rails.configuration.allow_crawlers %>
User-agent: *
Disallow: /
<% end %>
27 changes: 27 additions & 0 deletions app/views/sitemap/_object.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
xml.instruct! :xml, version: '1.0'
cache 'sitemap', expires_in: 24.hours do
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',
'xmlns:rs' => 'http://www.openarchives.org/rs/terms/') do
xml.rs :md, capability: 'resourcelist', at: Time.current.iso8601
xml.url do
xml.loc root_url
xml.lastmod Time.current.iso8601
xml.changefreq 'weekly'
xml.priority 1
xml.rs :md, type: 'text/html'
end

objects.each do |object|
xml.url do
xml.loc item_url(object)
xml.lastmod object.updated_at
xml.changefreq 'weekly'
xml.priority 1
xml.rs :md, type: 'text/html'
object.file_sets.each do |file_set|
xml << "\t#{file_set.sitemap_link}\n"
end
end
end
end
end
20 changes: 20 additions & 0 deletions app/views/sitemap/collections.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
xml.instruct! :xml, version: '1.0'
cache 'sitemap', expires_in: 24.hours do
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do
xml.url do
xml.loc root_url
xml.lastmod Time.current.utc.iso8601
xml.changefreq 'weekly'
xml.priority 1
end

@collections.each do |collection|
xml.url do
xml.loc community_collection_url(collection.community, collection)
xml.lastmod collection.updated_at
xml.changefreq 'weekly'
xml.priority 1
end
end
end
end
20 changes: 20 additions & 0 deletions app/views/sitemap/communities.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
xml.instruct! :xml, version: '1.0'
cache 'sitemap', expires_in: 24.hours do
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do
xml.url do
xml.loc root_url
xml.lastmod Time.current.utc.iso8601
xml.changefreq 'weekly'
xml.priority 1
end

@communities.each do |community|
xml.url do
xml.loc community_url(community)
xml.lastmod community.updated_at
xml.changefreq 'weekly'
xml.priority 1
end
end
end
end
8 changes: 8 additions & 0 deletions app/views/sitemap/index.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
xml.instruct! :xml, version: '1.0'
xml.sitemapindex xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9' do
[:items, :theses, :collections, :communities].each do |category|
xml.sitemap do
xml.loc url_for(action: category, controller: 'sitemap', only_path: false)
end
end
end
1 change: 1 addition & 0 deletions app/views/sitemap/items.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xml << render(partial: 'object', locals: { objects: @items })
1 change: 1 addition & 0 deletions app/views/sitemap/theses.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xml << render(partial: 'object', locals: { objects: @theses })
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ class Application < Rails::Application
# Run skylight in UAT for performance metric monitoring pre-launch
config.skylight.environments += ['uat']

# we can tell crawlers to go away during the beta launch phase
config.allow_crawlers = ENV['RAILS_ALLOW_CRAWLERS'].present?

end
end
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,14 @@
mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new
end

get 'sitemap.xml', to: 'sitemap#index', defaults: { format: :xml }, as: :sitemapindex
get 'sitemap-communities.xml', to: 'sitemap#communities', defaults: { format: :xml }, as: :communities_sitemap
get 'sitemap-collections.xml', to: 'sitemap#collections', defaults: { format: :xml }, as: :collections_sitemap
get 'sitemap-items.xml', to: 'sitemap#items', defaults: { format: :xml }, as: :items_sitemap
get 'sitemap-theses.xml', to: 'sitemap#theses', defaults: { format: :xml }

# Dynamic robots.txt
get 'robots.txt' => 'robots#robots'

root to: 'welcome#index'
end
1 change: 0 additions & 1 deletion public/robots.txt

This file was deleted.

Loading