|
|
|
|
@ -105,6 +105,14 @@ sub get_post { |
|
|
|
|
)->read; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub new_post { |
|
|
|
|
my ( $self, $filename ) = @_; |
|
|
|
|
|
|
|
|
|
return MJB::Backend::Jekyll::MarkdownFile->new( |
|
|
|
|
path => $self->repo_path . "/_posts/" . $filename, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub get_title_of_post { |
|
|
|
|
my ( $self, $file ) = @_; |
|
|
|
|
|
|
|
|
|
@ -136,49 +144,7 @@ sub _post_path { |
|
|
|
|
return $self->repo_path . "/_posts/" . $title . ".markdown"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub create_post { |
|
|
|
|
my ( $self, $headers, $content ) = @_; |
|
|
|
|
|
|
|
|
|
# Check if the repo exists, and Update the repo if needed |
|
|
|
|
$self->_ensure_repository_is_latest; |
|
|
|
|
|
|
|
|
|
# Get the file path to write to. |
|
|
|
|
my $post_path = $self->_post_path( $headers ); |
|
|
|
|
|
|
|
|
|
# Ensure the post doesn't exist |
|
|
|
|
die "Error: Cannot create post that already exists at " . $post_path |
|
|
|
|
if -f $post_path; |
|
|
|
|
|
|
|
|
|
# Create the post |
|
|
|
|
open my $sf, ">", $post_path |
|
|
|
|
or die "Failed to open $post_path for writing: $!"; |
|
|
|
|
|
|
|
|
|
print $sf "---\n"; |
|
|
|
|
print $sf join( "\n", map { "$_: " . $headers->{$_} } keys %$headers ); |
|
|
|
|
print $sf "\n---\n"; |
|
|
|
|
print $sf $content; |
|
|
|
|
|
|
|
|
|
close $sf; |
|
|
|
|
|
|
|
|
|
# Add the file to git |
|
|
|
|
$self->system_command( [ qw( git add ), $post_path ], { |
|
|
|
|
chdir => $self->repo_path, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
# Commit the file |
|
|
|
|
$self->system_command( [ qw( git commit -m ), "Created " . $headers->{title} ], { |
|
|
|
|
chdir => $self->repo_path, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
# Push the repo to the store server |
|
|
|
|
$self->system_command( [ qw( git push origin master ) ], { |
|
|
|
|
chdir => $self->repo_path, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub update_post { |
|
|
|
|
sub write_post { |
|
|
|
|
my ( $self, $md_file ) = @_; |
|
|
|
|
|
|
|
|
|
$md_file->write; |
|
|
|
|
|