-
Notifications
You must be signed in to change notification settings - Fork 762
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
Create National Library of Norway.js #1059
Conversation
a286b95
to
5b4a1d0
Compare
*/ | ||
|
||
function detectWeb(doc, url) { | ||
if (url.match("/nbsok/search?")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use indexOf("string") != -1
to test for the presence of literal strings (much more efficient)
some nits inline, looks nice otherwise. Thanks! |
fields = ZU.getItemArray(doc, doc, 'http://urn.nb.no/URN:NBN'); | ||
Object.keys(fields).forEach(function(url) { | ||
item.url = url; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fishy: In each loop step you are replacing the previous item.url
with a new url
? Also I am not sure you really need to call the function ZU.getItemArray above. What would you like to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a quick and dirty way to get the link that starts with http://urn.nb.no/URN:NBN
. This rewrite is probably more efficient and transparent? (I know the link is somewhere inside #preview_metadata
, so I can narrow in on that.)
var container = doc.getElementById('preview_metadata');
if (container) {
var links = container.getElementsByTagName('a');
for(var i=0; i<links.length; i++) {
if (links[i].href && links[i].href.indexOf('urn.nb.no/URN:NBN') != -1) {
item.url = links[i].href;
break;
}
}
}
// Add permalink | ||
var container = doc.getElementById('preview_metadata'); | ||
if (container) { | ||
var links = container.getElementsByTagName('a'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use ZU.xpathText(container, './a[contains(@href, "urn.nb.no/URN:NBN")])
;
Should be basically as efficient and save you 5 lines.
edit: fixed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks! Just had to do './/', since it's in a subdiv
thanks! |
I’m relying mostly on the RIS translator.
To detect the document type without having to fetch the RIS file, I'm using an input field part of a feedback form (
//input[@id="mediaType"]
). This works, but seems a bit fragile, so I will try to get in contact with the library about a better solution. The best would be to have something like RDFa markup I guess.