Help - Search - Members - Calendar
Full Version: DirifyDashes
Movable Type Community Forum > Additional Resources > Plugin Development and Usage
ifenn
Hi,

Anil Dash mentions on his weblog that google prefers filenames with dashes, not underscores so I cobbled together this simple plug-in to dirify... but with dashes. Just save the following code as dirifydashes.pl in MT's plugins directory. Then use dirifydashes="1" instead of dirify="1" in your templates.

CODE
# Dirifydashes 1.0
# Same as dirify but converts space chars to dashes

use strict;
use MT::Template::Context;
use MT::Util qw( convert_high_ascii );
use MT::Util qw( remove_html );

MT::Template::Context->add_global_filter(dirifydashes => sub {
   my $s = $_[0];
   $s = convert_high_ascii($s);  ## convert high-ASCII chars to 7bit.
   $s = lc $s;                   ## lower-case.
   $s = remove_html($s);         ## remove HTML tags.
   $s =~ s!&[^;\s]+;!!g;         ## remove HTML entities.
   $s =~ s![^\w\s]!!g;           ## remove non-word/space chars.
   $s =~ tr! !-!s;               ## change space chars to dashes.
   $s;
});


Note: Since writing this plug-in I've found DirifyPlus but it's slightly more difficult to use.

All the best,

--
Ian Fenn
Chopstix Media
garylapointe
Wow, that's WAY shorter than I thought it'd be.

Two questions (for anyone):
1) I want to get it to remove (sometimes multiple) leading spaceS and not replace with dashes. (I put the spaces so categories on my one blog, sort the way I want).
2) I need to fix my .htaccess file so links don't break.

I'm sure both are very short solutions but my reg exp usually break more than I fix.

Thanks!
Gary
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.