MTのカテゴリーアーカイブのパスを得る。
公開日 : 2007-04-03 01:09:34
カテゴリーアーカイブのパスを得る方法がどうにもわからなくて、これまでこんな風に書いていたのだが、カテゴリーアーカイブの公開の設定(つまりTemplateMap)がどうなっているか決め打ちできないから汎用性が無いよなぁ...って...
my $cat_pth = &get_cat_arc($category, $blog_url, '/', 'index.html');
sub get_cat_arc {
my ($cat, $blog_base, $separator, $file_pth) = @_;
my $str = $cat->basename;
my $parent = $cat->parent;
while ($parent != 0) {
my $category = MT::Category->load({
id=>$parent});
$str = $category->basename.$separator.$str;
$parent = $category->parent;
}
return $blog_base.$str.$file_pth;
}
lib::MT::Category.pmにあるじゃねぇか!
sub category_path {
my $cat = shift;
return $cat->{__path} if exists $cat->{__path};
my $result = $cat->basename;
do {
$cat = $cat->parent ? __PACKAGE__->load($cat->parent) : undef;
$result = join "/", $cat->basename, $result if $cat;
} while ($cat);
# caching this information may be problematic IF
# parent category basenames are changed.
$cat->{__path} = $result;
}
ちゃんとキャッシュもしてるみたいだし。
やっぱり、ちゃんとドキュメント整備しようよ。これじゃやっぱり「ハック」の領域だよ。
まぁいいや、これでタスクリストのいくつかが潰れた。