Boostrap badge#
badge contentSo this is a badge given by bootstrap, we can add this into hexo just simply write some HTML like this.
<span class="badge badge-secondary">badge content</span> |
And yes, this is not like Hexo style, and hardly to modify.
So as last post, let build a tags to insert a badge.
Badge Tags#
badge.js#
First things to do, new a file call badge.js and put into scripts
directory in current theme’s directory:
touch /path/to/your/current/theme/dir/script/badge.js |
if scripts
directory is not existed, first new a directory.
mkdir /path/to/your/current/theme/dir/script |
Then, write down this into lastest javascript file (badge.js).
1 | /** |
In line 23, we registed a tag name badge, and next time we write something like below , it will show like bs badge.
{% badge @blah %} |
Different#
Here is a trivial different point with card we wrote in register
.
hexo.extend.tag.register('badge', postBadge, { ends: false }); |
In the third parameter, we write down { ends: false }
, this will tell hexo that this tag has no end tag. So our badge tag should write like this:
{% badge @blah %} |
And carefully don’t write something like this:
1 | {% badge @blah %} |
Line 2 should not be write down in post markdown file.
Classes#
badge has some different styles, we can use args to implement it.
Args is given by hexo tag api, we can pass argument to tag.
so we combine style name into bs classes, this is the code.
Primary Secondary Success Danger Warning Info Light Dark
Content#
This is how content show.
Content is given by hexo tag api, this is a string inside tag (of course markdown). We can use hexo render engine to show it.
Remind#
This badge styling is using Bootstrap v4.4, so you need to include bs stylesheet in <head>
.
<!-- Latest compiled and minified CSS --> |
Example#
{% badge @badge content %} |
So this is the correct code I wrote in the top. badge class should given by first argument
{% badge primary @Stuff %} |
If not given classes, it will also show secondary classes. So this two are equal.
{% badge @Stuff %} |
And content should put after a @
{% badge @Content here %} |
That is, how does a badge work on hexo by using tag plugins. You can find source code about this website in github if you want to learn more.