Last active
July 16, 2019 22:24
-
-
Save marciobarrios/0136e9668846e75f3c39d49f5463ae55 to your computer and use it in GitHub Desktop.
Script para generar automáticamente un índice en Squarespace para los posts sobre guías de viaje
This file contains hidden or 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
(function() { | |
if (/guia-para-viajar/.test(window.location.pathname) || /ruta-de-/.test(window.location.pathname)) { | |
if (/^Guía para viajar/.test(document.querySelector(".entry-title").textContent)) { | |
let index = "" | |
const h2 = document.querySelectorAll("h2") | |
h2.forEach(item => { | |
const content = item.textContent | |
if (!/^Datos básicos/.test(content)) { | |
item.id = content | |
index += `<li><a href="#${content}">${content}<a/></li>` | |
} | |
}) | |
const existingSeparator = document.querySelector(".horizontalrule-block") | |
const list = document.createElement("div") | |
list.classList.add("sqs-block", "html-block", "sqs-block-html") | |
const newSeparator = document.createElement("div") | |
newSeparator.classList.add("sqs-block", "horizontalrule-block", "sqs-block-horizontalrule") | |
newSeparator.innerHTML = existingSeparator.innerHTML | |
list.innerHTML = `<div class="sqs-block-content"><h2>Índice de contenidos</h2><ul>${index}</ul></div>` | |
existingSeparator.parentNode.insertBefore(list, existingSeparator) | |
list.parentNode.insertBefore(newSeparator, list) | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment