diff --git a/app/models/site.rb b/app/models/site.rb
index 4b2a8eb9..6aa96612 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -7,6 +7,7 @@ class Site < ApplicationRecord
include Site::Forms
include Site::FindAndReplace
include Site::Api
+ include Site::BuildStats
include Tienda
# Cifrar la llave privada que cifra y decifra campos ocultos. Sutty
diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb
new file mode 100644
index 00000000..8b23942d
--- /dev/null
+++ b/app/models/site/build_stats.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class Site
+ module BuildStats
+ extend ActiveSupport::Concern
+
+ included do
+ # Devuelve el tiempo promedio de publicación para este sitio
+ #
+ # @return [Integer]
+ def average_publication_time
+ build_stats.group(:action).average(:seconds).values.reduce(:+).round
+ end
+
+ # Devuelve el tiempo promedio de compilación para sitios similares
+ # a este.
+ #
+ # @return [Integer]
+ def average_publication_time_for_similar_sites
+ similar_deploys = Deploy.where(type: deploys.pluck(:type)).pluck(:id)
+
+ BuildStat.where(deploy_id: similar_deploys).group(:action).average(:seconds).values.reduce(:+).round
+ end
+
+ # Define si podemos calcular el tiempo promedio de publicación
+ # para este sitio
+ #
+ # @return [Boolean]
+ def average_publication_time_calculable?
+ build_stats.jekyll.where(status: true).count > 0
+ end
+
+ def similar_sites?
+ !design.no_theme?
+ end
+
+ # Detecta si el sitio todavía no ha sido publicado
+ #
+ # @return [Boolean]
+ def not_published_yet?
+ build_stats.jekyll.where(status: true).count.zero?
+ end
+ end
+ end
+end
diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml
index dbeddaad..f7b884af 100644
--- a/app/views/posts/index.haml
+++ b/app/views/posts/index.haml
@@ -1,7 +1,9 @@
%main.row
%aside.menu.col-md-3
- %h1= link_to @site.title, @site.url
+ %h1= @site.title
%p.lead= @site.description
+ - cache_if @usuarie, [@site, I18n.locale] do
+ = render 'sites/status', site: @site
%h3= t('posts.new')
%table.mb-3
diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml
new file mode 100644
index 00000000..fb38896a
--- /dev/null
+++ b/app/views/sites/_status.haml
@@ -0,0 +1,19 @@
+- link = nil
+- if site.not_published_yet?
+ - message = t('.not_published_yet')
+- if site.building?
+ - if site.average_publication_time_calculable?
+ - average_building_time = site.average_building_time
+ - elsif !site.similar_sites?
+ - average_building_time = 60
+ - else
+ - average_building_time = site.average_publication_time_for_similar_sites
+
+ - average_publication_time_human = distance_of_time_in_words average_building_time
+ - message = t('.building', average_time: average_publication_time_human, seconds: average_building_time)
+- else
+ - message = t('.available')
+ - link = true
+
+= render 'bootstrap/alert' do
+ = link_to_if link, message.html_safe, site.url
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 567ab6bb..ee16f506 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -330,6 +330,10 @@ en:
designer_url: 'Support the designer'
static_file_migration: 'File migration'
find_and_replace: 'Search and replace'
+ status:
+ building: "Your site is building, please wait ..."
+ not_published_yet: "Your site is being published for the first time, please wait up to 1 minute..."
+ available: "Your site is available! Click here to visit it."
index:
title: 'My Sites'
pull: 'Upgrade'
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 0a829e4a..e3d3f2ef 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -335,6 +335,10 @@ es:
designer_url: 'Apoyá a le(s) diseñadore(s)'
static_file_migration: 'Migración de archivos'
find_and_replace: 'Búsqueda y reemplazo'
+ status:
+ building: "Tu sitio se está publicando, por favor espera ..."
+ not_published_yet: "Tu sitio se está publicando por primera vez, por favor espera hasta un minuto..."
+ available: "¡Tu sitio está disponible! Cliquea aquí para visitarlo."
index:
title: 'Mis sitios'
pull: 'Actualizar'