Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
5b813e73
Unverified
Commit
5b813e73
authored
May 10, 2018
by
Robert Knight
Committed by
GitHub
May 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #732 from hypothesis/fix-document-metadata-tests-in-chrome
Fix document metadata tests in chrome
parents
6869a2fe
d98aff1a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
25 deletions
+31
-25
document.coffee
src/annotator/plugin/document.coffee
+15
-20
document-test.coffee
src/annotator/plugin/test/document-test.coffee
+16
-5
No files found.
src/annotator/plugin/document.coffee
View file @
5b813e73
$
=
require
(
'jquery'
)
baseURI
=
require
(
'document-base-uri'
)
baseURI
=
require
(
'document-base-uri'
)
Plugin
=
require
(
'../plugin'
)
Plugin
=
require
(
'../plugin'
)
...
@@ -28,8 +27,7 @@ module.exports = class Document extends Plugin
...
@@ -28,8 +27,7 @@ module.exports = class Document extends Plugin
this
.
getDocumentMetadata
()
this
.
getDocumentMetadata
()
# returns the primary URI for the document being annotated
# Returns the primary URI for the document being annotated
uri
:
=>
uri
:
=>
uri
=
decodeURIComponent
(
this
.
_getDocumentHref
())
uri
=
decodeURIComponent
(
this
.
_getDocumentHref
())
for
link
in
@
metadata
.
link
for
link
in
@
metadata
.
link
...
@@ -37,8 +35,7 @@ module.exports = class Document extends Plugin
...
@@ -37,8 +35,7 @@ module.exports = class Document extends Plugin
uri
=
link
.
href
uri
=
link
.
href
return
uri
return
uri
# returns all uris for the document being annotated
# Returns all uris for the document being annotated
uris
:
=>
uris
:
=>
uniqueUrls
=
{}
uniqueUrls
=
{}
for
link
in
@
metadata
.
link
for
link
in
@
metadata
.
link
...
@@ -87,9 +84,9 @@ module.exports = class Document extends Plugin
...
@@ -87,9 +84,9 @@ module.exports = class Document extends Plugin
_getMetaTags
:
(
prefix
,
attribute
,
delimiter
)
=>
_getMetaTags
:
(
prefix
,
attribute
,
delimiter
)
=>
tags
=
{}
tags
=
{}
for
meta
in
$
(
"meta"
)
for
meta
in
@
document
.
querySelectorAll
(
'meta'
)
name
=
$
(
meta
).
attr
(
attribute
)
name
=
meta
.
getAttribute
(
attribute
)
content
=
$
(
meta
).
prop
(
"content"
)
content
=
meta
.
content
if
name
if
name
match
=
name
.
match
(
RegExp
(
"^
#{
prefix
}#{
delimiter
}
(.+)$"
,
"i"
))
match
=
name
.
match
(
RegExp
(
"^
#{
prefix
}#{
delimiter
}
(.+)$"
,
"i"
))
if
match
if
match
...
@@ -114,24 +111,23 @@ module.exports = class Document extends Plugin
...
@@ -114,24 +111,23 @@ module.exports = class Document extends Plugin
else
if
@
metadata
.
dc
.
title
else
if
@
metadata
.
dc
.
title
@
metadata
.
title
=
@
metadata
.
dc
.
title
[
0
]
@
metadata
.
title
=
@
metadata
.
dc
.
title
[
0
]
else
else
@
metadata
.
title
=
$
(
"head title"
).
text
()
@
metadata
.
title
=
@
document
.
title
_getLinks
:
=>
_getLinks
:
=>
# we know our current location is a link for the document
# we know our current location is a link for the document
@
metadata
.
link
=
[
href
:
this
.
_getDocumentHref
()]
@
metadata
.
link
=
[
href
:
this
.
_getDocumentHref
()]
# look for some relevant link relations
# look for some relevant link relations
for
link
in
$
(
"link"
)
for
link
in
@
document
.
querySelectorAll
(
'link'
)
l
=
$
(
link
)
href
=
this
.
_absoluteUrl
(
link
.
href
)
# get absolute url
href
=
this
.
_absoluteUrl
(
l
.
prop
(
'href'
))
# get absolute url
rel
=
link
.
rel
rel
=
l
.
prop
(
'rel'
)
type
=
link
.
type
type
=
l
.
prop
(
'type'
)
lang
=
link
.
hreflang
lang
=
l
.
prop
(
'hreflang'
)
if
rel
not
in
[
"alternate"
,
"canonical"
,
"bookmark"
,
"shortlink"
]
then
continue
if
rel
not
in
[
"alternate"
,
"canonical"
,
"bookmark"
,
"shortlink"
]
then
continue
if
rel
is
'alternate'
if
rel
is
'alternate'
# Ignore feeds resources
# Ignore feeds resources
if
type
and
type
.
match
/^application\/(rss|atom)\+xml/
then
continue
if
type
and
type
.
match
/^application\/(rss|atom)\+xml/
then
continue
# Ignore alternate languages
# Ignore alternate languages
if
lang
then
continue
if
lang
then
continue
...
@@ -150,7 +146,6 @@ module.exports = class Document extends Plugin
...
@@ -150,7 +146,6 @@ module.exports = class Document extends Plugin
# kind of a hack to express DOI identifiers as links but it's a
# kind of a hack to express DOI identifiers as links but it's a
# convenient place to look them up later, and somewhat sane since
# convenient place to look them up later, and somewhat sane since
# they don't have a type
# they don't have a type
if
name
==
"doi"
if
name
==
"doi"
for
doi
in
values
for
doi
in
values
if
doi
[
0
..
3
]
!=
"doi:"
if
doi
[
0
..
3
]
!=
"doi:"
...
@@ -180,8 +175,8 @@ module.exports = class Document extends Plugin
...
@@ -180,8 +175,8 @@ module.exports = class Document extends Plugin
@
metadata
.
documentFingerprint
=
dcUrn
@
metadata
.
documentFingerprint
=
dcUrn
_getFavicon
:
=>
_getFavicon
:
=>
for
link
in
$
(
"link"
)
for
link
in
@
document
.
querySelectorAll
(
'link'
)
if
$
(
link
).
prop
(
"rel"
)
in
[
"shortcut icon"
,
"icon"
]
if
link
.
rel
in
[
"shortcut icon"
,
"icon"
]
@
metadata
[
"favicon"
]
=
this
.
_absoluteUrl
(
link
.
href
)
@
metadata
[
"favicon"
]
=
this
.
_absoluteUrl
(
link
.
href
)
# Hack to get a absolute url from a possibly relative one
# Hack to get a absolute url from a possibly relative one
...
...
src/annotator/plugin/test/document-test.coffee
View file @
5b813e73
...
@@ -173,9 +173,19 @@ describe 'Document', ->
...
@@ -173,9 +173,19 @@ describe 'Document', ->
if
canonicalLink
if
canonicalLink
canonicalLink
.
remove
()
canonicalLink
.
remove
()
createDoc
=
(
href
,
baseURI
)
->
# Create a blank HTML document with a faked `href` and `baseURI` and
# return a `Document` instance which reads metadata from it.
createDoc
=
(
href
,
baseURI
,
htmlDoc
)
->
if
!
htmlDoc
# Create a blank DOM Document
htmlDoc
=
document
.
implementation
.
createHTMLDocument
()
# `Document.location` is not overridable. In order to fake the
# location in tests, create a proxy object in front of our blank HTML
# document.
fakeDocument
=
fakeDocument
=
createElement
:
document
.
createElement
.
bind
(
document
),
createElement
:
htmlDoc
.
createElement
.
bind
(
htmlDoc
),
querySelectorAll
:
htmlDoc
.
querySelectorAll
.
bind
(
htmlDoc
),
location
:
location
:
href
:
href
href
:
href
doc
=
new
Document
(
$
(
'<div></div>'
)[
0
],
{
doc
=
new
Document
(
$
(
'<div></div>'
)[
0
],
{
...
@@ -215,11 +225,12 @@ describe 'Document', ->
...
@@ -215,11 +225,12 @@ describe 'Document', ->
assert
.
equal
(
doc
.
uri
(),
href
)
assert
.
equal
(
doc
.
uri
(),
href
)
it
'returns the canonical URI if present'
,
->
it
'returns the canonical URI if present'
,
->
canonicalLink
=
document
.
createElement
(
'link'
)
htmlDoc
=
document
.
implementation
.
createHTMLDocument
()
canonicalLink
=
htmlDoc
.
createElement
(
'link'
)
canonicalLink
.
rel
=
'canonical'
canonicalLink
.
rel
=
'canonical'
canonicalLink
.
href
=
'https://publisher.org/canonical'
canonicalLink
.
href
=
'https://publisher.org/canonical'
document
.
head
.
appendChild
(
canonicalLink
)
htmlDoc
.
head
.
appendChild
(
canonicalLink
)
doc
=
createDoc
(
'https://publisher.org/not-canonical'
,
null
)
doc
=
createDoc
(
'https://publisher.org/not-canonical'
,
null
,
htmlDoc
)
assert
.
equal
doc
.
uri
(),
canonicalLink
.
href
assert
.
equal
doc
.
uri
(),
canonicalLink
.
href
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment