Bootstrap Card#
card header content
card content
So this is a card given by bootstrap, we can add this into hexo just simply write some HTML like this.
<div class="card card-default"> |
But this kind of things is not like Hexo style, and hardly to modify.
Luckly, Hexo is giving us some api call tag plugin, so let made a tag to insert a card!
Tag Plugin#
So what is actually tag plugin is? This is the answer of Hexo doc.
A tag allows users to quickly and easily insert snippets into their posts.
As you see, we can simply build a tag and it will render a block our want. A example is above. This Bs Alert block is write down in .md
like this:
{% alert %} |
And this tag is named by note. OK, let we get started to build card tag.
card Tag#
card.js#
First things to do, new a file call card.js and put into scripts
directory in current theme’s directory:
touch /path/to/your/current/theme/dir/script/card.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 (card.js).
1 | /** |
In line 47, we registed a tag name card, and next time we write something like below , it will show like bs card.
{% card %} |
Classes#
card 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.
Default card
card content
Primary card
card content
Secondary card
card content
Success card
card content
Danger card
card content
Warning card
card content
Info card
card content
Light card
card content
Dark card
card content
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.
header and Footer#
card header and footer is also given in bs, so we can implement it.
Card Header
This is how header work.
- First, you must put your header content between
<!-- header -->
and<!-- endheader -->
. - In card.js, we use RegExp to find correct header content.
- RegExp for header is line 1.
- After finding, we render this stuff by using hexo render engine.
Card Footer
This is how footer work.
- First, you must put your header content between
<!-- footer -->
and<!-- endfooter -->
. - In card.js, we use RegExp to find currect footer content.
- RegExp for footer is line 1.
- After finding, we render this stuff by using hexo render engine.
Remind#
This card styling is using Bootstrap v4.4, so you need to include bs stylesheet in <head>
.
<!-- Latest compiled and minified CSS --> |
Example#
{% card %} |
So this is the correct code I wrote in the top. card box in the tag of:
{% card %} |
And header should put in:
<!-- header --> |
Also footer should put in:
<!-- footer --> |
And this is support classes:
{% card default %}...{% endcard %} |
If not given classes, it will also show default classes. So this two are equal.
{% card default %}...{% endcard %} |
That is, how does a card work on hexo by using tag plugins. You can find source code about this website in github if you want to learn more.