Plugin -- hexo-tag-figure
Summary of this post
This post is my notes for the following topics:
- hexo plugin: hexo-tag-figure
- adding additional CSS style settings to NexT theme (by configuring
custom_file_path
in the file_config.next.yml
)
此篇主要是記錄hexo-tag-figure
的使用心得,以及如何使用_config.next.yml
中的custom_file_path
參數設定來增加自定義 CSS 設定內容的相關筆記。
Environment
hexo-tag-figure: 0.4.1
NexT: 8.2.1
hexo: 5.3.0
hexo-cli: 4.2.0
os: Windows_NT 10.0.18363 win32 x64
hexo-tag-figure
GitHub
Example
Code
figure--center
: theclass name
of the figure element. This is the required argument, though in the end I didn’t apply customized CSS style to this class, this argument can not be skipped.hexo-tag-figure/book-cover.jpg
: the image path. Check the source code to find the path logic: (update on Feb 16 2021: I change thepermalink
setting from:year/:month/:day/:title/
to:title/
, thus the image path needs to be updated too. The image path in the screenshot includes:year/:month/:day/:title/
since I previously set thepermalink
in this form 😅) Aad the permalink:title/
as prefix to load the image. 文件沒有特別針對 image path 做說明,從 DevTools 觀察了一下其他還沒使用 hexo-tag-figure 插入的圖片路徑,測試後發現 image path 要加上 permalink。300
: the image width. I skip the height setting.Confessions of a Young Novelist
: the title text that is placed infigcaption
element. Add customized font color and font size to this element.Book cover of Confessions of a Young Novelist
: the alt text for this image.
CSS
- According to NexT’s document, extra CSS settings can be added by enable the
custom_file_path
in theme config file (in my case the_config.next.yml
in root folder). This is my configuration:
# Define custom file paths.
# Create your custom files in site directory `source/_data` and uncomment needed files below.
custom_file_path:
#head: source/_data/head.njk
#header: source/_data/header.njk
#sidebar: source/_data/sidebar.njk
#postMeta: source/_data/post-meta.njk
#postBodyEnd: source/_data/post-body-end.njk
#footer: source/_data/footer.njk
#bodyEnd: source/_data/body-end.njk
#variable: source/_data/variables.styl
#mixin: source/_data/mixins.styl
style: source/_data/styles.styl # Enable this option by removing the '#' in the beginning of the line
- Add the
styles.styl
file in the pathC:\Projects\hexo_blog\source\_data
- Add CSS settings for
figcaption
element, remove each image’s bottom margin by setting themargin-button
to 0px. Withmargin-button
set as 0px, the text underneath (thefigcaption
) will be closer to the image.
figcaption {
color: #999;
text-align: center;
font-size: 14px; # Set to 14px to make the font size same as the text in table of content
}
.post-body img {
margin-bottom: 0px;
}
- Save the configuration and run
hexo generate
andhexo deploy
, done ☕