]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7014 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Jul 2024 18:31:56 +0000 (20:31 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Jul 2024 18:31:56 +0000 (20:31 +0200)
app/Jobs/FluidbookImagesPreprocess.php
app/Models/ToolWebflow.php

index d26f0f7c517e04d35ff6d250cadf87cc0fbd3270..ab027f7d9f69714e47997a26bd50214d49066ec8 100644 (file)
@@ -119,7 +119,7 @@ class FluidbookImagesPreprocess extends Base
                 if ($job->isError()) {
                     Log::error('This file failed ' . $job->getPath());
                 }
-                Log::error('This file is stuck ' . $job->getPath());
+                //Log::error('This file is stuck ' . $job->getPath());
             }
             return true;
         }
index 35c02a545ff63dc6d23abb90a278c875bc107516..7329eac7d7c5f4aeabb6dda2c2a65ab0b61ad21b 100644 (file)
@@ -43,6 +43,8 @@ class ToolWebflow extends ToolboxTranslatableModel
 
     protected $_translationsForCompilation = [];
 
+    protected $_urlMaps = null;
+
     public function setFields()
     {
         parent::setFields();
@@ -416,7 +418,7 @@ class ToolWebflow extends ToolboxTranslatableModel
     {
         $code = '$(".w-webflow-badge").remove();' . "\n";
         foreach ($this->getLocales() as $locale) {
-            $code .= '$("a#switch-' . $locale['locale'] . '").attr("href","https://' . $locale['url'] . '");' . "\n";
+            $code .= 'if($("html").attr("lang")=="' . $locale['locale'] . '"){$("a#switch-' . $locale['locale'] . '").attr("href",null).attr("nohref","");}else{$("a#switch-' . $locale['locale'] . '").attr("href",SWITCH_URL_' . $locale['locale'] . ');}' . "\n";
         }
 
         $js = '$(function(){' . $code . '});';
@@ -479,9 +481,13 @@ class ToolWebflow extends ToolboxTranslatableModel
      * @param $locale string
      * @return void
      */
-    protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo, $urlmap)
+    protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo)
     {
 
+        $urlmaps = $this->getURLMaps();
+        $urlmap = $urlmaps[$locale];
+        $origRelative = $relative;
+
         $html = file_get_contents($f->getPathname());
         $regex = '/("https:\/\/' . $this->webflow . '.webflow.io\/\\\\&quot;)(.*)(\\\\&quot;")/';
         $html = preg_replace($regex, '\"$2\"', $html);
@@ -500,8 +506,25 @@ class ToolWebflow extends ToolboxTranslatableModel
             }
         }
 
+        // Replace URL
+        foreach ($urlmap as $k => $v) {
+            $html = str_replace(ltrim($k, '/'), ltrim($v, '/'), $html);
+        }
+
+
+        $localeURL = "<script>";
+        foreach ($this->getLocales() as $l) {
+            $code = $l['locale'];
+            if ($code === $locale) {
+                continue;
+            }
+            $u = $urlmaps[$code][$origRelative] ?? $origRelative;
+            $localeURL .= 'var SWITCH_URL_' . $code . '="https://' . $l['url'] . $u . '";' . "\n";
+        }
+        $localeURL .= "</script>";
+
         $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);
+        $html = str_replace('</body>', $localeURL . '<script src="/js/custom.js"></script>' . "\n" . '</body>', $html);
 
         $html = preg_replace('/\s+lang=\"[a-zA-Z\-_]{2,6}\"/', ' lang="' . $locale . '"', $html);
 
@@ -512,11 +535,6 @@ class ToolWebflow extends ToolboxTranslatableModel
         // Images
 
 
-        // Replace URL
-        foreach ($urlmap as $k => $v) {
-            $html = str_replace(ltrim($k, '/'), ltrim($v, '/'), $html);
-        }
-
         // SEO
         if (!$isMainLocale || $htmlPage) {
             foreach ($seo as $s) {
@@ -546,7 +564,24 @@ class ToolWebflow extends ToolboxTranslatableModel
         file_put_contents($dest . ($urlmap[$relative] ?? $relative), $html);
     }
 
+    public function getURLMaps()
+    {
+
+        if (null === $this->_urlMaps) {
+            $this->_urlMaps = [];
+            foreach ($this->getLocalesCodes() as $locale) {
+                $this->_urlMaps[$locale] = $this->_getURLMap($locale);
+            }
+        }
+        return $this->_urlMaps;
+    }
+
     public function getURLMap($locale)
+    {
+        return $this->getURLMaps()[$locale];
+    }
+
+    protected function _getURLMap($locale)
     {
         if ($locale === $this->getMainLocale()) {
             return [];