Skip to content

Commit

Permalink
Merge branch 'linker_tracking_wout_refs' of https://github.com/Sefari…
Browse files Browse the repository at this point in the history
…a/Sefaria-Project into linker_tracking
  • Loading branch information
Steven Kaplan authored and Steven Kaplan committed Nov 7, 2021
2 parents 1da4c9f + 78e4dfd commit 6e02f07
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sefaria/model/webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def add_or_update_from_linker(data):
webpage = WebPage(data)
existing = False
webpage._normalize() # to remove bad refs, so pages with empty ref list aren't saved
if webpage.should_be_excluded():
if webpage.should_be_excluded() or len(data["refs"]) == 0: # data["refs"] is empty when linker.js finds no refs on a page:
if existing:
webpage.delete()
return "excluded"
Expand Down
2 changes: 1 addition & 1 deletion static/test/linker_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h3>Some problematic ones</h3> <a href="https://github.com/Sefaria/Sefaria-Proje

<p>This paragraph appears outside of #foo: Amos 5:6 (shouldn't link when `selector` is #foo)</p>

<script type="text/javascript" charset="utf-8" src="http://localhost:8000/linker.v2.js"></script>
<script type="text/javascript" charset="utf-8" src="/linker.v2.js"></script>

<script>
sefaria.link({
Expand Down
12 changes: 10 additions & 2 deletions templates/js/linker.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@

if (matchedTitles.length == 0) {
console.log("No book titles found to link to Sefaria.");
ns._trackPage();
return;
}

Expand Down Expand Up @@ -363,8 +364,15 @@
};

ns._trackPage = function() {
if (ns.trackedMatches.length == 0) { return; }

if (ns.trackedMatches.length === 0 && ns.matches.length > 0) {
// we want to track page in two cases:
// 1) if there are trackedMatches found
// or 2) if there are no trackMatches found AND no matches found, as we want to send a message
// to api/linker_track so that the backend will delete the webpage.
// however, this if statement is a third case:
// when there are no trackMatches found but there are matches found, we don't want to track page
return;
}
var robots = document.head.querySelector("meta[name~=robots]");
if (robots && robots.content.includes("noindex")) { return; }

Expand Down
20 changes: 14 additions & 6 deletions templates/js/linker.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,13 @@
const full_text = [].reduce.call(ns.elems, (prev, current) => prev + current.textContent, "");
ns.matchedTitles = bookTitles.filter(title => full_text.indexOf(title) > -1).filter(distinct);

if (ns.matchedTitles.length === 0) {
if (ns.matchedTitles.length === 0) {
//console.log("No book titles found to link to Sefaria.");
return;
ns._trackPage();
}
else {
ns._getRegexesThenTexts(ns.mode);
}

ns._getRegexesThenTexts(ns.mode);
};


Expand Down Expand Up @@ -617,8 +618,15 @@
};

ns._trackPage = function() {
if (ns.trackedMatches.length == 0) { return; }

if (ns.trackedMatches.length === 0 && ns.matches.length > 0) {
// we want to track page in two cases:
// 1) if there are trackedMatches found
// or 2) if there are no trackMatches found AND no matches found, as we want to send a message
// to api/linker_track so that the backend will delete the webpage.
// however, this if statement is a third case:
// when there are no trackMatches found but there are matches found, we don't want to track page
return;
}
var robots = document.head.querySelector("meta[name~=robots]");
if (robots && robots.content.includes("noindex")) { return; }

Expand Down

0 comments on commit 6e02f07

Please sign in to comment.