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
77038342
Commit
77038342
authored
May 03, 2013
by
Ed Summers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved document metadata extraction which now replaces previous getHref jschannel rpc call
parent
eb9f9a7d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
19 deletions
+139
-19
host.coffee
h/js/host.coffee
+5
-2
document.coffee
h/js/plugin/document.coffee
+125
-6
services.coffee
h/js/services.coffee
+9
-11
No files found.
h/js/host.coffee
View file @
77038342
...
...
@@ -160,8 +160,11 @@ class Annotator.Host extends Annotator
@
drag
.
last
=
null
)
.
bind
(
'getDocumentMetadata'
,
=>
return
@
plugins
.
Document
.
getDocumentMetadata
()
.
bind
(
'getDocumentInfo'
,
=>
return
{
uri
:
@
plugins
.
Document
.
uri
()
metadata
:
@
plugins
.
Document
.
metadata
}
)
scanDocument
:
(
reason
=
"something happened"
)
=>
...
...
h/js/plugin/document.coffee
View file @
77038342
class
Annotator
.
Plugin
.
Document
extends
Annotator
.
Plugin
$
=
Annotator
.
$
events
:
'beforeAnnotationCreated'
:
'beforeAnnotationCreated'
pluginInit
:
->
@
metadata
=
null
this
.
getDocumentMetadata
()
# returns the primary URI for the document being annotated
uri
:
=>
uri
=
decodeURIComponent
document
.
location
.
href
for
link
in
@
metadata
if
link
.
rel
==
"canonical"
uri
=
link
.
href
return
uri
# returns all uris for the document being annotated
uris
:
=>
uniqueUrls
=
{}
for
link
in
@
metadata
.
link
uniqueUrls
[
link
.
href
]
=
true
if
link
.
href
return
(
href
for
href
of
uniqueUrls
)
beforeAnnotationCreated
:
(
annotation
)
=>
if
not
@
metadata
@
metadata
=
this
.
getDocumentMetadata
()
annotation
.
document
=
@
metadata
getDocumentMetadata
:
=>
$
=
jQuery
@
metadata
=
title
:
$
(
"head title"
).
text
()
@
metadata
=
{}
# first look for some common metadata types
# TODO: look for microdata/rdfa?
this
.
_getScholar
()
this
.
_getDublinCore
()
this
.
_getOpenGraph
()
# extract out/normalize some things
this
.
_getTitle
()
this
.
_getLinks
()
return
@
metadata
_getScholar
:
=>
@
metadata
.
scholar
=
{}
for
meta
in
$
(
"meta"
)
name
=
$
(
meta
).
prop
(
"name"
)
content
=
$
(
meta
).
prop
(
"content"
)
if
name
.
match
(
/^citation_/
)
if
@
metadata
.
scholar
[
name
]
@
metadata
.
scholar
[
name
].
push
(
content
)
else
@
metadata
.
scholar
[
name
]
=
[
content
]
_getDublinCore
:
=>
@
metadata
.
dc
=
{}
for
meta
in
$
(
"meta"
)
name
=
$
(
meta
).
prop
(
"name"
)
content
=
$
(
meta
).
prop
(
"content"
)
nameParts
=
name
.
split
(
"."
)
if
nameParts
.
length
==
2
and
nameParts
[
0
]
==
"dc"
n
=
nameParts
[
1
]
if
@
metadata
.
dc
[
n
]
@
metadata
.
dc
[
n
].
push
(
content
)
else
@
metadata
.
dc
[
n
]
=
[
content
]
_getOpenGraph
:
=>
@
metadata
.
og
=
{}
for
meta
in
$
(
"meta"
)
property
=
$
(
meta
).
attr
(
"property"
)
content
=
$
(
meta
).
prop
(
"content"
)
if
property
match
=
property
.
match
(
/^og:(.+)$/
)
if
match
n
=
match
[
1
]
if
@
metadata
.
og
[
n
]
@
metadata
.
og
[
n
].
push
(
content
)
else
@
metadata
.
og
[
n
]
=
[
content
]
_getTitle
:
=>
if
@
metadata
.
scholar
.
citation_title
@
metadata
.
title
=
@
metadata
.
scholar
.
citation_title
[
0
]
else
if
@
metadata
.
dc
.
title
@
metadata
.
title
=
@
metadata
.
dc
.
title
else
@
metadata
.
title
=
$
(
"head title"
).
text
()
_getLinks
:
=>
# we know our current location is a link for the document
@
metadata
.
link
=
[
href
:
document
.
location
.
href
]
# look for some relevant link relations
for
link
in
$
(
"link"
)
l
=
$
(
link
)
href
=
this
.
_absoluteUrl
(
l
.
prop
(
'href'
))
# get absolute url
rel
=
l
.
prop
(
'rel'
)
type
=
l
.
prop
(
'type'
)
if
rel
in
[
"alternate"
,
"canonical"
]
@
metadata
.
link
.
push
(
href
:
href
,
rel
:
rel
,
type
:
type
)
# look for links in scholar metadata
for
name
,
values
of
@
metadata
.
scholar
if
name
==
"citation_pdf_url"
for
url
in
values
@
metadata
.
link
.
push
href
:
this
.
_absoluteUrl
(
url
)
type
:
"application/pdf"
# 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
# they don't have a type
if
name
==
"citation_doi"
for
doi
in
values
if
doi
[
0
..
3
]
!=
"doi:"
doi
=
"doi:"
+
doi
@
metadata
.
link
.
push
(
href
:
doi
)
# look for links in dublincore data
for
name
,
values
of
@
metadata
.
dc
if
name
==
"identifier"
for
id
in
values
if
id
[
0
..
3
]
==
"doi:"
@
metadata
.
link
.
push
(
href
:
id
)
# hack to get a absolute url from a possibly relative one
_absoluteUrl
:
(
url
)
->
img
=
$
(
"<img src='
#{
url
}
'>"
)
url
=
img
.
prop
(
'src'
)
img
.
prop
(
'src'
,
null
)
return
url
h/js/services.coffee
View file @
77038342
...
...
@@ -343,14 +343,18 @@ class Hypothesis extends Annotator
# Get the location of the annotated document
@
provider
.
call
method
:
'getHref'
success
:
(
href
)
=>
method
:
'getDocumentInfo'
success
:
(
info
)
=>
href
=
info
.
uri
@
plugins
.
Document
.
metadata
=
info
.
metadata
options
=
angular
.
extend
{},
(
@
options
.
Store
or
{}),
annotationData
:
uri
:
href
loadFromSearch
:
limit
:
1000
uri
:
href
<<<<<<<
HEAD
this
.
addStore
(
options
)
addStore
:
(
options
)
->
...
...
@@ -361,15 +365,9 @@ class Hypothesis extends Annotator
return
unless
href
?
console
.
log
"Loaded annotions for '"
+
href
+
"'."
for
href
in
this
.
getSynonymURLs
href
console
.
log
"Also loading annotations for: "
+
href
this
.
plugins
.
Store
.
loadAnnotationsFromSearch
uri
:
href
# get metadata for the annotated document
@
provider
.
call
method
:
'getDocumentMetadata'
success
:
(
metadata
)
=>
this
.
plugins
.
Document
.
metadata
=
metadata
for
uri
in
@
plugins
.
Document
.
uris
()
console
.
log
"Also loading annotations for: "
+
uri
this
.
plugins
.
Store
.
loadAnnotationsFromSearch
uri
:
uri
class
DraftProvider
drafts
:
[]
...
...
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