From 996c70f29826b7dd61058a783d8c681d0d5cf9f6 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Jan 2021 15:29:14 -0300 Subject: [PATCH] =?UTF-8?q?guardar=20la=20fecha=20de=20modificaci=C3=B3n?= =?UTF-8?q?=20en=20el=20archivo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit last_modified_at es utilizada por jekyll-feed y otros plugins, aunque nos hubiera gustado updated_at --- app/models/post.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 0c4e017..39de2db 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -141,10 +141,17 @@ class Post < OpenStruct end alias to_param id + # Fecha de última modificación del archivo def updated_at File.mtime(path.absolute) end + # Obtiene la fecha actual de modificación y la guarda hasta la próxima + # vez. + def modified_at + @modified_at ||= Time.now + end + # Solo ejecuta la magia de OpenStruct si el campo existe en la # plantilla # @@ -215,6 +222,7 @@ class Post < OpenStruct # Y que no se procese liquid yaml['liquid'] = false yaml['usuaries'] = usuaries.map(&:id).uniq + yaml['last_modified_at'] = modified_at "#{yaml.to_yaml}---\n\n#{body}" end