Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大白技术控
yanglr2010
提交
31d6356e
Y
yanglr2010
项目概览
大白技术控
/
yanglr2010
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yanglr2010
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
31d6356e
编写于
1月 12, 2020
作者:
EvanOne(文一)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(#25): Remove cheerio
上级
d412a73e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
151 addition
and
108 deletion
+151
-108
scripts/filters/external-link.js
scripts/filters/external-link.js
+47
-36
scripts/filters/lazyload.js
scripts/filters/lazyload.js
+29
-30
scripts/filters/post-heading.js
scripts/filters/post-heading.js
+22
-12
scripts/filters/resize-img.js
scripts/filters/resize-img.js
+39
-19
scripts/filters/shake-file.js
scripts/filters/shake-file.js
+4
-2
scripts/filters/wrap-table.js
scripts/filters/wrap-table.js
+9
-8
source/css/_common/components/widgets/lazyload.styl
source/css/_common/components/widgets/lazyload.styl
+1
-1
未找到文件。
scripts/filters/external-link.js
浏览文件 @
31d6356e
...
...
@@ -2,49 +2,60 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
var
theme
=
hexo
.
theme
.
config
;
if
(
!
(
theme
.
external_link
&&
theme
.
external_link
.
icon
&&
theme
.
external_link
.
icon
.
enable
))
return
;
if
(
!
theme
.
external_link
||
!
theme
.
external_link
.
icon
||
!
theme
.
external_link
.
icon
.
enable
)
{
return
;
}
var
url
=
require
(
'
url
'
);
var
cheerio
;
var
config
=
this
.
config
;
if
(
!
cheerio
)
cheerio
=
require
(
'
cheerio
'
);
var
$
=
cheerio
.
load
(
data
.
content
,
{
decodeEntities
:
false
});
var
siteHost
=
url
.
parse
(
config
.
url
).
hostname
||
config
.
url
;
$
(
'
a
'
).
each
(
function
()
{
var
href
=
$
(
this
).
attr
(
'
href
'
);
if
(
!
href
)
return
;
var
className
=
$
(
this
).
attr
(
'
class
'
);
var
classNameWhitelist
=
[
'
friends-plugin__item
'
,
];
if
(
className
&&
classNameWhitelist
.
includes
(
className
))
return
;
var
data
=
url
.
parse
(
href
);
if
(
!
data
.
protocol
)
return
;
if
(
data
.
hostname
===
siteHost
)
return
;
var
fa_prefix
=
theme
.
fa_prefix
||
'
fa
'
;
$
(
this
).
replaceWith
(
function
()
{
return
$
(
data
.
content
=
data
.
content
.
replace
(
/
(
<a
([^
>
]
*
)
href="
([^
"
]
*
)
"
([^
>
]
*
)
>
([^
<
]
*
)
<
\/
a>
)
/gim
,
function
(
match
,
all
,
attrBegin
,
href
,
attrEnd
,
html
)
{
// Exit if the href attribute doesn't exists.
if
(
!
href
)
{
return
match
;
}
// Exit if the url has same host with `config.url`, which means isn't an external link.
var
link
=
url
.
parse
(
href
);
if
(
!
link
.
protocol
||
link
.
hostname
===
siteHost
)
{
return
match
;
};
var
attrOther
=
attrBegin
+
attrEnd
;
var
className
=
''
;
attrOther
.
split
(
/
\s
/gim
).
forEach
(
attr
=>
{
var
nAttr
=
attr
.
replace
(
/
[
"'
]
*/gim
,
''
);
var
aKey
=
(
nAttr
.
split
(
'
=
'
)[
0
]
||
''
).
trim
();
var
aValue
=
(
nAttr
.
split
(
'
=
'
)[
1
]
||
''
).
trim
();
if
(
aKey
===
'
class
'
)
{
className
=
aValue
;
}
});
// Exit if the class name is in whitelist.
var
whiteList
=
[
'
friends-plugin__item
'
];
if
(
className
&&
whiteList
.
includes
(
className
))
{
return
match
;
}
var
fa_prefix
=
theme
.
fa_prefix
||
'
fa
'
;
return
(
'
<span class="external-link">
'
+
'
<a href="
'
+
href
+
'
" target="_blank" rel="noopener">
'
+
$
(
this
).
html
()
+
'
</a>
'
+
'
<i class="
'
+
fa_prefix
+
'
fa-external-link"></i>
'
+
`<a
${
attrBegin
}
href="
${
href
}
"
${
attrEnd
}
>
${
html
}
</a>`
+
`<i class="
${
fa_prefix
}
fa-external-link"></i>`
+
'
</span>
'
);
});
});
data
.
content
=
$
.
html
();
}
);
},
0
);
scripts/filters/lazyload.js
浏览文件 @
31d6356e
...
...
@@ -2,36 +2,35 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
var
theme
=
hexo
.
theme
.
config
;
if
(
!
(
theme
.
lazyload
&&
theme
.
lazyload
.
enable
))
return
;
var
cheerio
;
if
(
!
cheerio
)
cheerio
=
require
(
'
cheerio
'
);
var
$
=
cheerio
.
load
(
data
.
content
,
{
decodeEntities
:
false
});
$
(
'
img
'
).
each
(
function
(
)
{
var
$img
=
$
(
this
)
;
// 最小 1 * 1 像素的透明 gif 图片
var
loadingGIF
=
`/
${(
theme
.
images
&&
theme
.
images
.
replace
(
/^
\/
+|
\/
+$/gm
,
''
))
||
'
images
'
}
/loading.svg`
;
var
loadingBlock
=
'
data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=
'
;
var
placeholder
;
if
(
theme
.
lazyload
.
placeholder
===
'
gif
'
)
{
placeholder
=
loadingGIF
;
}
else
if
(
theme
.
lazyload
.
placeholder
===
'
block
'
)
{
placeholder
=
loadingBlock
;
}
$img
.
addClass
(
'
lazyload
'
)
;
$img
.
attr
(
'
data-src
'
,
$img
.
attr
(
'
src
'
));
$img
.
attr
(
'
src
'
,
placeholder
);
if
(
theme
.
lazyload
.
placeholder
)
{
$img
.
addClass
(
theme
.
lazyload
.
placeholder
)
;
if
(
!
theme
.
lazyload
||
!
theme
.
lazyload
.
enable
)
{
return
;
}
data
.
content
=
data
.
content
.
replace
(
/<img
([^
>
]
*
)
src="
([^
"
]
*
)
"
([^
>
]
*
)
>/gim
,
function
(
match
,
attrBegin
,
src
,
attrEnd
)
{
// Exit if the src doesn't exists.
if
(
!
src
)
{
return
match
;
}
// Smallest 1 * 1 pixel transparent gif
var
loadingBlock
=
'
data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=
'
;
var
loadingGIF
=
`/
${(
theme
.
images
&&
theme
.
images
.
replace
(
/^
\/
+|
\/
+$/gm
,
''
))
||
'
images
'
}
/loading.svg`
;
var
phClassName
=
theme
.
lazyload
.
placeholder
;
var
placeholder
=
''
;
if
(
phClassName
===
'
gif
'
)
{
placeholder
=
loadingGIF
;
}
else
if
(
phClassName
===
'
block
'
)
{
placeholder
=
loadingBlock
;
}
return
`
<img
${
attrBegin
}
class="lazyload lazyload-
${
phClassName
}
"
src="
${
placeholder
}
" data-src="
${
src
}
"
${
attrEnd
}
>`
;
}
});
data
.
content
=
$
.
html
();
);
},
1
);
scripts/filters/post-heading.js
浏览文件 @
31d6356e
...
...
@@ -3,18 +3,28 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
var
cheerio
;
var
tagName
=
`h[1-6]`
;
var
attrId
=
`id="([^"]*)"`
;
var
tagNotEnd
=
`([^>]*)`
;
var
regAttrId
=
tagNotEnd
+
attrId
+
tagNotEnd
;
var
regHTagInnermost
=
new
RegExp
(
`<
${
tagName
}${
regAttrId
}
>((?:(?!<\\/?
${
tagName
}${
regAttrId
}
>)(?:\\s|\\S))*?)<\/
${
tagName
}
>`
,
'
gim
'
);
if
(
!
cheerio
)
cheerio
=
require
(
'
cheerio
'
);
data
.
content
=
data
.
content
.
replace
(
regHTagInnermost
,
function
(
match
,
attrBegin
,
id
,
attrEnd
,
html
)
{
if
(
!
id
)
{
return
match
;
}
var
$
=
cheerio
.
load
(
data
.
content
,
{
decodeEntities
:
false
});
$
(
'
h1,h2,h3,h4,h5,h6
'
).
each
(
function
()
{
var
$heading
=
$
(
this
);
var
headingTxt
=
$heading
.
text
().
trim
();
$heading
.
html
(
'
<span class="heading-link">
'
+
headingTxt
+
'
</span>
'
);
});
data
.
content
=
$
.
html
();
var
newHtml
=
(
html
.
replace
(
/<
[^
>
]
+>/gim
,
''
)
||
''
).
trim
();
return
`
<h2
${
attrBegin
}
id="
${
id
}
"
${
attrEnd
}
>
<span class="heading-link">
${
newHtml
}
</span>
</h2>
`
;
}
);
},
0
);
scripts/filters/resize-img.js
浏览文件 @
31d6356e
...
...
@@ -3,24 +3,44 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
var
cheerio
;
if
(
!
cheerio
)
cheerio
=
require
(
'
cheerio
'
);
var
$
=
cheerio
.
load
(
data
.
content
,
{
decodeEntities
:
false
});
$
(
'
img
'
).
each
(
function
()
{
var
$img
=
$
(
this
);
if
(
!
$img
.
attr
(
'
src
'
))
return
;
if
(
$img
.
attr
(
'
src
'
).
includes
(
'
?size=
'
))
{
var
size
=
$img
.
attr
(
'
src
'
).
split
(
'
?size=
'
)[
1
]
&&
$img
.
attr
(
'
src
'
).
split
(
'
?size=
'
)[
1
].
toLowerCase
();
var
w
=
size
.
split
(
'
x
'
)[
0
]
+
'
px
'
;
var
h
=
size
.
split
(
'
x
'
)[
1
]
+
'
px
'
;
$img
.
css
({
width
:
w
,
height
:
h
});
data
.
content
=
data
.
content
.
replace
(
/<img
([^
>
]
*
)
src="
([^
"
]
*
)
"
([^
>
]
*
)
>/gim
,
function
(
match
,
attrBegin
,
src
,
attrEnd
)
{
// Exit if the src doesn't exists.
if
(
!
src
)
{
return
match
;
}
// A flag that sets the size of image.
var
RESIZE_IMG_SIGN
=
'
?size=
'
;
var
srcLower
=
src
.
toLowerCase
();
// Exit if the src doesn't include the sign of resize.
if
(
!
srcLower
.
includes
(
RESIZE_IMG_SIGN
))
{
return
match
;
}
var
size
=
srcLower
.
split
(
RESIZE_IMG_SIGN
)[
1
];
// Exit if hasn't the value of width or height.
if
(
!
size
)
{
return
match
;
}
// The sign between width and height.
var
MULTIPLY_SIGN
=
'
x
'
;
var
w
=
size
.
split
(
MULTIPLY_SIGN
)[
0
];
var
h
=
size
.
split
(
MULTIPLY_SIGN
)[
1
];
var
style
=
''
;
if
(
w
)
{
style
+=
`width:
${
w
}
px;`
;
}
if
(
h
)
{
style
+=
`height:
${
h
}
px;`
;
}
var
attr1
=
attrBegin
.
trim
();
var
attr2
=
attrEnd
.
trim
();
return
`<img
${
attr1
}
src="
${
src
}
" style="
${
style
}
"
${
attr2
}
>`
;
}
});
data
.
content
=
$
.
html
();
);
},
0
);
scripts/filters/shake-file.js
浏览文件 @
31d6356e
...
...
@@ -2,10 +2,12 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_generate
'
,
()
=>
{
hexo
.
extend
.
filter
.
register
(
'
after_generate
'
,
function
()
{
var
theme
=
hexo
.
theme
.
config
;
if
(
!
theme
.
shake_file
)
return
;
if
(
!
theme
.
shake_file
)
{
return
;
}
if
(
!
(
theme
.
sidebar
&&
theme
.
sidebar
.
enable
))
{
hexo
.
route
.
remove
(
'
js/sidebar.js
'
);
...
...
scripts/filters/wrap-table.js
浏览文件 @
31d6356e
...
...
@@ -3,13 +3,14 @@
'
use strict
'
;
hexo
.
extend
.
filter
.
register
(
'
after_post_render
'
,
function
(
data
)
{
var
cheerio
;
data
.
content
=
data
.
content
.
replace
(
/
(
<table
[^
>
]
*>
(?!
<
\/
table
)
.*<
\/
table>
)
/gim
,
function
(
match
,
table
)
{
if
(
!
table
)
{
return
match
;
}
if
(
!
cheerio
)
cheerio
=
require
(
'
cheerio
'
);
var
$
=
cheerio
.
load
(
data
.
content
,
{
decodeEntities
:
false
});
var
$wrapper
=
$
(
'
<div class="table-container"></div>
'
);
$
(
'
table
'
).
wrap
(
$wrapper
);
data
.
content
=
$
.
html
();
return
`<div class="table-container">
${
table
}
</div>`
;
}
);
},
0
);
source/css/_common/components/widgets/lazyload.styl
浏览文件 @
31d6356e
.lazyload {
&
.
block {
&
-
block {
box-sizing: content-box;
min-width: 30px;
min-height: 30px;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录