Skip to content

Commit f4de2af

Browse files
committed
feat: add image-title(#56)
1 parent b2bf3e2 commit f4de2af

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

ChangeLogs.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Changelogs
2+
## 2020.2.2
3+
4+
\[enhancement\] add image-title.
25

36
## 2019.10.18
47

@@ -26,7 +29,7 @@ Changelogs
2629

2730
\[optimization\] change paragraph spacing 0.5em to 1em.Now it's more clear.
2831

29-
## v1.4 - 2019.8.3
32+
## 2019.8.3
3033

3134
\[enhancement\] add pullquote style support.
3235

@@ -38,25 +41,25 @@ Changelogs
3841

3942
fix variable time_format doesn't work in page.
4043

41-
## v1.3 - 2019.7.9
44+
## 2019.7.9
4245

4346
\[enhancement\] change native hexo-toc function to tocbot component.
4447

4548
github: [tscanlin/tocbot: Build a table of contents from headings in an HTML document.](https://github.com/tscanlin/tocbot)
4649

4750

48-
## v1.2 - 2019.7.6
51+
## 2019.7.6
4952

5053
\[enhancement\] add MathJax support,now you can type math formula in LaTeX.
5154

5255
[MathJax | Beautiful math in all browsers.](https://www.mathjax.org/)
5356

5457

55-
## v1.1 - 2019.7.5
58+
## 2019.7.5
5659

5760
\[optimization\] add component fragment_cache in layout to decline requests in render process.
5861

59-
## v1.0 - 2019.6.11
62+
## 2019.6.11
6063

6164
Release the first version.
6265

README-CN.md

+19
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ mathjax:
220220
```
221221
LaTeX语法这里不做解释,本主题中,单dollar符号包围的为行内公式,例:`$f(x)=ax+b$`,双dollar符号包围的为块公式,例`$$f(x)=ax+b$$`更多写法请参考LaTeX和[Demo site中的公式测试页面](https://siricee.github.io/hexo-theme-Chic/2019/07/05/MathJax_test/)。
222222

223+
### 图片标题
224+
225+
在Hexo中,你有两种方式引入图片:
226+
227+
- GFM 语法直接引入(不显示图片标题)
228+
```
229+
![pic](picUrl)
230+
```
231+
- Hexo 内置标签系统-图片标签(显示图片标题)
232+
```
233+
{% img [class names] /path/to/image [width] [height] '"alt text" "title text"' %}
234+
```
235+
所以如果你仅仅想方便快捷引入图片,那你应该使用 GFM 语法,这种方式也是兼容性最好的方案。
236+
237+
但如果你需要显示**图片标题**,你就应该使用第二种方案,**图片标签方式**。
238+
- `"alt text"`用来显示当图片加载失败时垫底的提示文字。
239+
- `"title text"`将会被显示到图片下方作为图片标题。
240+
241+
你可以在 [Demo site](https://siricee.github.io/hexo-theme-Chic/2019/06/05/markdown_test/#Image) 中查看图片标题的效果和示例语法。
223242

224243
## Customize 自定义
225244
- 代码高亮风格 在`hexo-theme-Chic\themes\Chic\source\css\style.styl`中更改highlight为`_highlight`文件夹中的stylus文件即可更换代码高亮风格。

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Configuration](#configuration)
3030
- [Add 'Tag','Category' Page](#add-tagcategory-page)
3131
- [MathJax (Render LaTeX Formula)](#mathjax-render-latex-formula)
32+
- [Image-title](#image-title)
3233
- [Customize](#customize)
3334
- [FAQ](#faq)
3435
- [Gallary](#gallary)
@@ -229,8 +230,25 @@ mathjax:
229230
```
230231
LaTeX grammers will not be illustrated in this doc. In Chic theme, Single '$' rounded statement is regarded as inline formula like `$f(x)=ax+b$` ; Double '$' rounded statement is regarded as block formula like `$$f(x)=ax+b$$`.More information please read LaTeX doc and [Formula test page in Demo Site](https://siricee.github.io/hexo-theme-Chic/2019/07/05/MathJax_test/).
231232

233+
### Image-title
232234

235+
You have 2 method to import image in your post:
236+
237+
- image import with GFM (Without image-title)
238+
```
239+
![pic](picUrl)
240+
```
241+
- hexo built-in image tag (With image-title)
242+
```
243+
{% img [class names] /path/to/image [width] [height] '"alt text" "title text"' %}
244+
```
245+
So if you want to import as fast as possible, you can use GFM,and this way will also get best adaptability.
246+
247+
**If you want to display image-title, you should use hexo built-in image tag.**
248+
- `"alt text"` is used when image not load or something wrong in that image 404.
249+
- `"title text"` **will be displayed below the image.**
233250

251+
You can preview image-title and sample code in [Demo site](https://siricee.github.io/hexo-theme-Chic/2019/06/05/markdown_test/#Image)
234252

235253
## Customize
236254

scripts/.gitkeep

Whitespace-only changes.

scripts/imageTag.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* transfer tag to imagg-box block.
3+
* {% img [class names] /path/to/image [width] [height] '"alt text" "title text"' %}
4+
* This is used to display image title.
5+
*/
6+
hexo.extend.tag.register('img', ([src, alt = '', title = '', imgClass = '']) => {
7+
return `<div class="image-box">
8+
<img src="${src}" alt="${alt}" title="${title}" class="${imgClass}">
9+
<p class="image-box-title">${title || alt}</p>
10+
</div>`;
11+
});

source/css/_page/_post/post_content.styl

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@
121121

122122
img[data-action="zoom"]
123123
cursor zoom-in
124+
// this element is rendered by hexo.extend.tag.register()
125+
// location: scripts/image.js
126+
.image-box
127+
.image-box-title
128+
text-align center
129+
font-size .7em
130+
margin-top .5em
131+
margin-bottom 1em
132+
color $light-font-secondary-color
133+
.dark-theme &
134+
color $dark-font-secondary-color
135+
// end element
124136

125137
blockquote
126138
font-size 1rem

0 commit comments

Comments
 (0)