$subject = __('Site :name publié', ['name' => $wf->name]);
$notify = true;
+ $publishOn = 'dev';
if ($this->mode === 'api') {
$wf->getEditableData();
$notify = false;
$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');
+ } else if ($this->mode === 'production') {
+ $text = __('Le site vient d\'être républié en production');
+ $publishOn = 'production';
} else {
$text = __('Le site vient d\'être républié suite à une déclenchement manuel');
$notify = false;
}
- $wf->compile();
+ $wf->compile($publishOn);
$actions = [];
foreach ($wf->getLocales() as $locale) {
- $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url'];
+ $u = $publishOn === 'dev' ? $locale['url'] : $locale['prod'];
+ $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $u;
}
if ($notify && isset($text)) {
if ($this->user === null) {
$this->addField('publish_on_save', Checkbox::class, __('Publier le site lors de la modification de contenus'), ['default' => true, 'tab' => __('Paramètres')]);
$this->addField('domains', Textarea::class, __('Domaines à télécharger'), ['translatable' => false, 'tab' => __('Paramètres')]);
$this->addField('exclude_domains', Textarea::class, __('Domaines à exclure'), ['translatable' => false, 'tab' => __('Paramètres')]);
- $this->addField('locales_domains', Table::class, __('Langues'), ['translatable' => false, 'columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]);
+ $this->addField('locales_domains', Table::class, __('Langues'), ['translatable' => false, 'columns' => ['locale' => __('Code langue'), 'url' => __('URL de développement'), 'prod' => __('URL en production')], 'tab' => __('Paramètres')]);
$this->addField('slack', Text::class, __('Notification slack'), ['translatable' => false, 'tab' => __('Paramètres')]);
$s = StaticSiteUploader::getSites();
$sites = [];
}
+ public function getLocaleData($code)
+ {
+ foreach ($this->getLocales() as $locale) {
+ if ($locale['locale'] === $code) {
+ return $locale;
+ }
+ }
+ }
+
public function getLocales()
{
return Cache::get('webflow_' . $this->id . '_locales', []);
return $res;
}
- public function compile()
+ public function compile($env = "dev")
{
$this->_parsePages();
foreach ($this->getLocales() as $locale) {
- $this->compileLocale($locale['locale']);
+ $this->compileLocale($locale['locale'], $env);
}
- StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id), $this->upload);
+ StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id . '/' . $env), $this->upload, $env);
}
protected function getCustomCSS()
return Files::mkdir(protected_path('webflow/mirror/' . $this->id));
}
- protected function compileLocale($locale)
+ protected function compileLocale($locale, $env = 'dev')
{
$mirror = $this->getMirrorPath();
- $path = Files::emptyDir(protected_path('webflow/final/' . $this->id . '/' . $locale));
+ $path = Files::emptyDir(protected_path('webflow/final/' . $this->id . '/' . $env . '/' . $locale));
$rsync = new CommandLine\Rsync($mirror, $path, false);
$rsync->addExclude('*.html');
$rsync->execute();
continue;
}
$relative = '/' . str_replace($mirror, '', $f->getPathname());
- $this->compileHTMLFile($f, $relative, $path, $isMainLocale, $locale, $texts, $images, $seo, $urlmap);
+ $this->compileHTMLFile($f, $relative, $path, $isMainLocale, $locale, $texts, $images, $seo, $env);
}
+ $domain = $this->getLocaleData($locale)[$env === 'dev' ? 'url' : 'prod'];
+
// Redirections
$htaccess = '<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
+
+ RewriteCond %{HTTP_HOST} !=' . $domain . '
+ RewriteRule ^(.*)$ https://' . $domain . '/$1 [R=301,L]
+
';
foreach ($this->redirections as $redirection) {
foreach ($seo as $s) {
* @param $locale string
* @return void
*/
- protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo)
+ protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo, $env = 'dev')
{
$urlmaps = $this->getURLMaps();
continue;
}
$u = $urlmaps[$code][$origRelative] ?? $origRelative;
- $localeURL .= 'var SWITCH_URL_' . $code . '="https://' . $l['url'] . $u . '";' . "\n";
+ $d = $l[$env === 'dev' ? 'url' : 'prod'];
+ $localeURL .= 'var SWITCH_URL_' . $code . '="https://' . $d . $u . '";' . "\n";
}
$localeURL .= "</script>";