Skip to content

Commit a79ca7e

Browse files
committed
/foo/bar.html だけでなく、/foo/bar でも利用できるようにする
1 parent 8ae39fe commit a79ca7e

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

lib/PerlUsersJP/Builder.pm

+27-8
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,39 @@ sub build_entries {
7878
#$self->build_atom(\@entries);
7979
}
8080

81+
82+
# ビルドのルールは次の通り
83+
#
84+
# CASE1: content/foo/index.(md|html) から public/foo/index.html をビルド
85+
# この時、URL pathは次の3種で、一番上をcanonial属性に指定する
86+
# /foo/
87+
# /foo/index.html
88+
# /foo
89+
#
90+
# CASE2: content/foo/bar.(md|html) から次の2つをビルド
91+
# 1. public/foo/bar/index.html
92+
# 2. public/foo/bar.html
93+
# この時、URL pathは次の4種で、一番上をcanonial属性に指定する
94+
# /foo/bar
95+
# /foo/bar/
96+
# /foo/bar/index.html
97+
# /foo/bar.html
98+
#
8199
sub build_entry {
82100
my ($self, $src) = @_;
83101

84-
# mkdir
102+
my $matter = $self->front_matter($src);
103+
104+
my $name = $src->basename =~ s!\.([^.]+)$!!r;
85105
my $dest_dir = $self->to_public($src->parent);
106+
$dest_dir = $dest_dir->child($name) unless $name eq 'index';
86107
$dest_dir->mkpath;
108+
my $dest = $dest_dir->child('index.html');
109+
my $sub_dest; $sub_dest = $dest->parent->parent->child("$name.html") unless $name eq 'index';
87110

88-
my $matter = $self->front_matter($src);
89-
90-
my $dest;
91111
if ($matter->format eq 'html') {
92-
$dest = $src->copy($dest_dir);
112+
$src->copy($dest);
113+
$src->copy($sub_dest) if $sub_dest;
93114
}
94115
else {
95116
my $html = $self->_render_string('entry.html', {
@@ -99,10 +120,8 @@ sub build_entry {
99120
author => $matter->author,
100121
description => $matter->description,
101122
});
102-
103-
my $name = $src->basename =~ s!\.[^.]+$!.html!r;
104-
$dest = $dest_dir->child($name);
105123
$dest->spew_utf8($html);
124+
$sub_dest->spew_utf8($html) if $sub_dest;
106125
}
107126

108127
$self->diag("Created entry $dest\n");

0 commit comments

Comments
 (0)