From 7e8bcc55a11ab2fbdbf5dbba93e3cec6d072aafc Mon Sep 17 00:00:00 2001 From: f Date: Thu, 20 Apr 2023 18:22:00 -0300 Subject: [PATCH 1/5] feat: indicar que se puede publicar el sitio #13178 --- app/models/site/build_stats.rb | 7 +++++++ app/views/sites/_status.haml | 2 ++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + 4 files changed, 11 insertions(+) diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb index 6eebcc84..64e689b6 100644 --- a/app/models/site/build_stats.rb +++ b/app/models/site/build_stats.rb @@ -40,6 +40,13 @@ class Site def not_published_yet? build_stats.jekyll.where(status: true).count.zero? end + + # Hubo cambios desde la última publicación? + # + # @return [Boolean] + def awaiting_publication? + updated_at > (build_stats.jekyll.where(status: true).last&.created_at || updated_at) + end end end end diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index a731aa7d..2d0de7b9 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -1,6 +1,8 @@ - link = nil - if site.not_published_yet? - message = t('.not_published_yet') +- elsif site.awaiting_publication? + - message = t('.awaiting_publication') - if site.building? - if site.average_publication_time_calculable? - average_building_time = site.average_publication_time diff --git a/config/locales/en.yml b/config/locales/en.yml index 3ddf681d..afb470c8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -365,6 +365,7 @@ en: building: "Your site is building, please wait to refresh this page..." 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." + awaiting_publication: "There are unpublished changes. Click the button below and wait a moment to find them on your site." index: title: 'My Sites' pull: 'Upgrade' diff --git a/config/locales/es.yml b/config/locales/es.yml index 01f1085c..d80e2676 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -370,6 +370,7 @@ es: building: "Tu sitio se está publicando, por favor espera para recargar esta página..." 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." + awaiting_publication: "Hay cambios sin publicar, cliqueá el botón debajo y espera un momento para encontrarlos en tu sitio." index: title: 'Mis sitios' pull: 'Actualizar' From 0567e491eedb6c7bf59718b4b684c8c7796b7a53 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 20 Apr 2023 18:22:21 -0300 Subject: [PATCH 2/5] fix: poder ver los mensajes en el orden correcto --- app/views/sites/_status.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/sites/_status.haml b/app/views/sites/_status.haml index 2d0de7b9..9a671d71 100644 --- a/app/views/sites/_status.haml +++ b/app/views/sites/_status.haml @@ -3,7 +3,7 @@ - message = t('.not_published_yet') - elsif site.awaiting_publication? - message = t('.awaiting_publication') -- if site.building? +- elsif site.building? - if site.average_publication_time_calculable? - average_building_time = site.average_publication_time - elsif !site.similar_sites? From 498c8cc5ad5653631b7d8b9d3133111eb4ce3832 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 20 Apr 2023 21:14:12 -0300 Subject: [PATCH 3/5] fix: usar los posts indexados para obtener la diferencia --- app/models/site/build_stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb index 64e689b6..63761bae 100644 --- a/app/models/site/build_stats.rb +++ b/app/models/site/build_stats.rb @@ -45,7 +45,7 @@ class Site # # @return [Boolean] def awaiting_publication? - updated_at > (build_stats.jekyll.where(status: true).last&.created_at || updated_at) + waiting? && updated_at >= (indexed_posts.order(updated_at: :desc).select(:updated_at).first&.updated_at || 1.second.ago) end end end From da873d2efe41ae63d5bb3f63eebfdf6e490a2b10 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 21 Apr 2023 12:10:03 -0300 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20detectar=20si=20el=20sitio=20o=20los?= =?UTF-8?q?=20art=C3=ADculos=20fueron=20modificados=20luego=20de=20publica?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/site/build_stats.rb | 41 ++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb index 63761bae..23931140 100644 --- a/app/models/site/build_stats.rb +++ b/app/models/site/build_stats.rb @@ -41,11 +41,48 @@ class Site build_stats.jekyll.where(status: true).count.zero? end - # Hubo cambios desde la última publicación? + # Cambios posibles luego de la última publicación exitosa: + # + # * Artículos modificados + # * Configuración modificada + # * Métodos de publicación añadidos # # @return [Boolean] def awaiting_publication? - waiting? && updated_at >= (indexed_posts.order(updated_at: :desc).select(:updated_at).first&.updated_at || 1.second.ago) + waiting? && (post_publication_pending? || configuration_publication_pending?) + end + + # Se modificaron artículos después de publicar el sitio por última + # vez + # + # @return [Boolean] + def post_publication_pending? + last_indexed_post_time > last_publication_time + end + + # Se modificó el sitio después de publicarlo por última vez + # + # @return [Boolean] + def configuration_publication_pending? + updated_at > last_publication_time + end + + private + + # Encuentra el último artículo modificado. Si no hay ninguno, + # devuelve la fecha de modificación del sitio. + # + # @return [Time] + def last_indexed_post_time + indexed_posts.order(updated_at: :desc).select(:updated_at).first&.updated_at || updated_at + end + + # Encuentra la fecha de última publicación exitosa, si no hay + # ninguno, devuelve la fecha de modificación del sitio. + # + # @return [Time] + def last_publication_time + build_stats.jekyll.where(status: true).order(created_at: :desc).select(:created_at).first&.created_at || updated_at end end end From 04c9ff5319000c27f404682d712c2f1738886871 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 21 Apr 2023 12:15:22 -0300 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20detectar=20cambios=20de=20configurac?= =?UTF-8?q?i=C3=B3n=20por=20separado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/site/build_stats.rb | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/models/site/build_stats.rb b/app/models/site/build_stats.rb index 23931140..0d1d5a57 100644 --- a/app/models/site/build_stats.rb +++ b/app/models/site/build_stats.rb @@ -49,34 +49,49 @@ class Site # # @return [Boolean] def awaiting_publication? - waiting? && (post_publication_pending? || configuration_publication_pending?) + waiting? && (post_pending? || deploy_pending? || configuration_pending?) end # Se modificaron artículos después de publicar el sitio por última # vez # # @return [Boolean] - def post_publication_pending? + def post_pending? last_indexed_post_time > last_publication_time end # Se modificó el sitio después de publicarlo por última vez # # @return [Boolean] - def configuration_publication_pending? - updated_at > last_publication_time + def deploy_pending? + last_deploy_time > last_publication_time + end + + # Se modificó la configuración del sitio + # + # @return [Boolean] + def configuration_pending? + last_configuration_time > last_publication_time end private - # Encuentra el último artículo modificado. Si no hay ninguno, - # devuelve la fecha de modificación del sitio. + # Encuentra la fecha del último artículo modificado. Si no hay + # ninguno, devuelve la fecha de modificación del sitio. # # @return [Time] def last_indexed_post_time indexed_posts.order(updated_at: :desc).select(:updated_at).first&.updated_at || updated_at end + # Encuentra la fecha de última modificación de los métodos de + # publicación. + # + # @return [Time] + def last_deploy_time + deploys.order(updated_at: :desc).select(:updated_at).first&.updated_at || updated_at + end + # Encuentra la fecha de última publicación exitosa, si no hay # ninguno, devuelve la fecha de modificación del sitio. # @@ -84,6 +99,13 @@ class Site def last_publication_time build_stats.jekyll.where(status: true).order(created_at: :desc).select(:created_at).first&.created_at || updated_at end + + # Fecha de última modificación de la configuración + # + # @return [Time] + def last_configuration_time + File.mtime(config.path) + end end end end