File bin/modules/site.sh

Last commit: Tue Dec 10 00:35:41 2024 +0100	Jan Dankert	Fixing the download links
1 #!/bin/bash 2 3 # Build website for repo 4 if [ ! -d $site_dir ]; then 5 echo "Error: Directory for sites does not exist: '$site_dir'" 6 return 4 7 fi 8 9 function html_header() { 10 11 if [ -n "$1" ]; then 12 title=$1 13 fi 14 15 if [ -n "$2" ]; then 16 depth=$2 17 else 18 depth=2 19 fi 20 21 uppath=$(for i in $(seq $depth); do echo -n "../";done) 22 if [[ -z $uppath ]]; then 23 uppath="./" 24 fi 25 26 echo "<html><head>" 27 echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=2\" />" 28 echo "<title>${title}</title>" 29 echo "<link rel=\"stylesheet\" href=\"${uppath}_assets/css/dit.css\">" 30 echo "<link rel=\"stylesheet\" href=\"${uppath}_assets/css/bulma.min.css\">" 31 #echo "<link rel=\"stylesheet\" href=\"${uppath}_assets//highlight-default.css\">" 32 #echo "<script src=\"${uppath}_assets/js/jquery-3.1.1.min.js\" defer=\"defer\"></script>" 33 #echo "<script src=\"${uppath}_assets/js/bootstrap.min.js\" defer=\"defer\"></script>" 34 #echo "<script src=\"${uppath}_assets/js/highlight.min.js\" defer=\"defer\"></script>" 35 echo "<script src=\"${uppath}_assets/js/dit.js\" defer=\"defer\"></script>" 36 37 echo "</head>" 38 echo "<body>" 39 40 echo "<section class=\"hero\"> 41 <div class=\"hero-body\"> 42 <p class=\"title\">$title</p> 43 </div> 44 </section>" 45 46 if [[ "$depth" -gt 0 ]]; then 47 48 echo -n "<nav class=\"navbar\" role=\"navigation\" aria-label=\"main navigation\"><div class=\"navbar-menu\">" 49 echo -n "<a class=\"navbar-item\" href=\"${uppath}\">&lt;</a>" 50 echo -n "<a class=\"navbar-item\" href=\"${uppath}${REPO_NAME}/commit/\">Log</a>" 51 echo -n "<a class=\"navbar-item\" href=\"${uppath}${REPO_NAME}/branch/\">Branches</a>" 52 echo -n "<a class=\"navbar-item\" href=\"${uppath}${REPO_NAME}/tag/\">Tag</a>" 53 echo -n "<a class=\"navbar-item\" href=\"${uppath}${REPO_NAME}/file/\">Files</a>" 54 echo "</div></nav>" 55 #echo "<a href=\"../graph.html\">Graph</a>" 56 57 fi 58 59 echo "<pre>" 60 61 } 62 63 function html_footer() { 64 65 if [[ "$1" != "0" ]]; then 66 echo "</pre><footer class=\"footer\"> 67 <div class=\"content has-text-centered\"><p><strong>$repo_project_name</strong> $repo_description</p>" 68 if [ -n "$site_clone_url" ]; then 69 echo "<p><code>git clone $site_clone_url/$REPO_NAME.git</code></p>" 70 fi 71 echo "</div> 72 </footer></body></html>" 73 fi 74 } 75 76 77 # create sub directories if not already there 78 if [ ! -d $site_dir/$REPO_NAME ]; then 79 mkdir -v $site_dir/$REPO_NAME 80 fi 81 82 for dir in "commit" "branch" "tag" "file" "raw"; do 83 if [ ! -d $site_dir/$REPO_NAME/$dir ]; then 84 mkdir -v $site_dir/$REPO_NAME/$dir 85 fi 86 done 87 88 git archive HEAD | tar -x -C $site_dir/$REPO_NAME/raw 89 git archive --format tar.gz --output=$site_dir/$REPO_NAME/$REPO_NAME-latest.tar.gz HEAD 90 91 92 ( html_header "$REPO_NAME" 1 93 echo "$REPO_NAME" 94 echo "$repo_project_name $repo_project_description" 95 echo "<hr>" 96 echo 97 98 if [ -f $site_dir/$REPO_NAME/raw/README.txt ]; then 99 cat $site_dir/$REPO_NAME/raw/README.txt 100 elif [ -f $site_dir/$REPO_NAME/raw/README.md ]; then 101 cat $site_dir/$REPO_NAME/raw/README.md 102 fi 103 104 echo -n "Last Commit:" 105 git log -1 --pretty=format:"%ad %an%x09<cite>%s</cite>" --date=rfc | tr -d '\n' 106 echo "<hr>" 107 108 echo -n "<a href=\"./commit/\">" 109 git log --oneline | wc -l | tr -d '\n' 110 echo -n " Commits" 111 echo "</a>" 112 113 echo -n "<a href=\"./tag/\">" 114 git tag | wc -l | tr -d '\n' 115 echo -n " Tags" 116 echo "</a>" 117 118 echo -n "<a href=\"./branch/\">" 119 git branch | wc -l | tr -d '\n' 120 echo -n " Branches" 121 echo "</a>" 122 123 echo -n "<a href=\"./file/\">" 124 git ls-tree -r HEAD --name-only | wc -l | tr -d '\n' 125 echo -n " Files" 126 echo "</a>" 127 128 echo "<hr>" 129 echo "<a href=\"./$REPO_NAME-latest.tar.gz\">Download</a>" 130 html_footer ) > $site_dir/$REPO_NAME/index.html 131 132 echo "Creating commit history" 133 ( html_header "Log" 2 134 135 git log --pretty=format:"%H%x09%ad%x09%an%x09%s" --date=rfc | while read line; do 136 IFS=$'\t'; logline=($line); unset IFS; 137 echo "<time>${logline[1]}</time> <em> ${logline[2]}</em> <a href=\"./${logline[0]}.html\"><cite>${logline[3]}</cite></a>" 138 done 139 html_footer ) > $site_dir/$REPO_NAME/commit/index.html 140 141 #( html_header "Graph" 142 # git log --oneline --graph 143 # html_footer ) > $site_dir/$REPO_NAME/graph.html 144 145 git log --pretty=%H | while read hash; do 146 if [ ! -f $site_dir/$REPO_NAME/commit/$hash.html ]; then 147 ( html_header "Commit" 2 148 git log -1 $hash --stat 149 html_footer ) > $site_dir/$REPO_NAME/commit/$hash.html; 150 fi 151 done 152 153 echo "Creating branches" 154 ( html_header "Branches" 2 155 git branch --format='%(refname:short)'| while read line ; do echo "<a href=\"./$line.html\">$line</a>"; done 156 html_footer ) > $site_dir/$REPO_NAME/branch/index.html; 157 158 159 git branch --format='%(refname:short)'| while read ref; do 160 git archive --format tar.gz --output=$site_dir/$REPO_NAME/branch/$REPO_NAME-$ref.tar.gz $ref 161 ( html_header "Branch <code>$ref</code>" 2 162 echo "<a href=\"./$REPO_NAME-$ref.tar.gz\">Download $ref</a>" 163 echo 164 git ls-tree -r $ref --name-only 165 html_footer ) > $site_dir/$REPO_NAME/branch/$ref.html; 166 done 167 168 echo "Creating tags" 169 ( html_header "Tags" 2 170 git tag| while read line ; do echo "<a href=\"./$line.html\">$line</a>"; done 171 html_footer ) > $site_dir/$REPO_NAME/tag/index.html; 172 173 git tag | while read ref; do 174 if [ ! -f $site_dir/$REPO_NAME/tag/$REPO_NAME-$ref.tar.gz ]; then 175 git archive --format tar.gz --output=$site_dir/$REPO_NAME/tag/$REPO_NAME-$ref.tar.gz $ref 176 ( html_header "Tag <code>$ref</code>" 2 177 echo "<a href=\"./$REPO_NAME-$ref.tar.gz\">Download Tag $ref</a>" 178 echo 179 git ls-tree -r $ref --name-only 180 html_footer ) > $site_dir/$REPO_NAME/tag/$ref.html; 181 fi 182 done 183 184 echo "Creating file list" 185 ( html_header "Files" 2; 186 echo "All files in HEAD:" 187 git ls-tree -r HEAD --name-only | while read line ; do 188 # experiment for tree 189 #out=`echo $line | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"` 190 out=$line 191 echo "<a href=\"./content/$line.html\">$out</a>" 192 done 193 echo "<hr>" 194 echo "<a href=\"../$REPO_NAME-latest.tar.gz\">Download</a>" 195 html_footer ) > $site_dir/$REPO_NAME/file/index.html; 196 197 echo "Creating file information" 198 git ls-tree -r HEAD --name-only | while read f; do 199 200 filedirname=$(dirname $f ) 201 mkdir -p "$site_dir/$REPO_NAME/file/content/${filedirname}" 202 203 slashes=${f//[^\/]} 204 depth=$(expr ${#slashes} + 3) 205 ( html_header "File <code>$f</code>" "${depth}" 206 echo -n "Last commit: " 207 git log -1 --oneline --pretty=format:"%ad%x09%an%x09%s" -- $f 208 echo "<hr>" 209 210 uppath=$(for i in $(seq $depth); do echo -n "../";done) 211 if [[ -z $uppath ]]; then 212 uppath="./" 213 fi 214 215 type=$(file -b --mime-type $site_dir/$REPO_NAME/raw/$f| cut -d/ -f1) 216 if [ "$type" == "image" ]; then 217 echo "<img src=\"${uppath}${REPO_NAME}/raw/$f\" />" 218 elif [ "$type" == "text" ]; then 219 extension="${f##*.}" 220 echo "<code class=\"source\" data-language=\"$extension\">" 221 # output with line numbers and HTML escaping 222 num=0; # line number 223 cat $site_dir/$REPO_NAME/raw/$f | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' | while IFS= read -r line || [ -n "$line" ]; do 224 ((++num)) # increase line number 225 printf '%0.s ' $(seq 1 $((6-${#num}))) # right-align the line number 226 echo "<a class=\"line\" id=\"$num\" href=\"#$num\">$num</a> $line" 227 done 228 echo "</code>" 229 else 230 echo "<i class=\"notification\">Binary file could not be displayed</i>" 231 fi 232 233 echo "<hr>" 234 echo "<a href=\"${uppath}${REPO_NAME}/raw/$f\">Download <code>$f</code></a>" 235 echo "<hr>" 236 echo "History" 237 git log --oneline --pretty=format:"%ad%x09%an%x09%s" --date=rfc -- $f 238 html_footer ) > $site_dir/$REPO_NAME/file/content/${f}.html; 239 done 240 echo "done" 241 242 # Copy assets like CSS,JS,... 243 244 if [ ! -d $site_dir/_assets ]; then 245 mkdir -v $site_dir/_assets 246 fi 247 248 cp -r $DIT_DIR/assets/* $site_dir/_assets/ 249 250 # Creating Index 251 if ( is_on $site_index_create ); then 252 echo "Creating index in $site_dir" 253 ( html_header "$site_index_title" 0 254 ( cd $site_dir; find . -maxdepth 1 -type d -printf '<a href="./%P">%P</a>\n'|sort ) 255 html_footer 0 ) > $site_dir/index.html 256 fi 257 258 if [ -n "$site_sync_ssh_host" ]; then 259 echo "Syncing to $site_sync_ssh_host ..." 260 rsync -a --delete -e ssh $site_dir/ $site_sync_ssh_user@$site_sync_ssh_host:$site_sync_ssh_path 261 fi 262 263
Download bin/modules/site.sh
History Tue, 10 Dec 2024 00:35:41 +0100 Jan Dankert Fixing the download links Mon, 9 Dec 2024 23:41:28 +0100 Jan Dankert Sorting the index. Mon, 9 Dec 2024 23:30:46 +0100 Jan Dankert Fix: Up-path was wrong, "/" must be escaped here. Mon, 9 Dec 2024 23:02:59 +0100 Jan Dankert Delete files on the target host for sites. Mon, 9 Dec 2024 22:36:24 +0100 Jan Dankert Create directory for repo if it does not exist. Mon, 9 Dec 2024 22:32:06 +0100 Jan Dankert Performance optimation: Reuse commits and tags. Mon, 9 Dec 2024 22:23:47 +0100 Jan Dankert Fix: Do not create directories for files in the root directory. Sun, 8 Dec 2024 23:38:44 +0100 Jan Dankert Fix: Support for bare repositories, store the files under their normal name. Sun, 8 Dec 2024 22:33:23 +0100 Jan Dankert Modules can be disabled by project configuration Sun, 8 Dec 2024 21:32:24 +0100 Jan Dankert Fix: Support for bare repositories. Wed, 27 Nov 2024 01:04:22 +0100 Jan Dankert Small fixes... Tue, 26 Nov 2024 23:26:36 +0100 Jan Dankert New: Creating a project website Mon, 13 May 2024 22:31:52 +0200 Jan Dankert some layout fixes; archive files for every tag and branch Mon, 13 May 2024 00:16:05 +0200 Jan Dankert changing from bootstrap to bulma. Mon, 13 May 2024 00:14:24 +0200 Jan Dankert fixing the up-paths, assets are now in the root folder Sun, 12 May 2024 23:21:28 +0200 Jan Dankert new: hightlight.js - but it breaks the line numbers :( Sun, 12 May 2024 19:53:02 +0200 Jan Dankert first edition of DIT, the delivery expert.