Skip to content

Instantly share code, notes, and snippets.

@AaronO
Last active December 20, 2015 21:29
Show Gist options
  • Save AaronO/6198332 to your computer and use it in GitHub Desktop.
Save AaronO/6198332 to your computer and use it in GitHub Desktop.
Pull links from site to index
// Utility function
var startsWith = function (str1, str2) {
return str1.indexOf(str2) == 0;
}
// Url of page/domain
var baseUrl = "https://friendco.de";
// Utility functions
var hrefExtractor = function(idx, el) { return el.href; };
// Check if it belong to baseUrl
var belongsToBase = function(idx, url) {
return startsWith(url, baseUrl)
};
// Slice out baseUrl
var relativeLink = function(idx, url) {
return url.slice(baseUrl.length);
}
var links = $("a").map(hrefExtractor).filter(belongsToBase).map(relativeLink).toArray();
console.log(links.join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment