Skip to content

Instantly share code, notes, and snippets.

@satyr
Created January 24, 2009 10:12
Show Gist options
  • Save satyr/51397 to your computer and use it in GitHub Desktop.
Save satyr/51397 to your computer and use it in GitHub Desktop.
/* appjet:version 0.1 */
http://validator.w3.org/feed/check.cgi?url=http%3A//d3adspace.appjet.net/3
import('storage', 'lib-at0m');
Top = 'http://mayokara.info/';
Dsp = Top +'deadspace/';
Myk = Atom.Person('mayokara', {uri: Dsp});
HTM = wget(Dsp);
htm = HTM.replace(/<!--[\s\S]+?-->/g, '')
cnt = +request.path.slice(1) || 7e7;
{ let [, y, m, d] = (/#d(\d{4})(\d\d)(\d\d)/(htm)||[]).map(Number);
tdy = new Date(y, m - 1, d);
} storage[d4mat(tdy)] = HTM;
atm = Atom({
title: 'd3adspace',
link: {href: Dsp},
author: Myk,
icon: Top +'favicon.ico',
updated: new Date,
});
pluck('ol', htm).some(function(ol, i){
if(i >= cnt) return true;
var dat = new Date(tdy - i * 24 * 60 * 6e4), key = '#'+ d4mat(dat);
pluck('li', ol).reverse().forEach(function(li, j, lis){
var num = lis.length - j, n03 = sprintf('%03d', num);
atm.add({
title: key +' '+ n03,
link: {href: Dsp +'?'+ n03 + key},
author: Myk,
content: {type: 'html', _: li},
id: 'urn:md5:'+ md5(li),
updated: new Date(dat.setMinutes(num)),
});
});
});
atm.write();
function pluck(tag, src){
var res = [], stk = [], tag = RegExp('</?'+ tag +'\\b[^>]*>', 'g'), m;
while((m = (tag(src)||0)[0]))
if(m[1] !== '/') stk.push(tag.lastIndex);
else {
var n = stk.pop();
stk.length || res.push(src.slice(n, tag.lastIndex - m.length));
}
return res;
}
function d4mat(date){
return sprintf('d%04d%02d%02d',
date.getFullYear(),
date.getMonth() + 1,
date.getDate());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment