@@ -8,6 +8,7 @@ use PerlUsersJP::FrontMatter;
88
99use Path::Tiny ();
1010use Date::Format ();
11+ use Scalar::Util ();
1112use Text::MicroTemplate;
1213
1314use Text::Xatena;
@@ -179,6 +180,7 @@ sub build_categories {
179180sub build_category {
180181 my ($self , $src_category , $src_list ) = @_ ;
181182
183+ # すでにカテゴリ一覧のページが存在していたら、生成しないでおく
182184 $src_category = Path::Tiny::path($src_category );
183185 for my $ext (' html' , ' txt' , ' md' , ' markdown' ) {
184186 return if $src_category -> child(" index.$ext " )-> exists ;
@@ -187,28 +189,32 @@ sub build_category {
187189 my $content_dir = $self -> content_dir;
188190 my $category = $src_category =~ s ! $content_dir!! r ;
189191
192+ my @src_list = map {
193+ my $file = Path::Tiny::path($_ );
194+ my $matter = $self -> front_matter($file );
195+ my $name = $file -> basename =~ s !\. [^.]+$!! r ;
196+ my $title = $matter -> exists ? $matter -> title : $file -> basename . ' /' ;
197+ my $href = $matter -> exists ? " $category /$name " : " $category /@{[$file ->basename]}/" ;
198+ {
199+ file => $file ,
200+ matter => $matter ,
201+ name => $name ,
202+ title => $title ,
203+ href => $href ,
204+ }
205+ } $src_list -> @*;
206+
190207 my $html = $self -> _render_string(' category.html' , {
191208 category => $category ,
192209 description => $category ,
193210 title => $category ,
194- files => [map {
195- my $file = Path::Tiny::path($_ );
196- my $matter = $self -> front_matter($file );
197- my ($basename , $title , $href );
198- if ($matter -> exists ) {
199- my $name = $file -> basename =~ s !\. [^.]+$! .html! r ;
200-
201- $basename = $file -> basename;
202- $title = $matter -> title;
203- $href = sprintf (' %s/%s' , $category , $name );
204- }
205- else {
206- $basename = $file -> basename;
207- $title = $basename . ' /' ;
208- $href = sprintf (' %s/%s' , $category , $basename );
209- }
210- { title => $title , href => $href }
211- } sort { $a cmp $b } $src_list -> @* ],
211+ files => [
212+ sort {
213+ Scalar::Util::looks_like_number($a -> {name }) && Scalar::Util::looks_like_number($b -> {name })
214+ ? $a -> {name } <=> $b -> {name }
215+ : $a -> {name } cmp $b -> {name }
216+ } @src_list
217+ ],
212218 });
213219
214220 my $category_dir = $self -> public_dir-> child($category );
0 commit comments