Applicable to >= 3.8.0
The sidebar now supports customization, allowing you to add your favorite widgets. You can add your own widgets or sort existing ones (the Blog Data
and Announcement
widgets are fixed, but others can be sorted).
Widget Sorting
You only need to configure the sort_order
. (It uses the order
property of the Flex
layout. For specific details, you can refer to the Mozilla documentation. In simple terms, use numbers to specify the sorting order. If not configured, the default value is 0. The smaller the number, the higher the sorting order.
1 | aside: |
Customizing Widgets
If you want to add your own content to the sidebar, you can customize it.
Create widget.yml
Create a file widget.yml
in the source/_data
directory of your Hexo blog (if the _data folder doesn't exist, create it).
Format
1 | top: |
Parameter Explanation
top: The created widget will appear in the non-sticky area (visible on all pages).
bottom: The created widget will appear in the sticky area (except for the article page).
Parameter | Explanation |
---|---|
class_name | The parent class name of the created widget (optional) |
id_name | The parent id name of the created widget (optional) |
name | The title of the created widget |
icon | The icon of the created widget |
order | The sorting order of the created widget (optional) |
html | The relevant code of the created widget |
The generated code will be:
1 | <div class="card-widget Your_written_class_name" id="Your_written_id_name" style="order: Your_written_order"> |
If you need to make UI adjustments to the added widgets, please add CSS to the inject.
Example
Let's take the Visitor Map as an example:
Get the HTML code for the visitor map:
1
<script type="text/javascript" id="clstr_globe" src="//clustrmaps.com/globe.js?d=5V2tOKp8qAdRM-i8eu7ETTO9ugt5uKbbG-U7Yj8uMl8"></script>
Create widget.yml:
1
2
3
4
5
6
7bottom:
- class_name: user-map
id_name: user-map
name: Visitor Map
icon: fas fa-heartbeat
order:
html: '<script type="text/javascript" id="clstr_globe" src="//clustrmaps.com/globe.js?d=5V2tOKp8qAdRM-i8eu7ETTO9ugt5uKbbG-U7Yj8uMl8"></script>'Run Hexo