@@ -15,7 +15,9 @@ export default async function({login, q, imports, data, rest, account}, {enabled
1515 }
1616
1717 //Load inputs
18- let { load, lines, visibility, languages, skipped} = imports . metadata . plugins . code . inputs ( { data, q, account} )
18+ let { load, days, lines, visibility, languages, skipped} = imports . metadata . plugins . code . inputs ( { data, q, account} )
19+ if ( ! days )
20+ days = Infinity
1921 skipped . push ( ...data . shared [ "repositories.skipped" ] )
2022 const pages = Math . ceil ( load / 100 )
2123
@@ -35,7 +37,8 @@ export default async function({login, q, imports, data, rest, account}, {enabled
3537 . filter ( ( { actor} ) => account === "organization" ? true : actor . login ?. toLocaleLowerCase ( ) === login . toLocaleLowerCase ( ) )
3638 . filter ( ( { repo :{ name :repo } } ) => ! ( ( skipped . includes ( repo . split ( "/" ) . pop ( ) ) ) || ( skipped . includes ( repo ) ) ) )
3739 . filter ( event => visibility === "public" ? event . public : true )
38- . flatMap ( ( { payload} ) => Promise . all ( payload . commits . map ( async commit => ( await rest . request ( commit . url ) ) . data ) ) ) ,
40+ . filter ( ( { created_at} ) => Number . isFinite ( days ) ? new Date ( created_at ) > new Date ( Date . now ( ) - days * 24 * 60 * 60 * 1000 ) : true )
41+ . flatMap ( ( { created_at :created , payload} ) => Promise . all ( payload . commits . map ( async commit => ( { created :new Date ( created ) , ...( await rest . request ( commit . url ) ) . data } ) ) ) ) ,
3942 ] ) ,
4043 ]
4144 . flat ( )
@@ -51,7 +54,7 @@ export default async function({login, q, imports, data, rest, account}, {enabled
5154
5255 //Search for a random snippet
5356 let files = events
54- . flatMap ( ( { sha, commit :{ message, url} , files} ) => files . map ( ( { filename, status, additions, deletions, patch} ) => ( { sha, message, filename, status, additions, deletions, patch, repo :url . match ( / r e p o s [ / ] (?< repo > [ \s \S ] + ) [ / ] g i t [ / ] c o m m i t s / ) ?. groups ?. repo } ) ) )
57+ . flatMap ( ( { created , sha, commit :{ message, url} , files} ) => files . map ( ( { filename, status, additions, deletions, patch} ) => ( { created , sha, message, filename, status, additions, deletions, patch, repo :url . match ( / r e p o s [ / ] (?< repo > [ \s \S ] + ) [ / ] g i t [ / ] c o m m i t s / ) ?. groups ?. repo } ) ) )
5558 . filter ( ( { patch} ) => ( patch ? ( patch . match ( / \n / mg) ?. length ?? 1 ) : Infinity ) < lines )
5659 for ( const file of files )
5760 file . language = await imports . language ( { ...file , prefix :login } ) . catch ( ( ) => "unknown" )
@@ -60,12 +63,15 @@ export default async function({login, q, imports, data, rest, account}, {enabled
6063 if ( snippet ) {
6164 //Trim common indent from content and change line feed
6265 if ( ! snippet . patch . split ( "\n" ) . shift ( ) . endsWith ( "@@" ) )
63- snippet . patch = snippet . patch . replace ( / ^ (?< coord > @ @ .* ?@ @ ) / , "$<coord>\n " )
64- const indent = Math . min ( ...( snippet . patch . match ( / ^ [ + - ] ? + / mg) ? .map ( indent => ( indent . length ?? Infinity ) - indent . startsWith ( "+" ) - indent . startsWith ( "-" ) ) ?? [ ] ) ) || 0
65- const content = imports . htmlescape ( snippet . patch . replace ( / \r \n / mg , "\n" ) . replace ( new RegExp ( `^([+-]?) ${ " " . repeat ( indent ) } ` , "mg" ) , "$1" ) )
66+ snippet . patch = snippet . patch . replace ( / ^ (?< coord > @ @ .* ?@ @ ) . * / , "$<coord>" )
67+ const indent = Math . min ( ...( snippet . patch . match ( / ^ . \s + / mg) ?? [ 0 ] ) . map ( line => line . length - 1 ) ) || 0
68+ const content = imports . htmlescape ( snippet . patch . replace ( new RegExp ( `^(.)\\s{0, ${ indent } }` , "mg" ) , "$1" ) )
6669
6770 //Format patch
68- snippet . patch = imports . htmlunescape ( ( await imports . highlight ( content , "diff" ) ) . trim ( ) ) . replace ( / \n / g, "<br/>" )
71+ snippet . patch = imports . htmlunescape ( await imports . highlight ( content , "diff" ) )
72+ . trim ( )
73+ . replace ( / \r ? \n / g, "<br/>" )
74+ . replace ( / < s p a n c l a s s = " t o k e n p r e f i x u n c h a n g e d " > < \/ s p a n > / g, '<span class="token prefix unchanged">·</span>' )
6975 }
7076
7177 //Results
0 commit comments