From cfb803cda6c43bd2c0d39ad071b1bf3c24eef301 Mon Sep 17 00:00:00 2001 From: Blog Manager Robot Date: Mon, 17 Oct 2022 21:52:43 +0000 Subject: [PATCH] A bunch of work. --- Web/lib/MJB/Web.pm | 8 +-- Web/lib/MJB/Web/Controller/Dashboard.pm | 29 +++++++++++ Web/templates/dashboard/blog.html.ep | 29 +++++++++++ Web/templates/dashboard/blog_post.html.ep | 52 +++++++++++++++++++ .../dashboard/blog_post_create.html.ep | 52 +++++++++++++++++++ Web/templates/dashboard/blog_posts.html.ep | 38 +++++++------- .../lib/MJB/Backend/Jekyll.pm | 8 +++ .../lib/MJB/Backend/Jekyll/MarkdownFile.pm | 13 ++++- 8 files changed, 206 insertions(+), 23 deletions(-) create mode 100644 Web/templates/dashboard/blog_post.html.ep create mode 100644 Web/templates/dashboard/blog_post_create.html.ep diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm index 8c2d1d1..3b41da7 100644 --- a/Web/lib/MJB/Web.pm +++ b/Web/lib/MJB/Web.pm @@ -114,9 +114,11 @@ sub startup ($self) { $auth->post( '/password' )->to('UserSettings#do_change_password' )->name('do_change_password' ); # Dashboard - $auth->get ( '/dashboard' )->to('Dashboard#index' )->name('show_dashboard' ); - $auth->get ( '/dashboard/blog/:id' )->to('Dashboard#blog' )->name('show_dashboard_blog' ); - $auth->get ( '/dashboard/blog/:id/posts' )->to('Dashboard#blog_posts' )->name('show_dashboard_blog_posts' ); + $auth->get ( '/dashboard' )->to('Dashboard#index' )->name('show_dashboard' ); + $auth->get ( '/dashboard/blog/:id' )->to('Dashboard#blog' )->name('show_dashboard_blog' ); + $auth->get ( '/dashboard/blog/:id/posts' )->to('Dashboard#blog_posts' )->name('show_dashboard_blog_posts' ); + $auth->get ( '/dashboard/blog/:id/post/*mdfile' )->to('Dashboard#blog_post' )->name('show_dashboard_blog_post' ); + $auth->get ( '/dashboard/blog/:id/post' )->to('Dashboard#blog_post_create' )->name('show_dashboard_blog_post_create' ); # Blog Management $auth->get ( '/blog/create' )->to('Blog#create' )->name('show_blog_create' ); diff --git a/Web/lib/MJB/Web/Controller/Dashboard.pm b/Web/lib/MJB/Web/Controller/Dashboard.pm index 13c96c6..c49d999 100644 --- a/Web/lib/MJB/Web/Controller/Dashboard.pm +++ b/Web/lib/MJB/Web/Controller/Dashboard.pm @@ -39,4 +39,33 @@ sub blog_posts ( $c ) { my $blog_posts = $c->stash->{blog_posts} = [ map { $_->read } @{$c->jekyll($blog->domain->name)->list_posts} ]; } +sub blog_post ( $c ) { + my $blog = $c->stash->{blog} = $c->db->blog( $c->param('id') ); + + if ( $blog->person->id ne $c->stash->{person}->id ) { + $c->render( + text => "Error: This blog isn't owned by you.", + status => 404, + format => 'txt', + ); + return; + } + + my $post = $c->stash->{post} = $c->jekyll($blog->domain->name)->get_post( $c->param('mdfile') ); +} + +sub blog_post_create ( $c ) { + my $blog = $c->stash->{blog} = $c->db->blog( $c->param('id') ); + + if ( $blog->person->id ne $c->stash->{person}->id ) { + $c->render( + text => "Error: This blog isn't owned by you.", + status => 404, + format => 'txt', + ); + return; + } + +} + 1; diff --git a/Web/templates/dashboard/blog.html.ep b/Web/templates/dashboard/blog.html.ep index 2dcdb6d..3754cca 100644 --- a/Web/templates/dashboard/blog.html.ep +++ b/Web/templates/dashboard/blog.html.ep @@ -7,6 +7,35 @@ +

<%= $blog->domain->name %>

+ +
+ +
+ + + + % if ( $blog ) {

My Websites

diff --git a/Web/templates/dashboard/blog_post.html.ep b/Web/templates/dashboard/blog_post.html.ep new file mode 100644 index 0000000..d0e3132 --- /dev/null +++ b/Web/templates/dashboard/blog_post.html.ep @@ -0,0 +1,52 @@ +% layout 'standard', title => 'Dashboard', sb_active => 'dashboard'; + + + +

<%= $blog->domain->name %>

+ + + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + + diff --git a/Web/templates/dashboard/blog_post_create.html.ep b/Web/templates/dashboard/blog_post_create.html.ep new file mode 100644 index 0000000..526b190 --- /dev/null +++ b/Web/templates/dashboard/blog_post_create.html.ep @@ -0,0 +1,52 @@ +% layout 'standard', title => 'Dashboard', sb_active => 'dashboard'; + + + +

<%= $blog->domain->name %>

+ + + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + + diff --git a/Web/templates/dashboard/blog_posts.html.ep b/Web/templates/dashboard/blog_posts.html.ep index 2504bba..d9a041d 100644 --- a/Web/templates/dashboard/blog_posts.html.ep +++ b/Web/templates/dashboard/blog_posts.html.ep @@ -7,31 +7,30 @@ -% if ( $blog ) { -

My Websites

-
- - - - - - - - - - - - -
DomainStatus Link
<%= $blog->domain->name %>Manage Blog
-% } +

<%= $blog->domain->name %>

+ + % if ( $blog_posts ) { -

My Posts

- +
+ @@ -39,6 +38,7 @@ + % } diff --git a/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.pm b/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.pm index 1936172..11f14df 100644 --- a/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.pm +++ b/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.pm @@ -97,6 +97,14 @@ sub list_posts { return [ @files ]; } +sub get_post { + my ( $self, $filename ) = @_; + + return MJB::Backend::Jekyll::MarkdownFile->new( + path => $self->repo_path . "/_posts/" . $filename, + )->read; +} + sub get_title_of_post { my ( $self, $file ) = @_; diff --git a/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll/MarkdownFile.pm b/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll/MarkdownFile.pm index f0062c6..d48a00b 100644 --- a/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll/MarkdownFile.pm +++ b/libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll/MarkdownFile.pm @@ -8,6 +8,16 @@ has path => ( required => 1, ); +has filename => ( + is => 'lazy', +); + +sub _build_filename { + my ( $self ) = @_; + + return (split( /\//, $self->path ))[-1]; +} + has headers => ( is => 'rw', default => sub { return +{} }, @@ -31,13 +41,14 @@ sub read { my ( $yaml, $markdown ) = ( undef, undef ); while ( defined( my $line = <$lf> ) ) { - $sep_count++ if $line =~ /^---$/; if ( $sep_count < 2 ) { $yaml .= $line; } else { $markdown .= $line; } + + $sep_count++ if $line =~ /^---$/; } $self->headers( Load($yaml) );
Title DateEdit
<%= $post->headers->{title} %> <%= $post->headers->{date} %>Edit Post