From 83e5ed10aa245bd81cb2abae87c3384d2bd21264 Mon Sep 17 00:00:00 2001 From: rwietter Date: Thu, 9 Nov 2023 14:35:46 -0300 Subject: [PATCH 1/2] fix: remove termo duplicado --- assets/data/cards_pt-br.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/assets/data/cards_pt-br.json b/assets/data/cards_pt-br.json index a6966210..b704d421 100644 --- a/assets/data/cards_pt-br.json +++ b/assets/data/cards_pt-br.json @@ -169,13 +169,6 @@ "Back-end" ] }, - { - "title": "Python", - "description": "O Python é uma linguagem de programação amplamente usada em aplicações da Web, desenvolvimento de software, ciência de dados e machine learning (ML). Os desenvolvedores usam o Python porque é eficiente e fácil de aprender e pode ser executada em muitas plataformas diferentes.", - "tags": [ - "Back-end" - ] - }, { "title": "UI Design", "description": "É o desenho e execução de uma interface para a pessoa usuária. Por exemplo, garantir que um botão vai ser visto e apertado.", From 0ca9c336ff692ea067b1c7195dc26cb110fcf6c1 Mon Sep 17 00:00:00 2001 From: rwietter Date: Thu, 9 Nov 2023 14:36:24 -0300 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20adiciona=20fun=C3=A7=C3=A3o=20de=20h?= =?UTF-8?q?ash=20para=20gerar=20id=20para=20o=20card?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/script.js | 57 +++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/assets/js/script.js b/assets/js/script.js index 4386891d..5806a729 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -72,15 +72,6 @@ function searchCards() { } -function formatCardTitle(title) { - let formatedWord = title.replace(/\s+/g, "-").toLowerCase(); - formatedWord = formatedWord - .normalize("NFD") - .replace(/[\u0300-\u036f]/g, ""); - formatedWord = formatedWord.replace(/[^\w\-]+/g, ""); - return formatedWord; -} - function insertCardsIntoHtml(data) { let cards = `
@@ -94,17 +85,17 @@ function insertCardsIntoHtml(data) {
` data.forEach((card) => { - const formatedTitle = formatCardTitle(card.title); + const cardId = generateCardId(card.id, card.title, card.description) cards += `
+ }" id="${cardId}">

${card.title}

star { - const formatedTitle = formatCardTitle(card.title); - if (favoriteCards.includes(formatedTitle)) { + const cardId = generateCardId(card.id, card.title, card.description) + if (favoriteCards.includes(cardId)) { if (!card.tags) { card.tags = []; } @@ -206,3 +197,35 @@ async function getCardsFromJson() { searchInput.addEventListener("input", searchCards); filterSelect.addEventListener("change", filterCards); getCardsFromJson(); + +/** + * Generates a card ID using a default UUID or a hash of the card description. + * + * @param {string} defaultCardId - A default UUID generated by the CLI. + * @param {string} title - The title of the card. + * @param {string} description - The description of the card. + * @returns {string} - A generated ID + */ +function generateCardId(defaultCardId, title, description) { + if (defaultCardId) return defaultCardId; + return generateContentId(title, description); +} + +/** + * Calculates a simple hash of the given content. + * + * @param {string} content - The content to be hashed. + * @param {string} title - An additional title to be added to the content. + * @param {number} hash - The initial hash value. + * @returns {string} The hashed representation of the content. + */ +function generateContentId(title = '', description = '', hash = 5381) { + const data = (title + description).slice(0, 32).split(' ').join('') + + for (let i = 0; i < data.length; i++) { + hash = ((hash << 5) + hash) + data.charCodeAt(i); + } + + const hashString = Math.abs(hash).toString(36); // Convert to base-36 string + return hashString; +} \ No newline at end of file