From: Vincent Vanwaelscappel Date: Tue, 12 Mar 2024 13:59:15 +0000 (+0100) Subject: wip #6775 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6a65e90f45c293b99f5ae6a18e1dc949ec614196;p=fluidbook-toolbox.git wip #6775 @3 --- diff --git a/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php b/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php index e3496b4b8..80911200d 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php +++ b/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php @@ -68,5 +68,6 @@ trait StaticSiteUploader $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id']; $rsync = new Rsync($from, $dest); $rsync->execute(); + $rsync->debug(); } } diff --git a/app/Jobs/WebflowPublish.php b/app/Jobs/WebflowPublish.php index c9f1d7174..5750bf02e 100644 --- a/app/Jobs/WebflowPublish.php +++ b/app/Jobs/WebflowPublish.php @@ -2,7 +2,6 @@ namespace App\Jobs; -use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader; use App\Models\ToolWebflow; use App\Models\User; use App\Notifications\ToolboxNotification; @@ -32,7 +31,7 @@ class WebflowPublish extends Base $wf = ToolWebflow::withoutGlobalScopes()->find($this->id); $subject = __('Site :name publié', ['name' => $wf->name]); if ($this->mode === 'webflow') { - $wf->mirror(false, true)->debug(); + $wf->mirror(false, rand(1, 10) === 10); $text = __('Le site vient d\'être républié suite à une mise à jour de webflow'); } else if ($this->mode === 'auto') { $text = __('Le site vient d\'être républié suite à une mise à jour des contenus'); @@ -40,6 +39,7 @@ class WebflowPublish extends Base $text = __('Le site vient d\'être républié suite à une déclenchement manuel'); } + $wf->compile(); $actions = []; foreach ($wf->getLocales() as $locale) { diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index d6a5c509a..2bb3132ab 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -6,16 +6,15 @@ use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader; use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation; use App\Jobs\WebflowPublish; use App\Models\Base\ToolboxModel; - +use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Backpack\Magic\Fields\Table; use Cubist\Backpack\Magic\Fields\Text; use Cubist\Backpack\Magic\Fields\Textarea; -use Cubist\Backpack\Magic\Fields\URL; use Cubist\Util\CommandLine; use Cubist\Util\Files\Files; -use Cubist\Util\Files\VirtualDirectory; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; // __('!! Outils') class ToolWebflow extends ToolboxModel @@ -45,6 +44,8 @@ class ToolWebflow extends ToolboxModel $sites[$k] = $item['label']; } $this->addField('upload', SelectFromArray::class, __('Uploader sur'), ['options' => $sites, 'tab' => __('Paramètres')]); + $this->addField('js', Code::class, __('Javascript complémentaire'), ['language' => 'js', 'tab' => __('Code')]); + $this->addField('css', Code::class, __('CSS complémentaire'), ['language' => 'css', 'tab' => __('Code')]); //$this->addField('texts'); //$this->addField('images'); //$this->addField('seo'); @@ -74,7 +75,7 @@ class ToolWebflow extends ToolboxModel */ public function mirror($slow = true, $force = false) { - $path = Files::mkdir(protected_path('webflow/mirrors/' . $this->id)); + $path = Files::mkdir(protected_path('webflow/mirror/' . $this->id)); if ($force) { $path = Files::emptyDir($path); } @@ -112,7 +113,7 @@ class ToolWebflow extends ToolboxModel } - protected function compile() + public function compile() { foreach ($this->getLocales() as $locale) { $this->compileLocale($locale['locale']); @@ -120,12 +121,51 @@ class ToolWebflow extends ToolboxModel StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id), $this->upload); } + protected function getCustomCSS() + { + $css = ''; + + return $css . "\n\n" . $this->css; + } + + protected function getCustomJS() + { + $js = ''; + + return $js . ";\n\n" . $this->js; + } + protected function compileLocale($locale) { - $mirror = Files::mkdir(protected_path('webflow/mirrors/' . $this->id)); + $mirror = Files::mkdir(protected_path('webflow/mirror/' . $this->id)); $path = Files::mkdir(protected_path('webflow/final/' . $this->id . '/' . $locale)); $rsync = new CommandLine\Rsync($mirror, $path, true); $rsync->execute(); + + file_put_contents(Files::mkdir($path . '/css') . 'custom.css', $this->getCustomCSS()); + file_put_contents(Files::mkdir($path . '/js') . 'custom.js', $this->getCustomJS()); + + foreach (Files::getRecursiveDirectoryIterator($path) as $f) { + /** @var $f \SplFileInfo */ + if ($f->isDir() || $f->getExtension() !== 'html') { + continue; + } + $this->compileHTMLFile($f, $locale); + } + } + + /** + * @param $f \SplFileInfo + * @param $locale string + * @return void + */ + protected function compileHTMLFile($f, $locale) + { + $html = file_get_contents($f->getPathname()); + $html = str_replace('', '' . "\n" . '', $html); + $html = str_replace('', '' . "\n" . '', $html); + + file_put_contents($f->getPathname(), $html); } public function onRetrieved(): bool diff --git a/bin/mount.sh b/bin/mount.sh index 69b491911..51685bcdb 100644 --- a/bin/mount.sh +++ b/bin/mount.sh @@ -20,7 +20,7 @@ if mountpoint -q "/application/usstorage"; then : else umount -l -q /application/usstorage - sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o uid=1001 -o gid=33 -o allow_other -o cache=yes -o kernel_cache -o compression=no -o large_read -o Ciphers=arcfour fluidbook@kingkong.cubedesigners.com:/home/fluidbook/data /application/usstorage + sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o uid=1001 -o gid=33 fluidbook@kingkong.cubedesigners.com:/home/fluidbook/data /application/usstorage fi mkdir -p /application/protected/fluidbookpublication/docs