Skip to content

Commit

Permalink
Blog to support slug attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Nov 24, 2021
1 parent 5296354 commit f8ae89e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions DB/lib/BlogDB/DB/Result/Blog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,16 @@ sub tags {
} $self->search_related('blog_tag_maps', {})->all];
}

sub slug {
my ( $self ) = @_;

my $title = $self->title ? $self->title : $self->url;

$title = lc($title);
s/[^a-zA-Z0-9]/_/g, s/[_]+/_/g, s/^_//, s/_$// for $title;

return sprintf( "%d-%s", $self->id, $title );
}


1;

0 comments on commit f8ae89e

Please sign in to comment.