Skip to content

Commit 4be9163

Browse files
committedJan 26, 2020
カテゴリ一覧微調整
1 parent 9babc8e commit 4be9163

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed
 

‎layouts/category.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
<body>
1212
<h1><?= $vars->{category} ?></h1>
1313
<ul>
14-
? for my $file (@{$vars->{files}}) {
15-
<li><a href="<?= $file->{href} ?>"><?= $file->{title} ?></a></li>
14+
? for (@{$vars->{files}}) {
15+
<li>
16+
<a href="<?= $_->{href} ?>">
17+
<?= $_->{matter}->exists && $_->{href} =~ m!advent! && $_->{name} =~ m!\d\d*! ? sprintf("%d日目 - %s by %sさん", $_->{name}, $_->{title}, ($_->{matter}->author ? $_->{matter}->author : "名無し") ) : $_->{title} ?>
18+
</a>
19+
</li>
1620
? }
1721
</ul>
1822

‎lib/PerlUsersJP/Builder.pm

+24-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use PerlUsersJP::FrontMatter;
88

99
use Path::Tiny ();
1010
use Date::Format ();
11+
use Scalar::Util ();
1112
use Text::MicroTemplate;
1213

1314
use Text::Xatena;
@@ -179,6 +180,7 @@ sub build_categories {
179180
sub 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

Comments
 (0)
Please sign in to comment.