[ 新規 ] [ 検索 | 一覧 | FrontPage ] [ 履歴 (RSS) | 差分履歴 (RSS) ] [ ログイン ]
【PR】Amazon | SL-C3000 | SL-C1000(3/18発売!) | SL-C860 | SL-6000W | SL-6000L | SL-6000N

WalWiki/カスタマイズ/同一カテゴリ内自動リンク

差分表示


編集前の状態に戻します。
同一カテゴリー内にページが存在すれば自動的にリンクを張ります
簡単に言うなら、自動リンクのカテゴリ内限定版(で、あってますか?)
*グローバル変数定義

 my @pagelist;                                               # yakty add [category auto link]
 my $category_name;                                          # yakty add [category auto link] [shrink linkname]

*init_form()内の変更

     # yakty add [category auto link] [shrink linkname] start
     if($form{mypage} =~ /^(.+?)\//){
         $category_name = $1;
     } else {
         $category_name = $form{mypage};
     }
     # yakty add [category auto link] [shrink linkname] end
 }

*sub autolink()追加

 # yakty add [category auto link] start
 sub autolink {
     my ($txt) = @_;
     $txt =~ s/<!--.*?-->//g;
     foreach my $page (@pagelist){
         my $key = $page;
         if($page =~ /^$category_name.*\/(.+)$/){
             $key = $1;
         } else {
             $key = $page;
         }
         my $ignoretag = "<\/((a)|(pre)|(form)|(h[1234])|(span))>";
         my $tmp;
         $txt =~ s+(\Q$key\E)(((.*?)($ignoretag))|(?!.*$ignoretag))+
             (length($tmp = $2) > 0 and ($4 !~ /<$6/)) ? $& :
             (
             (defined($link_cache{$page})) ? $link_cache{$page}:
             (length($_ = &make_link($page)) < 1024) ? ($link_cache{$page} = $_) : $_
             ) . $tmp
             +ges;
     }
     return $txt;
 }
 # yakty add [category auto link] end

*text_to_html()内の変更

 sub text_to_html {
     my ($txt, %option) = @_;
     # yakty add [category auto link] start
     my $page = $form{mypage};
     if($database{$page} and not $fixedpage{$page}){
         @pagelist = sort { ($a !~ /^$category_name/ and $b =~ /^$category_name/)
             or (($a =~ /^$category_name/ and $b !~ /^$category_name/) ? -1 : 0)
             or length($b) <=> length($a)
             or $b cmp $a } keys %database;
     } else {
         undef @pagelist;
     }
     # yakty add [category auto link] end

     if ($option{toc}) {
         # Convert @toc (table of contents) to HTML.
         # This part is taken from Makio Tsukamoto's WalWiki.
         my (@tocsaved, @tocresult);
         foreach (@toc) {
             if (/^(-{1,3})(.*)/) {
                 &back_push('ul', length($1), \@tocsaved, \@tocresult);
                 push(@tocresult, '<li>' . $2 . '</li>');
             }
         }
         push(@tocresult, splice(@tocsaved));
         #return join("\n", @tocresult, @result);              # yakty del [category auto link]
         return &autolink(join("\n", @tocresult, @result));    # yakty add [category auto link]
     } else {
         #return join("\n", @result);                          # yakty del [category auto link]
         return &autolink(join("\n", @result));                # yakty add [category auto link]
     }
 }


02333