From 264c0277e642968925bd7bd2fbe5485bf239d1fb Mon Sep 17 00:00:00 2001 From: Kevin Leutzinger <6435727+kleutzinger@users.noreply.github.com> Date: Tue, 7 Jan 2025 02:44:14 -0500 Subject: [PATCH] kevbadge show description if available add title to button where available --- site-generator/kevbadge.js | 19 +++++++++++++++++-- site-generator/package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/site-generator/kevbadge.js b/site-generator/kevbadge.js index 1ba5fd7..1dda203 100644 --- a/site-generator/kevbadge.js +++ b/site-generator/kevbadge.js @@ -1,5 +1,5 @@ (function () { - // "version": "0.0.16", + // "version": "0.0.17", const location = new URL(window.location); const IS_LOCAL_DEV = ["0.0.0.0", "localhost", "127.0.0.1"].includes( location.hostname, @@ -116,6 +116,14 @@ return c[l] > 1 ? c : c[0] || ""; } + const toSimpleChars = (str) => str.replace(/[^a-zA-Z0-9\s.]/g, ""); + + const make_h3 = (text) => { + const h3 = document.createElement("h3"); + h3.innerText = text; + return h3; + }; + const make_link = (url, text) => { const a = document.createElement("a"); a.setAttribute("href", url); @@ -241,7 +249,7 @@ } if (project.repo_url) { const year = project?.date_created?.split("-")[0]; - links.push( + links.unshift( make_link( project.repo_url, "open source code for this page " + @@ -250,6 +258,13 @@ ), ); } + if (project.web_description) { + const simpleDescription = toSimpleChars(project.web_description); + links.unshift(make_h3(simpleDescription)); + // also set title property of kevbadge-button to this text + document.querySelector(".kevbadge-button").title = + `${simpleDescription}\n\n Click for more info`; + } kevbadge_list.appendChild(make_list(links)); } diff --git a/site-generator/package.json b/site-generator/package.json index 298233a..d16a8c9 100644 --- a/site-generator/package.json +++ b/site-generator/package.json @@ -1,6 +1,6 @@ { "name": "kevbadge", - "version": "0.0.16", + "version": "0.0.17", "description": "badge featured on a few of my websites which provides info like source code, links, and other fun things", "main": "kevbadge.js", "scripts": {