Skip to content

Instantly share code, notes, and snippets.

@UbaldoRosas
Last active March 11, 2021 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UbaldoRosas/9ec2519525753e366307cbf24cd68594 to your computer and use it in GitHub Desktop.
Save UbaldoRosas/9ec2519525753e366307cbf24cd68594 to your computer and use it in GitHub Desktop.
Shopify product description splitter
// Contenedor en el cual buscar
var parent = $('#data-sections');
var titles = parent.find('h1');
function cleanString(str) {
// Función para reemplazar los caracteres especiales, acentos, espacios
var str = str
.toLowerCase()
.replace('á', 'a')
.replace('é', 'e')
.replace('í', 'i')
.replace('ó', 'o')
.replace('ú', 'u')
.replace('ñ', 'n')
.replace(new RegExp(' ', 'g'), '-');
return str;
}
// Extrae el contenido que hay entre cada título h1
titles.each(function(index, el) {
var title = $(el).text();
var content = $(el).nextUntil('h1');
var data = cleanString(title);
$('[data-'+data+']').append(content);
});
parent.remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment