From 8fe964686bfc7c46e5b89636c9fd3b47d23dc6e7 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 May 2024 15:00:08 -0300 Subject: [PATCH] feat: eliminar tildes de una string, sin transliterar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit usamos esto porque es más rápido y podemos tener un proceso similar en js sin implementar transliteración --- app/lib/core_extensions/string/remove_diacritics.rb | 12 ++++++++++++ config/initializers/core_extensions.rb | 1 + 2 files changed, 13 insertions(+) create mode 100644 app/lib/core_extensions/string/remove_diacritics.rb diff --git a/app/lib/core_extensions/string/remove_diacritics.rb b/app/lib/core_extensions/string/remove_diacritics.rb new file mode 100644 index 00000000..679db13d --- /dev/null +++ b/app/lib/core_extensions/string/remove_diacritics.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module CoreExtensions + module String + # Elimina tildes + module RemoveDiacritics + def remove_diacritics + unicode_normalize(:nfd).gsub(/[^\x00-\x7F]/, '') + end + end + end +end diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 7d1eab9e..6861da45 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true String.include CoreExtensions::String::StripTags +String.include CoreExtensions::String::RemoveDiacritics Jekyll::Document.include CoreExtensions::Jekyll::Document::Path Jekyll::DataReader.include Jekyll::Readers::DataReaderDecorator