hexo-auto-toc 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/index.js +9 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm install hexo-auto-toc
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
2. The plugin will automatically parse all content within the `<article>` tag and generate a table of contents.
|
|
20
|
-
If your article page structure does not wrap the content inside an `<article>` element, you
|
|
20
|
+
If your article page structure does not wrap the content inside an `<article>` element, contents in`<body>` will be parsed. Or you can add `<article>` manually — typically in the `index.html` file under your `blog` folder, but this is not necessary.
|
|
21
21
|
3. check the effects: `hexo clean&&hexo g&&hexo s`
|
|
22
22
|
|
|
23
23
|
- 使用
|
|
@@ -28,7 +28,7 @@ npm install hexo-auto-toc
|
|
|
28
28
|
npm install hexo-auto-toc
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
2. 插件会自动对`<article>`包含下的所有内容进行解析,自动生成目录。如果你的文章页面结构中内容没被`<article
|
|
31
|
+
2. 插件会自动对`<article>`包含下的所有内容进行解析,自动生成目录。如果你的文章页面结构中内容没被`<article>`包裹,将会解析`<body>`下的所有内容;你可以自行添加`<article>`(即blog文件夹下的index.html),但不是必须的。
|
|
32
32
|
2. 查看效果 `hexo clean&&hexo g&&hexo s`
|
|
33
33
|
|
|
34
34
|
- 效果 Example
|
|
@@ -49,6 +49,19 @@ npm install hexo-auto-toc
|
|
|
49
49
|
|
|
50
50
|
优化toc放置左/右,自动选择放在哪边
|
|
51
51
|
|
|
52
|
+
- New Updates
|
|
53
|
+
|
|
54
|
+
- version 1.0.6
|
|
55
|
+
Except index page, other pages have TOC if they have kinds of headers.
|
|
56
|
+
|
|
57
|
+
- version 1.0.5
|
|
58
|
+
Greater compatibility: Works with a wider variety of themes.
|
|
59
|
+
Performance Boost: Optimized the regular expressions for better matching.
|
|
60
|
+
Reliable Parsing: Integrated the Cheerio library to parse HTML, avoiding the drawbacks and errors common with regular expressions.
|
|
61
|
+
Smarter Positioning: Improved the Table of Contents (TOC) module's location; it will now be placed directly after the
|
|
62
|
+
element if one is present.
|
|
63
|
+
Automatic Layout: Enhanced the left/right placement of the TOC, allowing it to automatically choose the best side.
|
|
64
|
+
|
|
52
65
|
# Recommendations
|
|
53
66
|
|
|
54
67
|
- hexo-everyday-calendar:This is a practical calendar plugin for hexo bloggers, like contribution statistics on GitHub.
|
package/index.js
CHANGED
|
@@ -98,7 +98,7 @@ hexo.extend.filter.register('after_render:html', function (html) {
|
|
|
98
98
|
|
|
99
99
|
|
|
100
100
|
(function() {
|
|
101
|
-
const Patternstr = "
|
|
101
|
+
const Patternstr = "\/*\\\\\d{4}\/\\\\\d{2}\/\\\\\d{2}\/\.*"; //本身是字符串插入,所以对符号要转义
|
|
102
102
|
//"^\//*"->"/"
|
|
103
103
|
//"\/.*"->".*"
|
|
104
104
|
//JS引擎中"\"转义
|
|
@@ -106,18 +106,21 @@ hexo.extend.filter.register('after_render:html', function (html) {
|
|
|
106
106
|
const dataPattern = new RegExp(Patternstr);
|
|
107
107
|
const path = window.location.pathname;
|
|
108
108
|
console.log(dataPattern.toString(),path,dataPattern.test(path));//控制台在渲染时省略了反斜杠的可视表示。
|
|
109
|
-
if (!dataPattern.test(path)) {
|
|
109
|
+
if (!dataPattern.test(path)&&(path==='/'||path==='index.html')) {
|
|
110
|
+
console.log('no toc')
|
|
110
111
|
let toc = document.getElementById('fixed-toc-container');
|
|
111
112
|
if (toc) toc.style.display = 'none';
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
115
|
var content = document.querySelector('body');
|
|
116
|
+
console.log('content',content)
|
|
115
117
|
//var tocList = document.getElementById('fixed-toc-list');
|
|
116
118
|
if (!content || !tocList) {
|
|
117
119
|
document.getElementById('fixed-toc-container').style.display = 'none';
|
|
118
120
|
return;
|
|
119
121
|
}
|
|
120
122
|
var headings = content.querySelectorAll('h1, h2, h3, h4');
|
|
123
|
+
console.log('headings',headings)
|
|
121
124
|
if(headings){
|
|
122
125
|
const h1Element=headings[0];
|
|
123
126
|
const rect = h1Element.getBoundingClientRect();
|
|
@@ -172,11 +175,11 @@ hexo.extend.injector.register('body_end', () => {//生成静态页面时
|
|
|
172
175
|
const article = document.querySelector("article");
|
|
173
176
|
const toggleBtn = document.getElementById('toggle_btn');
|
|
174
177
|
if (!toc || !article) return;
|
|
175
|
-
if (window.innerWidth < 1024) {
|
|
178
|
+
if (window.innerWidth < 1024 && article.firstElementChild !== toc) {
|
|
176
179
|
console.log('small screen!!')
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
|
|
181
|
+
article.insertBefore(toc, article.firstChild);//移动节点,而非复制
|
|
182
|
+
|
|
180
183
|
toggleBtn.style.display='none';
|
|
181
184
|
// 替换样式:取消 fixed,设置适合正文的样式
|
|
182
185
|
toc.style.position = 'relative';
|
|
@@ -195,7 +198,6 @@ hexo.extend.injector.register('body_end', () => {//生成静态页面时
|
|
|
195
198
|
toc.style.boxShadow = 'none';
|
|
196
199
|
toc.style.margin = '1rem';
|
|
197
200
|
toc.style.paddingTop= '2rem';
|
|
198
|
-
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
window.addEventListener("DOMContentLoaded", moveElementIfSmallScreen);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hexo-auto-toc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Automatically generates a responsive table of contents that fixes to the side of the article page or above the articles, depending on the user's device.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toc",
|