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

Create National Library of Norway.js #1059

Merged
merged 1 commit into from
May 20, 2016
Merged

Conversation

danmichaelo
Copy link
Contributor

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.

*/

function detectWeb(doc, url) {
if (url.match("/nbsok/search?")) {
Copy link
Collaborator

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)

@adam3smith
Copy link
Collaborator

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;
});
Copy link
Contributor

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?

Copy link
Contributor Author

@danmichaelo danmichaelo May 19, 2016

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');
Copy link
Collaborator

@adam3smith adam3smith May 19, 2016

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.

Copy link
Contributor Author

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

@adam3smith
Copy link
Collaborator

thanks!

zuphilip pushed a commit to zuphilip/translators that referenced this pull request Mar 28, 2018
zuphilip pushed a commit to zuphilip/translators that referenced this pull request Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants