Skip to content

Commit

Permalink
kevbadge show description if available
Browse files Browse the repository at this point in the history
add title to button where available
  • Loading branch information
kleutzinger committed Jan 7, 2025
1 parent 9790d33 commit 264c027
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions site-generator/kevbadge.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 " +
Expand All @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion site-generator/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 264c027

Please sign in to comment.