- 2008年7月 1日 15:51
- Movable Type | Vicuna
エントリを見返すのに、AutoPagerizeが動作しないと不便なので対応した。
- PageButeプラグインでHomeを分割
- AutoPagerize用のmicroformatsを仕込む
ページ分割にPHPを使用したくなかったので、静的なHTMLを出力してくれるPageButeプラグインを使用した。
あと「次のページ」へのリンクをA要素丸ごと出力するタグしか無いので、URLだけを出力するタグを追加した(そのままだとAutoPagerize用のrel属性を追加できない)。
この辺をクリアできる分割プラグインがあればそっち使った方が楽そう。
PageButeプラグインでHomeを分割
PageButeプラグインをインストール、PageBute.plとテンプレートを編集する。
MTPageNextがMT標準のテンプレートタグと被る
PageBute.plを書き替える。わかりやすく全てのタグ(MTPage〜)をMTPageBute〜とした。
MT::Template::Context->add_container_tag(PageButeContents => ¥&_page_contents);
MT::Template::Context->add_container_tag(IfPageButeNext => ¥&_if_page_next);
MT::Template::Context->add_container_tag(IfPageButeBefore => ¥&_if_page_before);
MT::Template::Context->add_tag(PageButeNext => ¥&_page_next);
MT::Template::Context->add_tag(PageButeBefore => ¥&_page_before);
MT::Template::Context->add_tag(PageButeNextURL => ¥&_page_next_url);
MT::Template::Context->add_tag(PageButeBeforeURL => ¥&_page_before_url);
MT::Template::Context->add_tag(PageButeSeparator => ¥&_separator);
MT::Template::Context->add_tag(PageButeLists => ¥&_page_lists);
そのままだとリンクにrel属性を追加できないので、MTPageButeNextURLを作る
プラグインに用意されているMTPageButeNextだと、A要素まで含んだ <a href="url">name</a> という形式で出力してしまうので、AutoPagerize用のrel属性を仕込めない。
URLのみを出力するMTPageButeNextURLを追加する。(追加箇所が散発的でめんどいのでDiff。+のとこを追加する)
$ diff -c Downloads/PageBute.pl Desktop/PageBute.pl
*** Downloads/PageBute.pl 2006-07-11 04:06:00.000000000 +0900
--- Desktop/PageBute.pl 2008-07-01 16:34:50.000000000 +0900
***************
*** 17,22 ****
--- 17,24 ----
my %garbage = (
NextLink => '<!-- NextLink for PageBute -->',
BeforeLink => '<!-- BeforeLink for PageBute -->',
+ NextURL => '<!-- NextURL for PageBute -->',
+ BeforeURL => '<!-- BeforeURL for PageBute -->',
Separator => '<!-- Separator for PageBute -->',
PageLists => '<!-- PageLists for PageBute -->',
Contents => '<!-- Contents for PageBute -->',
***************
*** 80,85 ****
--- 84,97 ----
$garbage{BeforeLink};
}
+ sub _page_next_url {
+ $garbage{NextURL};
+ }
+
+ sub _page_before_url {
+ $garbage{BeforeURL};
+ }
+
sub _separator {
$garbage{Separator};
}
***************
*** 164,169 ****
--- 176,183 ----
my $lists = &_create_lists($page_count, $page_limit);
my $before = $lists->{before} ? &_create_link($page_count - 1, $site_url . $filename, $file_ext, $pb->{before_delim}) : '';
my $next = $lists->{next} ? &_create_link($page_count + 1, $site_url . $filename, $file_ext, $pb->{next_delim}) : '';
+ my $before_url = $lists->{before} ? &_create_url($page_count - 1, $site_url . $filename, $file_ext) : '';
+ my $next_url = $lists->{next} ? &_create_url($page_count + 1, $site_url . $filename, $file_ext) : '';
my $page_lists = '';
for (my $i = $lists->{min_page}; $i <= $lists->{max_page}; $i++) {
$page_lists .= $i == $lists->{min_page} ? '' : $delim;
***************
*** 186,191 ****
--- 200,221 ----
$output =~ s/$garbage{IfPageNext}.*$garbage{IfPageNext}//g;
}
+ #replace before url
+ if ($before_url) {
+ $output =~ s/$garbage{IfPageBefore}//g;
+ $output =~ s/$garbage{BeforeURL}/$before_url/g;
+ } else {
+ $output =~ s/$garbage{IfPageBefore}.*$garbage{IfPageBefore}//g;
+ }
+
+ #replace next url
+ if ($next_url) {
+ $output =~ s/$garbage{IfPageNext}//g;
+ $output =~ s/$garbage{NextURL}/$next_url/g;
+ } else {
+ $output =~ s/$garbage{IfPageNext}.*$garbage{IfPageNext}//g;
+ }
+
#replace page lists
$output =~ s/$garbage{PageLists}/$page_lists/g;
***************
*** 247,250 ****
--- 277,288 ----
$url =~ s|\\|\/|g;
return "<a href=\"${url}\">$name</a>";
}
+
+ sub _create_url {
+ my ($page, $file, $extension) = @_;
+ my $url = $file . ( $page == 1 ? '' : "_${page}" ) . ".${extension}";
+ #for windows
+ $url =~ s|\\|\/|g;
+ return "${url}";
+ }
1;
メインページ テンプレートを編集
<MTEntries>
<$MTEntryTrackbackData$>
<$MTInclude module="ブログ記事の概要"$>
<$MTPageSeparator$>
</MTEntries>
↓
<$MTSetVar name="tmpPaginateValue" value="10"$>
<MTPageContents count="$tmpPaginateValue">
<MTEntries lastn="0">
<$MTEntryTrackbackData$>
<$MTInclude module="ブログ記事の概要"$>
<$MTPageSeparator$>
</MTEntries>
</MTPageContents>
<$MTInclude module="ページ番号"$>
ページ番号 テンプレートモジュールを新規作成
<$MTBlogEntryCount setvar="tmpBlogEntriesCount"$>
<MTIf name="tmpBlogEntriesCount" gt="$tmpPaginateValue">
<ol id="paginate">
<MTIfPageBefore><li class="prev"><a href="<$MTPageBeforeURL$>" rel="prev">« 前の<$MTGetVar name="tmpPaginateValue"$>件</a></li></MTIfPageBefore>
<li class="firstChild"><$MTPageLists delim="</li><li>"$></li>
<MTIfPageAfter><li class="next"><a href="<$MTPageAfterURL$>" rel="next">次の<$MTGetVar name="tmpPaginateValue"$>件 »</a></li></MTIfPageAfter>
</ol>
</MTIf>
AutoPagerize用のmicroformatsを仕込む
次のページのリンクを示す rel="next" はすでに仕込んであるので、AutoPagerizeで継ぎ足す対象を示す class="autopagerize_page_element" のみ仕込めばOK。(autopagerize_insert_before は無くてもいいみたい。ない場合、最後のautopagerizepageelement`の後ろに入る)
ブログ記事の概要 テンプレートモジュールを編集
<div class="section entr" id="entry<$MTEntryID pad="1"$>">
<$MTInclude module="エントリー詳細内部"$>
<$MTInclude module="リアクションリンク"$>
</div>
↓
<div class="section entry autopagerize_page_element" id="entry<$MTEntryID pad="1"$>">
<$MTInclude module="エントリー詳細内部"$>
<$MTInclude module="リアクションリンク"$>
</div>
インデックステンプレートを再構築して終了。
ページ番号のスタイルを指定してないけど面倒になったのでまた今度。
- Newer: VimperatorでコピーやペーストとかOSのショートカットが効かない
- Older: Yoshiori が彼女募集中です