Skip to content

Commit

Permalink
rework relative paths, optimise images
Browse files Browse the repository at this point in the history
  • Loading branch information
leon committed Jan 30, 2005
1 parent 6140912 commit 01ba28e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions perlmongers/bin/xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!/home/acme/bin/perl -w

use strict;
use Image::WorldMap;
Expand All @@ -15,12 +15,13 @@ my $tt = Template->new({
PRE_CHOMP => 1,
TRIM => 1,
EVAL_PERL => 1 ,
INCLUDE_PATH => ['lib', 'src'],
INCLUDE_PATH => ['.', 'lib', 'src'],
PROCESS => 'layout',
});

# Array containing all the group names
my @groups;
mkdir "html/groups/graphics";

foreach my $name (keys %$xml) {
my $group = $xml->{$name};
Expand All @@ -40,11 +41,11 @@ foreach my $name (keys %$xml) {
my $map = Image::WorldMap->new("titchy.png");
$map->add($group->{location}->{longitude}, $group->{location}->{latitude});
$map->draw("foo.png");
system("pngtopnm foo.png | ppmquant 255 | pnmtopng -compression 9 > html/groups/$id.png");
system("pngtopnm foo.png | ppmquant 64 | pnmtopng -compression 9 > html/groups/graphics/$id.png");
}
$group->{image} = "$id.png";
$group->{image} = "graphics/$id.png";

$tt->process('groups/group.html', $group, "html/groups/$id.html")
$tt->process('src/groups/group.html', $group, "html/groups/$id.html")
|| die $tt->error();

}
Expand Down
15 changes: 10 additions & 5 deletions perlmongers/lib/relative
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[% PERL %]
use URI::URL;
use File::Spec::Functions qw(abs2rel catfile splitpath);
my $template = '/' . $stash->get('template.name');
my $url = $stash->get('url');

if ($url !~ /http/) {
my $uri = URI::URL->new('http://www/src' . $url);
$uri = $uri->rel('http://www' . $template);
$uri .= 'index.html' if $uri =~ m|/$|;
print $uri
$url =~ s{^/}{};
$url = catfile "/src", $url;
$url .= 'index.html' if $url =~ m|/$|;
my($volume, $directories, $filepart) = splitpath($template);
my $uri = abs2rel($url, $directories);
# warn "$template -> $url = $uri\n";
print $uri;
} else {
# warn "$template -> $url = $url (URL)\n";
print $url;
}
[% END %]
Expand Down

0 comments on commit 01ba28e

Please sign in to comment.