Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * buildIndex
- *
- * builds the Contributors Index
- * @memberof mefi2book
- *
- */
- function buildIndex() {
- var userNames = [], // an alphabetized array of all users in thread
- userIndex = {}; // a hash of usernames, where each one has an array of page #s where their comments are
- logger("Converting PDF to json");
- extractpdf(CACHE_DIR+mefiSubSite+'_metafilter_'+mefiThreadNumber+'_first_pass.pdf', function (err, pages) {
- if (err) {
- logger("PDF extract for Contributor Index erroring out");
- done(err);
- } else {
- logger("Found " + pages.length + " pages");
- pages.forEach( function(element, index, array) {
- var currentPage = index + 1;
- logger("Finding contributors - page: "+currentPage);
- // find the names of the authors of each comment on the page
- var usersOnPage = element.match(new RegExp(" — (.*)\n", "g")) || [];
- logger("Cleaning up names - page: "+currentPage);
- // clean up the names (shouldn't have to do this, what's the right way?)
- usersOnPage.forEach( function(element, index, array) {
- array[index] = element.match(new RegExp(" — (.*)\n"))[1];
- });
- //
- usersOnPage.forEach( function(element, index, array) {
- var userArray;
- if ( userIndex[element] ) {
- userArray = userIndex[element];
- if ( userArray[userArray.length-1] != currentPage ) {
- userArray[userArray.length] = currentPage;
- }
- } else {
- userNames.push(element);
- userIndex[element] = [];
- userArray = userIndex[element];
- userArray[0] = currentPage;
- }
- });
- });
- logger("Sorting contributors' usernames");
- userNames.sort(function (a, b) {
- return a.toLowerCase().localeCompare(b.toLowerCase());
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement