]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Mar 2024 13:59:15 +0000 (14:59 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Mar 2024 13:59:15 +0000 (14:59 +0100)
app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php
app/Jobs/WebflowPublish.php
app/Models/ToolWebflow.php
bin/mount.sh

index e3496b4b8d92715363709ea0dd145f5a5f3dfc40..80911200d39490f1d811a8cd96e70cf2ad4a3444 100644 (file)
@@ -68,5 +68,6 @@ trait StaticSiteUploader
         $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id'];
         $rsync = new Rsync($from, $dest);
         $rsync->execute();
+        $rsync->debug();
     }
 }
index c9f1d7174b03ac0e985c965cdf987242484f7b1c..5750bf02e53368078c03e97c9e3fab9af21f3826 100644 (file)
@@ -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) {
index d6a5c509aeceea57b92074140a466b792e2f60ed..2bb3132abfc6614483770233fe00f19bb7b47cfb 100644 (file)
@@ -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('</head>', '<link href="/css/custom.css" rel="stylesheet">' . "\n" . '</head>', $html);
+        $html = str_replace('</body>', '<script src="/js/custom.js"></script>' . "\n" . '</body>', $html);
+
+        file_put_contents($f->getPathname(), $html);
     }
 
     public function onRetrieved(): bool
index 69b491911f17d65aa5a1faa9f67e4eaabaa43422..51685bcdbe0a954c5dada06f7554078ce075c826 100644 (file)
@@ -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