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

Support <a href="..." rel="next"> links #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true
trim_trailing_whitespace = true
insert_final_newline = true

[*.js]
indent_style = tab
18 changes: 18 additions & 0 deletions src/next_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ PageZipper.prototype.getNextLink = function(body) {

PageZipper.prototype.getAllScoredLinks = function(body) {
var allNextLinks = pgzp.getAllNextLinks(body);
var rels = pgzp.find_rel_next(allNextLinks);
if (rels) {
return rels;
}
var pageBarInfo = pgzp.getCurrentPageNumberFromPageBar(allNextLinks);
if (pageBarInfo[1]) {
pgzp.log("looking for page #: " + pageBarInfo[1].text + " w/confidence: " + pageBarInfo[2]);
pgzp.nextSynonyms[pgzp.nextSynonyms.length-1].syn = pageBarInfo[1].text; //update nextSynonyms
pgzp.nextSynonyms[pgzp.nextSynonyms.length-1].weight = pageBarInfo[2]; //update weight/confidence
}
else if (pgzp.debug) {
pgzp.log("Couldn't find a pagebar");
}
pgzp.linkTextIndex = pgzp.indexDuplicateLinks(allNextLinks);
pgzp.filter(allNextLinks, function(link) {return link.alreadyLoaded;}); //filter out already loaded links, needed by pageBar, but not anymore
pgzp.scoreLinks(allNextLinks);
Expand Down Expand Up @@ -60,6 +67,16 @@ PageZipper.prototype.normalizeLinks = function(allLinks) {
}
};

// Sometimes the website is nice and just tells is which one it is.
PageZipper.prototype.find_rel_next = function(allLinks) {
for (var i in allLinks) {
link = allLinks[i];
if (link.link.rel == "next") {
return [link];
}
}
};

//takes a trial name, normalizes all scores to between 0 and 100
PageZipper.prototype.normalizeTrialSet = function(trialName, allLinks) {
//get highest and lowest scores
Expand Down Expand Up @@ -157,6 +174,7 @@ PageZipper.prototype.addLinkComponents = function(link, allNextLinks, alreadyLoa

if (rootNode.title) allNextLinks.push(new NextLink(rootNode.title, link));
if (rootNode.alt) allNextLinks.push(new NextLink(rootNode.alt, link));
if (rootNode.rel) allNextLinks.push(new NextLink(rootNode.rel, link));
};

search(link);
Expand Down