User:Bawolff/sandbox/googleSitemap.js
< User:Bawolff | sandbox
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
importScript('User:Bawolff/mwapilib2.js');
//http://en.wikinews.org/w/api.php?action=query&prop=categories&generator=categorymembers&clprop=timestamp&gcmtitle=Category:Published&gcmdir=desc&gcmsort=timestamp&gcmnamespace=0&format=xml&gcmlimit=40&cllimit=max&cldir=asc
genSitemap = {};
genSitemap.do = function (titleListHTML, catListXML) {
if (!api) {throw new Error("could not load api lib.");}
api().renderPage
var sm; //sitemap
sm = '<?xml version="1.0" encoding="UTF-8"?>';
sm += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" \n xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">';
/* <url>
<loc>http://example.com/article123.html</loc>
<news:news>
<news:publication_date> 2006-08-14T03:30:00Z </news:publication_date>
<news:keywords>Business, Mergers, Acquisitions</news:keywords>
</news:news>
</url>
</urlset>
*/
}
genSitemap.init1 = function () {
//entry point
if (!api) {throw new Error("could not load api lib.");}
api().renderPage('User:Bawolff/simpleLatestNews').lift(genSitemap.init2).exec();
}
genSitemap.init2 = function (titleListHTML) {
var findHref = /<a[^>h]*?href="([^"]*)"[^>]*>/g;
var findName = /<a[^>]*?title="([^"]*)"[^>]*>/g;
var titlesLink = [], titlesName = [], link, name;
for (var i = 0; (link = findHref.exec(titleListHTML)) && name = findName.exec(titleListHTML); i++) {
titlesLink[i] = link;
titlesName[i] = name;
}
if (i > 0) {
genSitemap.getCatLinks(titlesLink, titlesName);
}
else {
throw new Error('problem geting latest pub');
}
}
genSitemap.getCatLinks = function (titlesLink, titlesName) {
api().makeRequest({action: 'query', prop: 'categories', clprop: 'timestamp', cllimt: 'max', 'titles' titlesName}, genSitemap.combineCats).exec();
//genSitemap.combineCats = function
}