Skip to content

Commit

Permalink
WIP - notes from review and tests
Browse files Browse the repository at this point in the history
one failing bc Item.public is returning private items.
  • Loading branch information
pgwillia committed Jan 24, 2018
1 parent dd8aaca commit 7497c12
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 23 deletions.
11 changes: 6 additions & 5 deletions app/controllers/sitemap_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ def index; end

def communities
@communities = Community.all
raise 'sitemap should contain less than 50,000 targets' if @communities.count > 50_000
# 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
raise 'sitemap should contain less than 50,000 targets' if @collections.count > 50_000
logger.warn 'collections sitemap should contain less than 50,000 targets' if @collections.count > 50_000
end

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

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

end
2 changes: 1 addition & 1 deletion app/models/concerns/item_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def valid_visibilities
end

def public
Item.where(visibility: JupiterCore::VISIBILITY_PUBLIC)
self.where(visibility: JupiterCore::VISIBILITY_PUBLIC)
end
end

Expand Down
8 changes: 0 additions & 8 deletions app/views/items/_google_scholar_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@
<% end %>
<meta name="dc.identifier" content="<%= @item.doi %>"/>
<meta name="citation_doi" content="<%= @item.doi %>"/>
<!-- does not support these metadata -->
<!--
<meta name="citation_journal_title" content=""/>
<meta name="citation_volume" content=""/>
<meta name="citation_issue" content=""/>
<meta name="citation_firstpage" content=""/>
<meta name="citation_lastpage" content=""/>
-->
7 changes: 4 additions & 3 deletions app/views/sitemap/_object.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ 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.utc.iso8601
xml.rs :md, capability: 'resourcelist', at: Time.current.iso8601
xml.url do
xml.loc root_url
xml.lastmod Time.current.utc.iso8601
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.lastmod object.updated_at
xml.rs :md, type: 'text/html'
object.file_sets.each do |file_set|
xml << "\t#{file_set.sitemap_link}\n"
Expand Down
2 changes: 1 addition & 1 deletion app/views/sitemap/collections.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ cache 'sitemap', expires_in: 24.hours do
@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
xml.lastmod collection.updated_at
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/sitemap/communities.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ cache 'sitemap', expires_in: 24.hours do
@communities.each do |community|
xml.url do
xml.loc community_url(community)
xml.lastmod community.updated_at
xml.changefreq 'weekly'
xml.priority 1
xml.lastmod community.updated_at
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new
end

get 'sitemap.xml', to: 'sitemap#index', defaults: { format: :xml }
get 'sitemap-communities.xml', to: 'sitemap#communities', defaults: { format: :xml }
get 'sitemap-collections.xml', to: 'sitemap#collections', defaults: { format: :xml }
get 'sitemap-items.xml', to: 'sitemap#items', defaults: { format: :xml }
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 }
root to: 'welcome#index'
end
147 changes: 147 additions & 0 deletions test/controllers/resourcesync.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.openarchives.org/rs/terms/" xmlns="http://www.openarchives.org/rs/terms/" elementFormDefault="qualified">

<xsd:annotation>
<xsd:documentation>
XML Schema for ResoureSync extensions to Sitemap files.
See: http://www.openarchives.org/rs/ .
2013-01-06 first stab [Simeon Warner],
2013-08-15 for v0.9.1, v1.0 [Simeon Warner],
2016-04-26 for v1.1 [Simeon Warner].
</xsd:documentation>
</xsd:annotation>

<xsd:element name="md">
<xsd:annotation>
<xsd:documentation>
Metadata about a resource
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:attribute name="at" type="xsd:dateTime"/>
<xsd:attribute name="capability" type="xsd:string"/>
<xsd:attribute name="change" type="changeType"/>
<xsd:attribute name="completed" type="xsd:dateTime"/>
<xsd:attribute name="datetime" type="xsd:dateTime"/>
<xsd:attribute name="encoding" type="xsd:string"/>
<xsd:attribute name="from" type="xsd:dateTime"/>
<xsd:attribute name="hash" type="xsd:string"/>
<xsd:attribute name="length" type="xsd:integer"/>
<xsd:attribute name="modified" type="xsd:dateTime"/>
<xsd:attribute name="path" type="pathType"/>
<xsd:attribute name="type" type="contentType"/>
<xsd:attribute name="until" type="xsd:dateTime"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>

<xsd:element name="ln">
<xsd:annotation>
<xsd:documentation>
Links to related resources
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:attribute name="encoding" type="xsd:string"/>
<xsd:attribute name="hash" type="xsd:string"/>
<xsd:attribute name="href" type="xsd:anyURI"/>
<xsd:attribute name="length" type="xsd:nonNegativeInteger"/>
<xsd:attribute name="modified" type="xsd:dateTime"/>
<xsd:attribute name="path" type="pathType"/>
<xsd:attribute name="pri" type="priType"/>
<xsd:attribute name="rel" type="relType"/>
<xsd:attribute name="type" type="contentType"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>

<xsd:simpleType name="changeType">
<xsd:annotation>
<xsd:documentation>
Allowed values of the change attribute are
created, updated, deleted
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="created"/>
<xsd:enumeration value="updated"/>
<xsd:enumeration value="deleted"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="pathType">
<xsd:annotation>
<xsd:documentation>
Path values must start with a slash, must not end with a slash
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="/.*[^/]"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="contentType">
<xsd:annotation>
<xsd:documentation>
MIME Content Types are described in RFCs 2045,2046
http://tools.ietf.org/html/rfc2045
http://tools.ietf.org/html/rfc2046
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[\w-]+/[\w-]+"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="priType">
<xsd:annotation>
<xsd:documentation>
The priority attribute may have values 1 through 999999
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="999999"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="relType">
<xsd:annotation>
<xsd:documentation>
Syntax for link relation values is specified by
http://tools.ietf.org/html/rfc5988 and the relevant
portion is:

# link-param = ( ( "rel" "=" relation-types )
# ...
# relation-type = reg-rel-type | ext-rel-type
# reg-rel-type = LOALPHA *( LOALPHA | DIGIT | "." | "-" )
# ext-rel-type = URI
#

Registered link relations (reg-rel-type) are listed at
http://www.iana.org/assignments/link-relations/link-relations.xhtml
and URIs are allowed for extension (ext-rel-type)
</xsd:documentation>
</xsd:annotation>
<xsd:union>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-z][a-z0-9\.\-]*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType>
<xsd:restriction base="xsd:anyURI"/>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>

</xsd:schema>
72 changes: 72 additions & 0 deletions test/controllers/siteindex.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" elementFormDefault="qualified">
<xsd:annotation>
<xsd:documentation>
XML Schema for Sitemap index files.
Last Modifed 2009-04-08
</xsd:documentation>
</xsd:annotation>

<xsd:element name="sitemapindex">
<xsd:annotation>
<xsd:documentation>
Container for a set of up to 50,000 sitemap URLs.
This is the root element of the XML file.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="strict"/>
<xsd:element name="sitemap" type="tSitemap" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name="tSitemap">
<xsd:annotation>
<xsd:documentation>
Container for the data needed to describe a sitemap.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="loc" type="tLocSitemap"/>
<xsd:element name="lastmod" type="tLastmodSitemap" minOccurs="0"/>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="strict"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="tLocSitemap">
<xsd:annotation>
<xsd:documentation>
REQUIRED: The location URI of a sitemap.
The URI must conform to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt).
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:anyURI">
<xsd:minLength value="12"/>
<xsd:maxLength value="2048"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="tLastmodSitemap">
<xsd:annotation>
<xsd:documentation>
OPTIONAL: The date the document was last modified. The date must conform
to the W3C DATETIME format (http://www.w3.org/TR/NOTE-datetime).
Example: 2005-05-10
Lastmod may also contain a timestamp.
Example: 2005-05-10T17:33:30+08:00
</xsd:documentation>
</xsd:annotation>
<xsd:union>
<xsd:simpleType>
<xsd:restriction base="xsd:date"/>
</xsd:simpleType>
<xsd:simpleType>
<xsd:restriction base="xsd:dateTime"/>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>


</xsd:schema>
Loading

0 comments on commit 7497c12

Please sign in to comment.