Skip to content

Commit 68bc742

Browse files
committed
feat: achieve line number setting
1 parent 0541ea3 commit 68bc742

File tree

4 files changed

+96
-14
lines changed

4 files changed

+96
-14
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Kaldorei
2+
23
A Simple And Elegant Ghost Theme Derive From Default Theme Casper
34

4-
![Ghost 2.x](https://img.shields.io/badge/Ghost-v2.x-blue.svg?style=flat-square)
5-
![Kaldorei 2.1.0](https://img.shields.io/badge/Kaldorei-v2.1.0-009a61.svg?style=flat-square)
5+
![Ghost 3.x](https://img.shields.io/badge/Ghost-v3.x-blue.svg?style=flat-square)
6+
![Kaldorei 3.0.0](https://img.shields.io/badge/Kaldorei-v3.0.0-009a61.svg?style=flat-square)
67

7-
# Preview
8+
## Preview
89

910
![img](assets/img/preview.png)
1011

1112
## Plan to do
13+
1214
- [x] 主题基调定为小清新绿色
1315

1416
- [x] 文章样式色调为墨蓝色
@@ -48,14 +50,17 @@ Ghost2.x版本中支持了语言的切换,Kaldorei 同时也支持了中/英
4850
> 方法:ghost后台 > `General` > `Publication Language` 改为 `zh` 即可
4951
5052
### 🏷️ 标签统计
53+
5154
Kaldorei使用了ghost的api来做统计,所以需要开启ghost的实验室中的`Public API`功能。
5255

5356
> 方法:ghost后台 > `labs` > `Enable Beta Features` > `勾选 Public API`
5457
5558
### 🌄 图片幻灯片
59+
5660
Kaldorei集成了fancyBox,支持图片暗箱效果、幻灯片轮播、全屏预览、缩略图预览等功能。预览&使用方法[图片预览](http://xlbd.me/how-to-use-fancybox-in-ghost-blog/)
5761

5862
### 💬 开启Disqus
63+
5964
Kaldorei支持Disqus讨论插件,只需在后台`代码注入`处添加一段代码。
6065

6166
> 方法:ghost后台 > `Code Injection` > `Blog Header`
@@ -67,6 +72,7 @@ Kaldorei支持Disqus讨论插件,只需在后台`代码注入`处添加一段
6772
```
6873

6974
### 🗂 开启归档功能
75+
7076
Kaldorei提供了简单的归档功能,使用ghost的api来生成归档,预览[博客归档](http://xlbd.me/archives)
7177

7278
> 方法:ghost后台:
@@ -76,6 +82,7 @@ Kaldorei提供了简单的归档功能,使用ghost的api来生成归档,预
7682
> * 去博客首页看看你的归档吧,Have fun.
7783
7884
### 🎨 更换代码主题
85+
7986
Kaldorei使用[highlight.js](https://github.com/isagalaev/highlight.js)实现代码高亮,默认使用的主题风格为 `monokai-sublime`
8087

8188
> 方法:ghost后台 > `Code Injection` > `Blog Header`
@@ -87,6 +94,34 @@ Kaldorei使用[highlight.js](https://github.com/isagalaev/highlight.js)实现代
8794

8895
[完整主题列表](https://highlightjs.org/static/demo/)
8996

97+
### 🔢 开启显示代码行号
98+
99+
> 主题版本 3.x 新增
100+
101+
Kaldorei 实现了配置的方式开启显示代码行号,默认是关闭的,支持 `dark` / `light` 两种模式
102+
103+
> 方法:ghost后台 > `Code Injection` > `Blog Header`
104+
105+
```js
106+
<script>
107+
var hljsSettings = {
108+
lineNumber: true, // 可选值 flase / true, 默认为 false
109+
mode: 'light' // 可选值 dark / light,默认为 'dark'
110+
};
111+
</script>
112+
```
113+
114+
不仅行号可以配置,行号的背景色也可以自定义,默认行号背景色如下:
115+
116+
```html
117+
<style>
118+
:root {
119+
--linenumber-dark-bg: #282c34;
120+
--linenumber-light-bg: #c5d2d9;
121+
}
122+
</style>
123+
```
124+
90125
### 🔍 搜索功能
91126

92127
搜索引擎默认支持按博文标题搜索,此功能需要安装的 `ghost` 版本 >= `2.10.x`

assets/css/screen.css

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,16 +2200,53 @@ pre {
22002200
overflow: hidden;
22012201
}
22022202
code.has-numbering {
2203+
display: block;
22032204
margin-left: 32px;
22042205
padding: 0.5em;
22052206
white-space: pre;
22062207
word-wrap: normal;
2207-
display: block;
22082208
}
22092209
code.hljs {
22102210
padding: 1.2em 2em;
22112211
}
22122212

2213+
pre .line-numbering {
2214+
position: absolute;
2215+
top: 0;
2216+
width: 3.5rem;
2217+
text-align: center;
2218+
color: rgba(255, 255, 255, 0.3);
2219+
padding: 1.25rem 0;
2220+
line-height: 1.4;
2221+
z-index: 10;
2222+
display: flex;
2223+
flex-direction: column;
2224+
height: 100%;
2225+
justify-content: space-evenly;
2226+
}
2227+
2228+
pre .line-numbering.light {
2229+
color: currentColor;
2230+
}
2231+
2232+
pre code.has-numbering::after {
2233+
content: '';
2234+
position: absolute;
2235+
z-index: 2;
2236+
top: 0;
2237+
left: 0;
2238+
width: 3.5rem;
2239+
height: 100%;
2240+
border-radius: 6px 0 0 6px;
2241+
border-right: 1px solid rgba(0, 0, 0, 0.66);
2242+
background-color: var(--linenumber-dark-bg);
2243+
}
2244+
2245+
pre code.has-numbering.light::after {
2246+
background-color: var(--linenumber-light-bg);
2247+
border-right: currentColor;
2248+
}
2249+
22132250
/* ==========================================================================
22142251
23. Archives
22152252
========================================================================== */

assets/css/variables.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
--midgrey: #738a94;
1515
--lightgrey: #c5d2d9;
1616
--whitegrey: #e5eff5;
17+
--linenumber-dark-bg: #282c34;
18+
--linenumber-light-bg: #c5d2d9;
1719

1820
/* font-family */
1921
--sans-serif: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

assets/js/index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,29 @@
3131
scrollToTop();
3232
});
3333

34+
// hljs settings
35+
if (typeof hljsSettings === "undefined") {
36+
window.hljsSettings = {};
37+
}
38+
3439
// highlight config
3540
hljs.initHighlightingOnLoad();
3641
// dynamicInjectHljsStyle()
3742

3843
// numbering for pre>code blocks
39-
// $(function() {
40-
// $('pre code').each(function() {
41-
// var lines = $(this).text().split('\n').length - 1;
42-
// var $numbering = $('<ul/>').addClass('pre-numbering');
43-
// $(this).addClass('has-numbering').parent().append($numbering);
44-
// for (var i = 1; i <= lines; i++) {
45-
// $numbering.append($('<li/>').text(i));
46-
// }
47-
// });
48-
// });
44+
if (hljsSettings.lineNumber) {
45+
$(function () {
46+
$('pre code').each(function () {
47+
var lines = $(this).text().split('\n').length - 1;
48+
var mode = hljsSettings.mode || 'dark'
49+
var $numbering = $('<div/>').addClass('line-numbering').addClass(mode);
50+
$(this).addClass('has-numbering').addClass(mode).parent().append($numbering);
51+
for (var i = 1; i <= lines; i++) {
52+
$numbering.append($('<span/>').text(i));
53+
}
54+
});
55+
});
56+
}
4957

5058
// toc config
5159
var toc = $('.toc');

0 commit comments

Comments
 (0)