Extend blog creation to create blogs.

master
Blog Manager Robot 3 years ago
parent 6f4a0fd6ce
commit 7372e6f57d
  1. 10
      Web/lib/MJB/Web.pm
  2. 17
      Web/lib/MJB/Web/Controller/Blog.pm

@ -1,6 +1,7 @@
package MJB::Web;
use Mojo::Base 'Mojolicious', -signatures;
use MJB::DB;
use MJB::Backend::Jekyll;
sub startup ($self) {
my $config = $self->plugin('NotYAMLConfig', { file => -e 'mjb.yml'
@ -21,6 +22,15 @@ sub startup ($self) {
return state $db = MJB::DB->connect($config->{database}->{mjb});
});
$self->helper( jekyll => sub ($c, $domain) {
return MJB::Backend::Jekyll->new(
root => '/home/manager/mjb/Web/repos', # Make a config option.
domain => $domain,
init_from => 'https://store.myjekyllblog.com/symkat/symkat.jekyllblog.com.git',
repo => 'git@store.myjekyllblog.com:mjb/' . $domain . '.git',
);
});
# Minion plugin & tasks
$self->plugin( Minion => { Pg => $self->config->{database}->{minion} } );

@ -27,6 +27,9 @@ sub do_create ($c) {
$domain = $domain ? $domain : $subdomain . '.' . $c->config->{customer_domain};
# Create the Jekyll repo for the site
my $jekyll = $c->jekyll($domain)->init;
my $blog = try {
$c->db->storage->schema->txn_do( sub {
# Make the domain name record.
@ -39,6 +42,10 @@ sub do_create ($c) {
domain_id => $domain_record->id,
});
$blog->create_related( 'repoes', {
url => $jekyll->repo,
});
return $blog;
});
} catch {
@ -50,11 +57,19 @@ sub do_create ($c) {
$domain = $domain ? $domain : $subdomain . '.' . $c->config->{hosted_domain};
# Create the Jekyll repo for the site
# Configure DNS to point to the blog
# Schedule a job to deploy the website
my $ssl_job_id = $c->minion->enqueue( 'create_ssl_cert', [ $blog->id ], {
notes => { '_mjb_bid_' . $blog->id => 1 },
queue => 'certbot',
});
$c->minion->enqueue( 'deploy_blog', [ $blog->id ], {
notes => { '_mjb_bid_' . $blog->id => 1 },
parents => [ $ssl_job_id ],
});
# Take the user to the management panel for the site

Loading…
Cancel
Save