# MT::Entry::permalink
# For content negotiation and MultiViews of Apache
#
# Special thanks to
#     Shinya: http://www.code-404.net/
#             http://d.hatena.ne.jp/code404/20050614#p1
#     Topia a.k.a. god: http://www.clovery.jp/
package MT::Plugin::RemoveExtFromPermalink;

use strict;
use MT 3.0;
use MT::Entry;

@MT::Plugin::RemoveExtFromPermalink::ISA = qw(MT::Plugin);

our $VERSION = '0.4';
(our $PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://;

my $plugin;
MT->add_plugin($plugin = __PACKAGE__->new({
    name	=> q{RemoveExtFromPermalink},
    description	=> qq{For content negotiation and MultiViews of Apache. Version $VERSION},
    version	=> $VERSION,
    # config_link	=> q{.},
    doc_link	=> q{http://blog.drry.jp/2005/06/30/0158},
    # author_name	=> q{},
    # author_link	=> q{http://profile.typekey.com/},
}));

sub instance { $plugin }

no warnings qw(redefine);

my $original_permalink = \&MT::Entry::permalink;
my $modified_permalink = sub {
    my $url = $original_permalink->(@_);
    my ($entry) = @_;
    my $blog = $entry->blog();
    my $index = MT->instance->config('IndexBasename');
    my $ext = $blog->file_extension;
    $url =~ s/(?:${index}(?:\.\w+)*)?\.${ext}(?>(#|$))/$1/;
    $url;
};

*MT::Entry::permalink = $modified_permalink;

1;
__END__


