Fossil SCM

If a directory listing (from /file or /dir or /tree) contains a README file, then render the content of that README beneath the directory listing. Example: [/file/skins]

drh 2017-03-15 17:27 trunk
Commit a6993f9bd485cc1f0c8747d827bafecc091a8f443a1bc8de99c37f43637f26d3
1 file changed +57
+57
--- src/browse.c
+++ src/browse.c
@@ -133,10 +133,11 @@
133133
Blob dirname;
134134
Manifest *pM = 0;
135135
const char *zSubdirLink;
136136
int linkTrunk = 1;
137137
int linkTip = 1;
138
+ char *zReadme;
138139
HQuery sURI;
139140
140141
if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
141142
login_check_credentials();
142143
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -295,10 +296,66 @@
295296
}
296297
}
297298
db_finalize(&q);
298299
manifest_destroy(pM);
299300
@ </ul></td></tr></table>
301
+
302
+ /* If the directory contains a readme file, then display its content below
303
+ ** the list of files
304
+ */
305
+ db_prepare(&q,
306
+ "SELECT x, u FROM localfiles"
307
+ " WHERE x COLLATE nocase IN"
308
+ " ('readme','readme.txt','readme.md','readme.wiki','readme.markdown',"
309
+ " 'readme.html') ORDER BY x LIMIT 1;"
310
+ );
311
+ if( db_step(&q)==SQLITE_ROW ){
312
+ const char *zName = db_column_text(&q,0);
313
+ const char *zUuid = db_column_text(&q,1);
314
+ if( zUuid ){
315
+ rid = fast_uuid_to_rid(zUuid);
316
+ }else{
317
+ if( zD ){
318
+ rid = db_int(0,
319
+ "SELECT fid FROM filename, mlink, event"
320
+ " WHERE name='%q/%q'"
321
+ " AND mlink.fnid=filename.fnid"
322
+ " AND event.objid=mlink.mid"
323
+ " ORDER BY event.mtime DESC LIMIT 1",
324
+ zD, zName
325
+ );
326
+ }else{
327
+ rid = db_int(0,
328
+ "SELECT fid FROM filename, mlink, event"
329
+ " WHERE name='%q'"
330
+ " AND mlink.fnid=filename.fnid"
331
+ " AND event.objid=mlink.mid"
332
+ " ORDER BY event.mtime DESC LIMIT 1",
333
+ zName
334
+ );
335
+ }
336
+ }
337
+ if( rid ){
338
+ @ <hr>
339
+ if( sqlite3_strlike("readme.html", zName, 0)==0 ){
340
+ if( zUuid==0 ){
341
+ zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
342
+ }
343
+ @ <iframe src="%R/raw/%s(zUuid)"
344
+ @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
345
+ @ sandbox="allow-same-origin"
346
+ @ onload="this.height=this.contentDocument.documentElement.scrollHeight;">
347
+ @ </iframe>
348
+ }else{
349
+ Blob content;
350
+ const char *zMime = mimetype_from_name(zName);
351
+ content_get(rid, &content);
352
+ wiki_render_by_mimetype(&content, zMime);
353
+ }
354
+ }
355
+ }
356
+ db_finalize(&q);
300357
style_footer();
301358
}
302359
303360
/*
304361
** Objects used by the "tree" webpage.
305362
--- src/browse.c
+++ src/browse.c
@@ -133,10 +133,11 @@
133 Blob dirname;
134 Manifest *pM = 0;
135 const char *zSubdirLink;
136 int linkTrunk = 1;
137 int linkTip = 1;
 
138 HQuery sURI;
139
140 if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
141 login_check_credentials();
142 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -295,10 +296,66 @@
295 }
296 }
297 db_finalize(&q);
298 manifest_destroy(pM);
299 @ </ul></td></tr></table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300 style_footer();
301 }
302
303 /*
304 ** Objects used by the "tree" webpage.
305
--- src/browse.c
+++ src/browse.c
@@ -133,10 +133,11 @@
133 Blob dirname;
134 Manifest *pM = 0;
135 const char *zSubdirLink;
136 int linkTrunk = 1;
137 int linkTip = 1;
138 char *zReadme;
139 HQuery sURI;
140
141 if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
142 login_check_credentials();
143 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -295,10 +296,66 @@
296 }
297 }
298 db_finalize(&q);
299 manifest_destroy(pM);
300 @ </ul></td></tr></table>
301
302 /* If the directory contains a readme file, then display its content below
303 ** the list of files
304 */
305 db_prepare(&q,
306 "SELECT x, u FROM localfiles"
307 " WHERE x COLLATE nocase IN"
308 " ('readme','readme.txt','readme.md','readme.wiki','readme.markdown',"
309 " 'readme.html') ORDER BY x LIMIT 1;"
310 );
311 if( db_step(&q)==SQLITE_ROW ){
312 const char *zName = db_column_text(&q,0);
313 const char *zUuid = db_column_text(&q,1);
314 if( zUuid ){
315 rid = fast_uuid_to_rid(zUuid);
316 }else{
317 if( zD ){
318 rid = db_int(0,
319 "SELECT fid FROM filename, mlink, event"
320 " WHERE name='%q/%q'"
321 " AND mlink.fnid=filename.fnid"
322 " AND event.objid=mlink.mid"
323 " ORDER BY event.mtime DESC LIMIT 1",
324 zD, zName
325 );
326 }else{
327 rid = db_int(0,
328 "SELECT fid FROM filename, mlink, event"
329 " WHERE name='%q'"
330 " AND mlink.fnid=filename.fnid"
331 " AND event.objid=mlink.mid"
332 " ORDER BY event.mtime DESC LIMIT 1",
333 zName
334 );
335 }
336 }
337 if( rid ){
338 @ <hr>
339 if( sqlite3_strlike("readme.html", zName, 0)==0 ){
340 if( zUuid==0 ){
341 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
342 }
343 @ <iframe src="%R/raw/%s(zUuid)"
344 @ width="100%%" frameborder="0" marginwidth="0" marginheight="0"
345 @ sandbox="allow-same-origin"
346 @ onload="this.height=this.contentDocument.documentElement.scrollHeight;">
347 @ </iframe>
348 }else{
349 Blob content;
350 const char *zMime = mimetype_from_name(zName);
351 content_get(rid, &content);
352 wiki_render_by_mimetype(&content, zMime);
353 }
354 }
355 }
356 db_finalize(&q);
357 style_footer();
358 }
359
360 /*
361 ** Objects used by the "tree" webpage.
362

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button