Last active
March 11, 2021 17:42
-
-
Save UbaldoRosas/9ec2519525753e366307cbf24cd68594 to your computer and use it in GitHub Desktop.
Shopify product description splitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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