Last active
March 23, 2017 20:54
-
-
Save eneuhauser/7e2f658829ad477980d38c80faf6f5a9 to your computer and use it in GitHub Desktop.
List Wikis for a GitHub Organization's Repositories
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
/** | |
* Executing the following in Chrome's console while viewing an organization's | |
* repositories will list available wiki pages for the those repostories. If | |
* paginated, you will have to repeat for each page. | |
*/ | |
function listWikis() { | |
return Promise.all($('li.source h3 a').map(src => { | |
const home = src.href + '/wiki'; | |
return new Promise(function(resolve) { | |
fetch(home, { credentials: 'include' }).then(r => r.text().then(t => { | |
const d = new DOMParser().parseFromString(t, 'text/html'), pages = $('a.wiki-page-link', d); | |
resolve({ | |
text: src.text.trim(), | |
href: home, | |
pages: pages.slice(1).map(a => { return { | |
text: a.text, | |
href: window.location.origin + a.getAttribute('href') | |
}; }), | |
exists: pages.length > 0 | |
}); | |
})); | |
}); | |
})).then(r => r.filter(w => w.exists)).then(toMarkdown); | |
function $(selector, start=document) { return Array.prototype.slice.call(start.querySelectorAll(selector), 0); } | |
function toMarkdown(wikis) { | |
const lf = '\n', max = 10; | |
console.log(wikis.map(r => { | |
const pages = r.pages.slice(0, max).map(p => toLink(p, ' * ')).join(lf), pp = r.pages.length - max; | |
return toLink(r) + (pages ? lf : '') + pages + (pp > 0 ? `${lf} * ${pp} more pages` : ''); | |
}).join(lf)); | |
return wikis; | |
function toLink(a, prefix='* ') { return `${prefix}[${a.text}](${a.href})`; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment