Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
fix items order
Browse files Browse the repository at this point in the history
  • Loading branch information
zag committed Jan 14, 2013
1 parent b1bf3de commit a29a324
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
39 changes: 29 additions & 10 deletions lib/WriteAt/To/Atom.pm
Expand Up @@ -134,16 +134,22 @@ sub write {
my $tree = shift;
my $res = &WriteAt::make_levels( "CHAPTER", 0, $tree );
my $w = $self->writer;
foreach my $entry (@$res) {

# check if need filter by published
#first setup published attr for items
# if default_published
my $current_time =
$self->{set_date}
? $self->get_time_stamp_from_string( $self->{set_date} )
: time();
my @items_to_publish = ();
my $order = 0;
foreach my $entry (@$res) {
$entry->{order} = ++$order; #for sort in later
my $published = $entry->{node}->get_attr->{published};
my $current_time = $self->{set_date} ?
$self->get_time_stamp_from_string( $self->{set_date} ) : time();
#if strict check published attr
unless ( $self->{default_published} ) {
unless ($published) {

#skip enties without published attr
next unless $published;
next unless $self->{default_published};
}

#set default publushed = current time
Expand All @@ -153,14 +159,27 @@ sub write {
: $current_time;

#skip entry in future
next if $published_time > $current_time;
next if $published_time > $current_time;

my $updated = $self->unixtime_to_string( time() );
#save publish timesamp for sorting later
$entry->{pub_time} = $published_time;
push @items_to_publish, $entry;
}

#sort entries
@items_to_publish =
sort { $b->{pub_time} <=> $a->{pub_time} || $b->{order} <=> $a->{order} }
@items_to_publish;
foreach my $entry (@items_to_publish) {

# check if need filter by published
my $published = $entry->{node}->get_attr->{published};
my $updated = $self->unixtime_to_string($current_time);
$published ||= $updated;
my $title = &WriteAt::get_text( $entry->{node} );
my $title_en = &WriteAt::rus2lat($title);

#clear spaces
#strip spaces
$title_en =~ s/\s+/-/g;
my $filename = $title_en . ".htm";
my $url = $self->{baseurl} . "/" . $filename;
Expand Down
1 change: 1 addition & 0 deletions lib/WriteAt/To/Latex.pm
Expand Up @@ -9,6 +9,7 @@ use strict;
use warnings;
use Perl6::Pod::Utl;
use WriteAt::To;
use Perl6::Pod::To::Latex;
use base ( 'Perl6::Pod::To::Latex', 'WriteAt::To' );
use utf8;

Expand Down
2 changes: 1 addition & 1 deletion scripts/atom2file
Expand Up @@ -78,7 +78,7 @@ my @nodes = ();
);

# setup next and previus keys
my $size = @nodes;
my $size = reverse @nodes;
for ( my $i = 0 ; $i < $size ; $i++ ) {
my $n = $nodes[$i];
$n->{prev} = $nodes[$i] if $i;
Expand Down
4 changes: 4 additions & 0 deletions t/exportatom.pod6
Expand Up @@ -26,4 +26,8 @@ ok
Ok
=head1 Teste
=CHAPTER chapter3
Test
=end pod

0 comments on commit a29a324

Please sign in to comment.