Skip to content

Commit f8ae89e

Browse files
committed
Blog to support slug attribute
1 parent 5296354 commit f8ae89e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

DB/lib/BlogDB/DB/Result/Blog.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,16 @@ sub tags {
240240
} $self->search_related('blog_tag_maps', {})->all];
241241
}
242242

243+
sub slug {
244+
my ( $self ) = @_;
245+
246+
my $title = $self->title ? $self->title : $self->url;
247+
248+
$title = lc($title);
249+
s/[^a-zA-Z0-9]/_/g, s/[_]+/_/g, s/^_//, s/_$// for $title;
250+
251+
return sprintf( "%d-%s", $self->id, $title );
252+
}
253+
243254

244255
1;

0 commit comments

Comments
 (0)