ref: ee6ed04e07614f72cd403d102742646a551fa1fe
parent: b2f9582d4c988b7e8de59338402b63158470acd4
author: phil9 <[email protected]>
date: Sun Jan 31 05:37:03 EST 2021
files: adapt display to file type currently all file types are displayed leading to gibberish being printed when the file is in binary format. Images are now displayed inline, an error message is printed for any other binary format
--- a/shithub
+++ b/shithub
@@ -259,8 +259,17 @@
echo ' <p>'$repo' @ <a href="'/git/$gituser/$repo/$hash/f.html'">'$hash'</a><br/></p>'
if(test -f $file){
echo ' <a href="'/git/$gituser/$repo/$hash/$file'/raw">View raw version</a>'
- echo ' <pre id="code">'
- htcat $file
+ type=`{file -m $file}
+ switch($type){
+ case text/*
+ echo ' <pre id="code">'
+ htcat $file
+ echo ' </pre>'
+ case image/*
+ echo ' <br/><div><img src="'/git/$gituser/$repo/$hash/$file'/raw" /></div>'
+ case *
+ echo ' <p>Binary file not displayed</p>'
+ }
}
if not if(test -d $file){
cd $file
@@ -270,9 +279,9 @@
fname=`$nl{echo -n $f | htcat}
echo '<a href="'$url'">'$fname'</a>'
}
+ echo ' </pre>'
}
- echo ' </pre>
- </body>
+ echo ' </body>
</html>'
case 'viewraw'