Skip to content

Instantly share code, notes, and snippets.

@ToQoz
Created February 2, 2016 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToQoz/242f1e1ce69e8b8733ec to your computer and use it in GitHub Desktop.
Save ToQoz/242f1e1ce69e8b8733ec to your computer and use it in GitHub Desktop.
aws-sdk indexer for Chemrtron
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