[Bps-public-commit] SD branch, master, updated. 0.74-44-g354db4b
? sunnavy
sunnavy at bestpractical.com
Thu Aug 5 06:02:27 EDT 2010
The branch, master has been updated
via 354db4babff7b855790e213d097fb1884ccbac56 (commit)
from efaf967772189b44bb4a82141ef2190f0cd67ccc (commit)
Summary of changes:
lib/App/SD/CLI/Command/Publish.pm | 40 +++++++++++++++++++++++++++++++++---
1 files changed, 36 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 354db4babff7b855790e213d097fb1884ccbac56
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Aug 5 17:55:32 2010 +0800
make "pubilsh --html" really work
diff --git a/lib/App/SD/CLI/Command/Publish.pm b/lib/App/SD/CLI/Command/Publish.pm
index 999444c..d43cb6f 100644
--- a/lib/App/SD/CLI/Command/Publish.pm
+++ b/lib/App/SD/CLI/Command/Publish.pm
@@ -75,6 +75,8 @@ sub work_with_urls {
my $current_url = shift;
my $content = shift;
+ my $current_depth = () = $current_url =~ m{.+?/}g;
+
#Extract Links from the file
my $h = HTML::TreeBuilder->new;
$h->no_space_compacting(1);
@@ -94,7 +96,7 @@ sub work_with_urls {
$all_links->{$link}++;
- my $url = URI::file->new($link)->rel("file://$current_url");
+ my $url = $link;
if ( $url =~ m|/$| ) {
$url .= "index.html"
@@ -102,18 +104,48 @@ sub work_with_urls {
$url .= ".html";
}
-
+ # if $url is absolute, let's make it relative
+ if ( $current_depth && $url =~ s{^/}{} ) {
+ $url = ( '../' x $current_depth ) . $url;
+ }
my ($attr)
= grep { defined $element->attr($_) and $link eq $element->attr($_) }
@{ $HTML::Tagset::linkElements{ $element->tag } };
- #Re-write the attribute in the HTML::Element Tree
$element->attr( $attr, $url );
+ }
+
+ my @links;
+
+ # we nned to turn every link into absolute, here is to find out dir info
+ # e.g. if $current_url is '/foo/bar/baz.html', @dirs will be qw/foo bar/
+ my @dirs = grep { $_ } split m{/}, $current_url;
+ # pop the page name like history.html
+ pop @dirs;
+
+ for my $link ( keys %$all_links ) {
+ next unless $link;
+
+ # we don't use ./ and file: link in pages, so they are bogus for us
+ # more worse thing is './' will overwride some page with nothing
+ next if $link eq './' || $link =~ /^file:/;
+
+ # generally, if the link is not absolute, we need to find it.
+ if ( $link !~ m{^/} ) {
+ my $depth = $link =~ s{\.\./}{}g;
+ my @tmp_dirs = @dirs;
+ # remove trailing dirs according to $depth
+ if ($depth) {
+ pop @tmp_dirs while $depth--;
+ }
+ $link = '/' . join '/', @tmp_dirs, $link;
+ }
+ push @links, $link;
}
- return $h->as_HTML, [ keys %$all_links ];
+ return $h->as_HTML, \@links;
}
sub handle_redirect {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list