Skip to content

Commit 7b9f48f

Browse files
committed
Blog display tweaks
1 parent 4d75ac0 commit 7b9f48f

File tree

6 files changed

+83
-14
lines changed

6 files changed

+83
-14
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,17 @@ sub slug {
251251
return sprintf( "%d-%s", $self->id, $title );
252252
}
253253

254+
sub posts {
255+
my ( $self ) = @_;
256+
257+
return [ map {
258+
+{
259+
title => $_->title,
260+
url => $_->url,
261+
date => $_->publish_date,
262+
}
263+
} $self->search_related( 'blog_entries')->all ];
264+
}
265+
254266

255267
1;

DB/lib/BlogDB/DB/Result/PendingBlog.pm

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,39 @@ __PACKAGE__->belongs_to(
237237
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-24 04:45:56
238238
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:F4GsyDnhsW34Ywl+BCrVEw
239239

240+
sub tags {
241+
my ( $self ) = @_;
242+
243+
return [map {
244+
+{
245+
id => $_->tag->id,
246+
name => $_->tag->name,
247+
is_adult => $_->tag->is_adult,
248+
}
249+
} $self->search_related('pending_blog_tag_maps', {})->all];
250+
}
251+
252+
sub slug {
253+
my ( $self ) = @_;
254+
255+
my $title = $self->title ? $self->title : $self->url;
256+
257+
$title = lc($title);
258+
s/[^a-zA-Z0-9]/_/g, s/[_]+/_/g, s/^_//, s/_$// for $title;
259+
260+
return sprintf( "%d-%s", $self->id, $title );
261+
}
262+
263+
sub posts {
264+
my ( $self ) = @_;
265+
266+
return [ map {
267+
+{
268+
title => $_->title,
269+
url => $_->url,
270+
date => $_->publish_date,
271+
}
272+
} $self->search_related( 'pending_blog_entries')->all ];
273+
}
240274

241-
# You can replace this text with custom code or comments, and it will be preserved on regeneration
242275
1;

Web/lib/BlogDB/Web/Controller/Blog.pm

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ sub post_new_blog ($c) {
8989
),
9090
});
9191

92-
$c->minion->enqueue( populate_blog_entires => [ $blog->id, 'pending' ]);
9392
$c->minion->enqueue( populate_blog_screenshot => [ $blog->id, 'pending' ]);
9493

9594
$c->redirect_to( $c->url_for( 'edit_new_blog', id => $blog->id ) );
@@ -98,8 +97,8 @@ sub post_new_blog ($c) {
9897
sub get_edit_new_blog ($c) {
9998
$c->set_template( 'blog/new/item' );
10099

101-
my $blog_id = $c->stash->{blog_id} = $c->param('id');
102-
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );
100+
my $blog_id = $c->stash->{blog_id} = $c->param('id');
101+
my $blog = $c->stash->{blog} = $c->db->resultset('PendingBlog')->find( $blog_id );
103102

104103

105104
# Populate the form with the current values.
@@ -120,12 +119,21 @@ sub get_edit_new_blog ($c) {
120119
};
121120

122121
}
122+
123+
foreach my $post ( $blog->search_related('pending_blog_entries')->all ) {
124+
push @{$c->stash->{posts}}, {
125+
title => $post->title,
126+
url => $post->url,
127+
date => $post->publish_date,
128+
};
129+
}
130+
123131
}
124132

125133
sub post_edit_new_blog ($c) {
126134

127-
my $blog_id = $c->stash->{blog_id} = $c->param('id');
128-
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );
135+
my $blog_id = $c->stash->{blog_id} = $c->param('id');
136+
my $blog = $c->stash->{blog} = $c->db->resultset('PendingBlog')->find( $blog_id );
129137

130138

131139
# TODO: This section should be guarded by checking that the user
@@ -147,6 +155,9 @@ sub post_edit_new_blog ($c) {
147155

148156
$blog->update;
149157

158+
# Get Posts from RSS Feed.
159+
$c->minion->enqueue( populate_blog_entries => [ $blog->id, 'pending' ]);
160+
150161
# Remove all tags, then add the tags we have set.
151162
$blog->search_related('pending_blog_tag_maps')->delete;
152163
foreach my $tag_id ( @{$c->every_param('tags')}) {
@@ -173,16 +184,16 @@ sub post_publish_new_blog ($c) {
173184
});
174185

175186
my @tags = $pb->search_related('pending_blog_tag_maps')->all;
176-
177187
foreach my $tag ( @tags ) {
178188
$blog->create_related('blog_tag_maps', {
179189
tag_id => $tag->tag_id,
180190
});
181191
$tag->delete;
182192
}
193+
$pb->search_related('pending_blog_entries')->delete;
183194
$pb->delete;
184195

185-
$c->minion->enqueue( populate_blog_entires => [ $blog->id, 'prod' ]);
196+
$c->minion->enqueue( populate_blog_entries => [ $blog->id, 'prod' ]);
186197
$c->minion->enqueue( populate_blog_screenshot => [ $blog->id, 'prod' ]);
187198

188199
$c->redirect_to( $c->url_for( 'view_blog', slug => $blog->slug ) );

Web/lib/BlogDB/Web/Plugin/MinionTasks.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sub register ( $self, $app, $config ) {
6868
$blog->update;
6969
});
7070

71-
$app->minion->add_task(populate_blog_entires => sub ( $job, $blog_id, $type ) {
71+
$app->minion->add_task(populate_blog_entries => sub ( $job, $blog_id, $type ) {
7272
my $rs1 = $type eq 'pending' ? 'PendingBlog' : 'Blog';
7373
my $rs2 = $type eq 'pending' ? 'PendingBlogEntry' : 'BlogEntry';
7474
my $rs3 = $type eq 'pending' ? 'pending_blog_entries' : 'blog_entries';

Web/templates/default/blog/index.html.tx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
</div>
3939
<div class="col">
40-
<img width="80%" src="/blog_screenshots/[% $blog.id %].jpg">
40+
<img width="80%" src="[% $blog.img_url %]">
4141
</div>
4242
</div>
4343

@@ -68,6 +68,13 @@
6868
<button type="submit" class="btn btn-primary float-end">Post Review</button>
6969
</form>
7070

71+
<div class="row">
72+
<h2>Recent Posts</h2>
73+
%% for $blog.posts -> $post {
74+
<a href="[% $post.url %]" target="_blank" alt="[% $post.date %]">[% $post.title %]</a>
75+
%% }
76+
</div>
77+
7178
<div class="row" style="height: 20em;"></div>
7279

7380

Web/templates/default/blog/new/item.html.tx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
%% }
44

55
%% override panel -> {
6-
<h3>[% $blog_obj.title %]</h3>
6+
<h3>[% $blog.title %]</h3>
77

88

99
<div class="row" style="margin: 2em">
1010
<div class="col">
11-
<form method="post" action="[% $c.url_for( 'do_publish_new_blog', id => $blog_obj.id ) %]">
11+
<form method="post" action="[% $c.url_for( 'do_publish_new_blog', id => $blog.id ) %]">
1212
<button type="submit" class="btn btn-primary float-end">Publish Blog</button>
1313
</form>
1414
</div>
@@ -34,7 +34,7 @@
3434

3535
<div class="row">
3636
<div class="col">
37-
<form method="post" action="[% $c.url_for( 'do_edit_new_blog', id => $blog_obj.id ) %]">
37+
<form method="post" action="[% $c.url_for( 'do_edit_new_blog', id => $blog.id ) %]">
3838

3939
%% include 'default/_/form/input.tx' { type => 'text', name => 'title',
4040
%% title => 'Title',
@@ -83,8 +83,14 @@
8383
</form>
8484
</div>
8585
<div class="col">
86-
<img width="80%" src="[% $blog_obj.img_url %]">
86+
<img width="80%" src="[% $blog.img_url %]">
8787
</div>
8888
</div>
89+
<div class="row">
90+
<h2>Recent Posts</h2>
91+
%% for $blog.posts -> $post {
92+
<a href="[% $post.url %]" target="_blank" alt="[% $post.date %]">[% $post.title %]</a>
93+
%% }
94+
</div>
8995

9096
%% }

0 commit comments

Comments
 (0)