From eb52e48913d03e544ff3eb3ac75cb8675c83f5a9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 27 May 2010 17:30:38 +0000 Subject: [PATCH] Closes #1079, Chronicle of Higher Ed problem Pushed updated translator from ajlyon --- .../The Chronicle of Higher Education.js | 215 +++++++++++------- 1 file changed, 131 insertions(+), 84 deletions(-) diff --git a/translators/The Chronicle of Higher Education.js b/translators/The Chronicle of Higher Education.js index 7e0d668ee2..4fd2e5adfa 100644 --- a/translators/The Chronicle of Higher Education.js +++ b/translators/The Chronicle of Higher Education.js @@ -2,24 +2,57 @@ "translatorID":"1e6d1529-246f-4429-84e2-1f1b180b250d", "translatorType":4, "label":"The Chronicle of Higher Education", - "creator":"Simon Kornblith", + "creator":"Simon Kornblith, Avram Lyon", "target":"^http://chronicle\\.com/", "minVersion":"1.0.0b3.r1", "maxVersion":"", "priority":100, "inRepository":true, - "lastUpdated":"2006-12-12 23:41:00" + "lastUpdated":"2010-05-27 17:30:00" } +/* + This translator works on articles posted in The Chronicle of Higher Education. + + It is based on the earlier translator by Simon Kornblith, but the Chronicle has + significantly restructured the site since 2006, breaking the old translator. + + As of early April 2010, this translator works on all tested pages. +*/ + +/* Test URLs: +Basic article: + http://chronicle.com/article/A-Little-Advice-From-32000/46210/ + Fagen, Adam, and Kimberly Suedkamp Wells. “A Little Advice From 32,000 Graduate Students.” The Chronicle of Higher Education, January 14, 2002, sec. Advice. http://chronicle.com/article/A-Little-Advice-From-32000/46210/. + +Older Article, with metadata at bottom: + http://chronicle.com/article/Grinnells-Green-Secrets/2653/ + Yuan, Xiao-Bo. “Grinnell's Green Secrets.” The Chronicle of Higher Education, June 16, 2006, Volume 52, Issue 41 edition, sec. News : Short Subjects. + +Blog Post: + http://chronicle.com/blogPost/humanities-cyberinfrastructure-project-bamboo/6138 + Katz, Stan. “Humanities Cyberinfrastructure: Project Bamboo.” The Chronicle of Higher Education. Brainstorm, July 17, 2008. http://chronicle.com/blogPost/humanities-cyberinfrastructure-project-bamboo/6138. +*/ + function detectWeb(doc, url) { - var articleRegexp = /^http:\/\/chronicle\.com\/(?:daily|weekly)\/[^/]+\// + /* The /daily/ and /weekly/ sections are leftover from the previous version + of the translator; they don't appear to still be on the Chronicle site, but + they might persist in older URLs. */ + var articleRegexp = /^http:\/\/chronicle\.com\/(daily|weekly|article|blogPost)\/[^/]+\// ; if(articleRegexp.test(url)) { - if(doc.location.href.indexOf("weekly") != -1) { - return "magazineArticle"; - } else { - return "webpage"; + var section = url.match(articleRegexp); + switch (section[1]) { + case "weekly": + case "daily": + case "article": + return "newspaperArticle"; + case "blogPost": + return "blogPost"; + default: + return false; } } else { + // This approach, used again below, is pretty crude. var aTags = doc.getElementsByTagName("a"); for(var i=0; i 0) { + item.pages = data[4]; + // If the section here and in the page proper are different, concatenate + if (item.section !== data[1]) + item.section = item.section + " : " + Zotero.Utilities.trimInternal(data[1]); + // Since newspaperArticle doesn't have Volume / Issue, put as Edition + item.edition = "Volume " + data[2] + ", Issue " + data[3]; + } + } + } + + item.attachments.push({url:doc.location.href, title: ("Chronicle of Higher Education Snapshot"), mimeType:"text/html"}); + item.complete(); + }, function() {Zotero.done();}); + Zotero.wait(); +} + +function parseAuthors(author) { + // Sometimes we have "By Author and Author" if(author.substr(0, 3).toLowerCase() == "by ") { author = author.substr(3); } + // Sometimes the author is in all caps + var pieces = author.split(" "); + for (var i = 0; i < pieces.length; i++) { + // TODO Make the all-caps character class more inclusive + if (pieces[i].match(/[A-Z-]+/) !== null) + pieces[i] = Zotero.Utilities.capitalizeTitle(pieces[i].toLowerCase(), true); + } + author = pieces.join(" "); + + // Somtimes we have multiple authors var authors = author.split(" and "); - for each(var author in authors) { - // fix capitalization - var words = author.split(" "); - for(var i in words) { - words[i] = words[i][0].toUpperCase()+words[i].substr(1).toLowerCase(); - } - author = words.join(" "); - - if(words[0] == "The") { - newItem.creators.push({lastName:author, creatorType:"author", fieldMode:true}); - } else { - newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author")); - } - } - } - - newItem.complete(); + return authors; } - -function doWeb(doc, url) { - var articleRegexp = /^http:\/\/chronicle\.com\/(?:daily|weekly)\/[^/]+\//; - if(articleRegexp.test(url)) { - scrape(doc); - } else { - var items = Zotero.Utilities.getItemArray(doc, doc, '^http://chronicle\\.com/(?:daily|weekly)/[^/]+/'); - items = Zotero.selectItems(items); - - if(!items) { - return true; - } - - var urls = new Array(); - for(var i in items) { - urls.push(i); - } - - Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); }); - Zotero.wait(); - } -} \ No newline at end of file