Created
February 2, 2016 16:14
-
-
Save ToQoz/242f1e1ce69e8b8733ec to your computer and use it in GitHub Desktop.
aws-sdk indexer for Chemrtron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indexer = { | |
id: 'aws', | |
icon: 'https://a0.awsstatic.com/main/images/logos/aws_logo_mobile@2x.png', | |
name: 'AWS', | |
index: function(ctx) { | |
return ctx | |
.fetchDocument('http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/_index.html', { | |
srcdoc: true | |
}) | |
.then(function(document) { | |
var serviceLinks = document.querySelectorAll('.service_list li > .object_link a'); | |
var serviceHrefs = Array.prototype.map.call(serviceLinks, function(link) { | |
return link.href.replace(/_\d{8}\.html$/, ".html") | |
}); | |
// for calling fetchDocument() with srcdoc=true in crawl() | |
var fetchDoc = ctx.fetchDocument.bind(ctx); | |
ctx.fetchDocument = function(url, opts) { | |
opts = opts || {}; | |
opts.srcdoc = true | |
return fetchDoc(url, opts); | |
}; | |
return ctx | |
.crawl(serviceHrefs, function(url, document) { | |
var links = document.querySelectorAll('.summary_signature a') | |
var crumbs = document.querySelectorAll('#menu .title'); | |
var className = crumbs[crumbs.length - 1].textContent; | |
Array.prototype.forEach.call(links, function(link) { | |
ctx.pushIndex(className + "." + link.textContent, link.href); | |
}); | |
}) | |
.then(function() { | |
ctx.fetchDocument = fetchDoc; | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment