| 1 | package XTaTIK::Model::Blog; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = '0.005003'; # VERSION | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Mojo::Base -base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Text::Markdown 'markdown'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use File::Glob qw/bsd_glob/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use File::Spec::Functions qw/catfile/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use File::Slurp::Tiny 'read_file'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use List::UtilsBy qw/sort_by/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Encode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use experimental 'postderef'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | has 'blog_root'; | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub brief_list { | ||||||||
|
Subroutine
brief_list: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 19 | 0 | my $self = shift; | |||||||||
| 20 | |||||||||||
| 21 | 0 | my @posts= bsd_glob $self->blog_root . '/*'; | |||||||||
| 22 | |||||||||||
| 23 | 0 | for ( @posts ) { | |||||||||
| 24 | 0 | s{^${\ $self->blog_root}/}{}; | |||||||||
| 25 | 0 | my ( $date, $title ) = /(\d{4}-\d{2}-\d{2})-(.+)\.md/; | |||||||||
| 26 | 0 | $title =~ tr/-/ /; | |||||||||
| 27 | 0 | $_ = { | |||||||||
| 28 | date => $date, | ||||||||||
| 29 | title => $title, | ||||||||||
| 30 | url => s/.md$//r, | ||||||||||
| 31 | }; | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | @posts = reverse sort_by { $_->{date} } @posts; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | return \@posts; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub post { | ||||||||
|
Subroutine
post: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||
| 40 | 0 | my $self = shift; | |||||||||
| 41 | 0 | my $post = shift; | |||||||||
| 42 | 0 | my ( $date, $title ) = $post =~ /(\d{4}-\d{2}-\d{2})-(.+)/; | |||||||||
| 43 | 0 | $title =~ tr/-/ /; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $post_src = catfile $self->blog_root, $post =~ s/[^\w-]//rg . '.md'; | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | return unless -e $post_src; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | my ( $next, $prev, $found_next ); | |||||||||
| 50 | 0 | for ( $self->brief_list->@* ) { | |||||||||
| 51 | 0 | ▶ | if ( $_->{url} eq $post ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $found_next = 1; | |||||||||
| 53 | 0 | next; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | $next = $_ unless $found_next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | if ( $found_next ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $prev = $_ ; | |||||||||
| 60 | 0 | last; | |||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | for ( $next, $prev ) { | |||||||||
| 65 | 0 | ▶ | defined or next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | my $post_src = catfile $self->blog_root, | ||||||||||
| 67 | 0 | $_->{url} =~ s/[^\w-]//rg . '.md'; | |||||||||
| 68 | 0 | my $content = decode 'utf8', read_file $post_src; | |||||||||
| 69 | 0 | my %metas; | |||||||||
| 70 | 0 | ▶ | $metas{ $1 } = $2 while $content =~ s/^%\s+(\w+)\s+(.+)$//m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | $_->{description} = $metas{description}; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | my $content = decode 'utf8', read_file $post_src; | |||||||||
| 75 | 0 | my %metas; | |||||||||
| 76 | 0 | ▶ | $metas{ $1 } = $2 while $content =~ s/^%\s+(\w+)\s+(.+)$//m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | return ( | ||||||||||
| 79 | 0 | $title, | |||||||||
| 80 | $date, | ||||||||||
| 81 | \%metas, | ||||||||||
| 82 | markdown($content), | ||||||||||
| 83 | $prev, | ||||||||||
| 84 | $next, | ||||||||||
| 85 | ); | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 1 | 1; | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||