Skip to content

Commit

Permalink
Define the badge add the script to let badge has its own style.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 28, 2024
1 parent 567d02a commit 8634cda
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ This article is written for internal use, just for convenience.
- Utility : Some data-process helper.
- Youtube : Any video upload in youtube.

## Prefix
- [Close duplicated] : Old issue, not implemented or fixed in the current milestone.
## Badge
- [outdated] : Old issue, not implemented or fixed in the current milestone.

## Example link

Expand Down
1 change: 1 addition & 0 deletions layouts/changelog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ <h3 class="single__subtitle">{{ .Params.subtitle }}</h3>
</script>
{{ partial "script/single-script" . }}
{{ partial "script/github-mention-link" . }}
{{ partial "script/badge" . }}
{{ end }}
29 changes: 29 additions & 0 deletions layouts/partials/script/badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script>
// replace [text] to badge style.
function replaceBadge(innerHtml, mappings) {
return innerHtml.replace(/\[(.*?)\]/, (match, p1) => {
const mapping = mappings[p1];
if(!mapping) {
return match;
}

const color = mappings[p1].color;
const style = 'background-color: ' + color + '; color: white; padding: 4px 8px; text-align: center; border-radius: 5px; font-family: Arial, Helvetica, sans-serif;'
const replaceWith = '<span style="' + style + '">' + p1 + '</span>'

return replaceWith;
});
}

const liList = document.getElementsByTagName('li');

for (var i = 0; i<liList.length; i++) {
const li = liList[i];

li.innerHTML = replaceBadge(li.innerHTML, {
outdated: {
color: 'Red',
}
});
}
</script>

0 comments on commit 8634cda

Please sign in to comment.