this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #16 from websages/footer_update

Add footer with commit that is running

authored by

Stephen Yeargin and committed by
GitHub
526890d8 4bfe3d26

+177 -5
+88 -1
htdocs/lib/tumble.pm
··· 6 6 7 7 use DBI; 8 8 use POSIX qw( strftime ); 9 + use Cwd qw( abs_path getcwd ); 10 + use File::Spec; 9 11 10 12 use YAML qw( LoadFile ); 11 13 ··· 246 248 } 247 249 248 250 251 + sub get_git_commit { 252 + my $self = shift; 253 + 254 + # Read git commit hash directly from .git files 255 + # This avoids needing the git command which might not be in PATH 256 + # Wrap in eval to prevent any errors from causing output 257 + my $git_commit; 258 + eval { 259 + local $SIG{__WARN__} = sub {}; # Suppress any warnings 260 + 261 + # Get current working directory 262 + my $cwd = getcwd() || '.'; 263 + my @dirs_to_try = (); 264 + 265 + # Method 1: Try from current directory (might be htdocs/) 266 + push @dirs_to_try, $cwd; 267 + 268 + # Method 2: Go up one level from current directory 269 + my $parent = File::Spec->catdir($cwd, File::Spec->updir()); 270 + $parent = abs_path($parent) if -d $parent; 271 + push @dirs_to_try, $parent if $parent && -d $parent; 272 + 273 + # Method 3: Try from template path 274 + if ($self->tmpl_path()) { 275 + my $tmpl_abs = abs_path($self->tmpl_path()); 276 + if ($tmpl_abs) { 277 + my $tmpl_dir = $tmpl_abs; 278 + $tmpl_dir =~ s|/[^/]+$||; # Remove thtml/ 279 + push @dirs_to_try, $tmpl_dir; 280 + $tmpl_dir =~ s|/[^/]+$||; # Remove htdocs/ 281 + push @dirs_to_try, $tmpl_dir if $tmpl_dir && -d $tmpl_dir; 282 + } 283 + } 284 + 285 + # Try each directory until we find one with .git 286 + for my $dir (@dirs_to_try) { 287 + next unless $dir && -d $dir; 288 + 289 + my $git_dir = File::Spec->catdir($dir, '.git'); 290 + next unless -d $git_dir || -f $git_dir; 291 + 292 + # Read HEAD file 293 + my $head_file = File::Spec->catfile($git_dir, 'HEAD'); 294 + next unless -f $head_file; 295 + 296 + if (open(my $fh, '<', $head_file)) { 297 + my $head = <$fh>; 298 + close($fh); 299 + chomp $head if $head; 300 + 301 + # If HEAD points to a ref, follow it 302 + if ($head && $head =~ /^ref: (.+)$/) { 303 + my $ref_file = File::Spec->catfile($git_dir, $1); 304 + if (-f $ref_file && open($fh, '<', $ref_file)) { 305 + $head = <$fh>; 306 + close($fh); 307 + chomp $head if $head; 308 + } else { 309 + next; 310 + } 311 + } 312 + 313 + # Extract short commit hash (first 7 characters) 314 + if ($head && $head =~ /^([0-9a-f]{7,})/i) { 315 + $git_commit = substr($1, 0, 7); 316 + last; 317 + } 318 + } 319 + } 320 + }; 321 + # Only return if it looks like a valid commit hash (7+ hex chars) 322 + return $git_commit if $git_commit && $git_commit =~ /^[0-9a-f]{7}$/i; 323 + return undef; 324 + } 325 + 249 326 sub wrap { 250 327 my $self = shift; 251 328 252 329 my ( $arg ); 253 330 %{$arg} = @_; 254 331 332 + my $wrapper_name = $arg->{'wrapper'}; 255 333 my $template = $self->load_tmpl( 256 - $arg->{'wrapper'} . '.t' . $self->{'arg'}->{'dtype'}, 334 + $wrapper_name . '.t' . $self->{'arg'}->{'dtype'}, 257 335 die_on_bad_params => 0 258 336 ); 259 337 260 338 delete $arg->{'wrapper'}; 339 + 340 + # Add git commit hash and URL for index template 341 + if ($wrapper_name eq 'index') { 342 + my $git_commit = $self->get_git_commit(); 343 + if ($git_commit) { 344 + $arg->{'git_commit'} = $git_commit; 345 + $arg->{'git_commit_url'} = "https://github.com/websages/tumble/commit/$git_commit"; 346 + } 347 + } 261 348 262 349 map { 263 350 chomp( $arg->{$_} ) if ref $arg->{$_};
+88 -3
htdocs/lib/tumble/search.pm
··· 4 4 5 5 use lsrfsh::MySQL; 6 6 use YAML qw( LoadFile ); 7 + use Cwd qw( abs_path getcwd ); 8 + use File::Spec; 7 9 8 10 use DBI; 9 11 ··· 68 70 $raw->{$item}->{'title'} . 69 71 qq{</a>}; 70 72 71 - print "link: $link\n"; 72 - 73 73 $c .= $self->wrap( 74 74 wrapper => 'tumble_item_ircLink', 75 75 author => $raw->{$item}->{'user'}, ··· 134 134 135 135 136 136 137 + sub get_git_commit { 138 + my $self = shift; 139 + 140 + # Read git commit hash directly from .git files 141 + # This avoids needing the git command which might not be in PATH 142 + # Wrap in eval to prevent any errors from causing output 143 + my $git_commit; 144 + eval { 145 + local $SIG{__WARN__} = sub {}; # Suppress any warnings 146 + 147 + # Get current working directory 148 + my $cwd = getcwd() || '.'; 149 + my @dirs_to_try = (); 150 + 151 + # Method 1: Try from current directory (might be htdocs/) 152 + push @dirs_to_try, $cwd; 153 + 154 + # Method 2: Go up one level from current directory 155 + my $parent = File::Spec->catdir($cwd, File::Spec->updir()); 156 + $parent = abs_path($parent) if -d $parent; 157 + push @dirs_to_try, $parent if $parent && -d $parent; 158 + 159 + # Method 3: Try from template path 160 + if ($self->tmpl_path()) { 161 + my $tmpl_abs = abs_path($self->tmpl_path()); 162 + if ($tmpl_abs) { 163 + my $tmpl_dir = $tmpl_abs; 164 + $tmpl_dir =~ s|/[^/]+$||; # Remove thtml/ 165 + push @dirs_to_try, $tmpl_dir; 166 + $tmpl_dir =~ s|/[^/]+$||; # Remove htdocs/ 167 + push @dirs_to_try, $tmpl_dir if $tmpl_dir && -d $tmpl_dir; 168 + } 169 + } 170 + 171 + # Try each directory until we find one with .git 172 + for my $dir (@dirs_to_try) { 173 + next unless $dir && -d $dir; 174 + 175 + my $git_dir = File::Spec->catdir($dir, '.git'); 176 + next unless -d $git_dir || -f $git_dir; 177 + 178 + # Read HEAD file 179 + my $head_file = File::Spec->catfile($git_dir, 'HEAD'); 180 + next unless -f $head_file; 181 + 182 + if (open(my $fh, '<', $head_file)) { 183 + my $head = <$fh>; 184 + close($fh); 185 + chomp $head if $head; 186 + 187 + # If HEAD points to a ref, follow it 188 + if ($head && $head =~ /^ref: (.+)$/) { 189 + my $ref_file = File::Spec->catfile($git_dir, $1); 190 + if (-f $ref_file && open($fh, '<', $ref_file)) { 191 + $head = <$fh>; 192 + close($fh); 193 + chomp $head if $head; 194 + } else { 195 + next; 196 + } 197 + } 198 + 199 + # Extract short commit hash (first 7 characters) 200 + if ($head && $head =~ /^([0-9a-f]{7,})/i) { 201 + $git_commit = substr($1, 0, 7); 202 + last; 203 + } 204 + } 205 + } 206 + }; 207 + # Only return if it looks like a valid commit hash (7+ hex chars) 208 + return $git_commit if $git_commit && $git_commit =~ /^[0-9a-f]{7}$/i; 209 + return undef; 210 + } 211 + 137 212 sub wrap { 138 213 my $self = shift; 139 214 140 215 my ( $arg ); 141 216 %{$arg} = @_; 142 217 218 + my $wrapper_name = $arg->{'wrapper'}; 143 219 my $template = $self->load_tmpl( 144 - $arg->{'wrapper'} . '.thtml', 220 + $wrapper_name . '.thtml', 145 221 die_on_bad_params => 0 146 222 ); 147 223 148 224 delete $arg->{'wrapper'}; 225 + 226 + # Add git commit hash and URL for index template 227 + if ($wrapper_name eq 'index') { 228 + my $git_commit = $self->get_git_commit(); 229 + if ($git_commit) { 230 + $arg->{'git_commit'} = $git_commit; 231 + $arg->{'git_commit_url'} = "https://github.com/websages/tumble/commit/$git_commit"; 232 + } 233 + } 149 234 150 235 map { 151 236 chomp( $arg->{$_} ) if ref $arg->{$_};
+1 -1
htdocs/thtml/index.thtml
··· 154 154 <div id="footer"> 155 155 <!-- tmpl_var name="nav_p" --> 156 156 <!-- tmpl_var name="nav_n" --> 157 - <br><br> Source Code Available on <a href=http://github.com/websages/tumble>Github</a>. 157 + <br><br> Source Code Available on <a href=http://github.com/websages/tumble>GitHub</a> <svg width="16" height="16" viewBox="0 0 16 16" fill="#000000" style="vertical-align: text-bottom; display: inline-block;"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>.<!-- tmpl_if name="git_commit" --> Revision: <a href="<!-- tmpl_var name="git_commit_url" -->"><!-- tmpl_var name="git_commit" --></a><!-- /tmpl_if --> 158 158 </div> 159 159 160 160 </div>