Skip to content

Commit 57e0b6f

Browse files
committed
feat: enhance excerpt
1 parent d832948 commit 57e0b6f

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

Diff for: theme/components/PostInfo.vue

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
<span>{{ post.frontmatter.summary || '' }}</span>
1515
</template>
1616
<!-- $page.excerpt -->
17+
<template v-else-if="post.excerptTempFilePath">
18+
<div :class="$style.abstract" class="theme-default-content abstract">
19+
<span v-html="require(excerptTempFilePath)"></span>
20+
</div>
21+
</template>
1722
<template v-else-if="post.excerpt">
18-
<div
19-
:class="$style.abstract"
20-
class="theme-default-content abstract"
21-
v-html="post.excerpt"
22-
></div>
23+
<div :class="$style.abstract" class="theme-default-content abstract">
24+
<span v-html="post.excerpt"></span>
25+
</div>
2326
</template>
2427
<!-- <Content :post-key="post.key" slot-key="summary" /> -->
2528
</article>

Diff for: theme/components/TitleLine.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
.root {
1515
position: relative;
1616
overflow: hidden;
17-
height: 1px;
17+
height: 2px;
1818
width: 24rem;
1919
box-sizing: border-box;
2020
margin: auto;
@@ -30,7 +30,7 @@ export default {
3030
border: 0;
3131
background: linear-gradient(90deg, rgba(24, 144, 255, 0) 0, $accentColor);
3232
transform: translateX(-100%);
33-
animation: pageLine 3s ease-in-out 1.5s infinite;
33+
animation: pageLine 3s ease-in-out 0.5s infinite;
3434
}
3535
3636
@keyframes pageLine {

Diff for: theme/plugins/blog/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = (optins = {}, ctx) => {
4141
],
4242

4343
// Blog https://github.com/meteorlxy/vuepress-theme-meteorlxy/blob/master/lib/plugins/blog/index.js
44-
extendPageData($page) {
44+
async extendPageData($page) {
4545
const frontmatter = $page.frontmatter;
4646
if (frontmatter && frontmatter.private === true) {
4747
// TODO 私有内容
@@ -50,9 +50,11 @@ module.exports = (optins = {}, ctx) => {
5050
// console.warn($page);
5151
// }
5252
}
53-
// if ($page.excerpt) { // 处理图片
54-
// console.warn($page.excerpt);
55-
// }
53+
if ($page.excerpt) { // excerpt 处理(图片等)
54+
const { parseFrontmatter } = require('@vuepress/shared-utils');
55+
const { excerpt } = parseFrontmatter($page._content);
56+
$page.excerptTempFilePath = await $page._context.writeTemp(`temp-excerpts/${$page.key}.md`, excerpt);
57+
}
5658
return extendPageData($page, ctx);
5759
},
5860
};

Diff for: theme/plugins/markdown/mdReplaceLink.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// https://github.com/martinheidegger/markdown-it-replace-link/blob/master/index.js
2+
3+
// 暂时用不到
4+
module.exports = function(options) {
5+
const replace = options.replaceLink;
6+
return md => {
7+
md.core.ruler.after(
8+
'inline',
9+
'replace-link',
10+
function(state) {
11+
if (typeof replace === 'function') {
12+
state.tokens.forEach(function(blockToken) {
13+
if (blockToken.type === 'inline' && blockToken.children) {
14+
blockToken.children.forEach(function(token) {
15+
const type = token.type;
16+
if (type === 'link_open') {
17+
replaceAttr(token, 'href', replace, state.env);
18+
} else if (type === 'image') {
19+
replaceAttr(token, 'src', replace, state.env);
20+
}
21+
});
22+
}
23+
});
24+
}
25+
return false;
26+
}
27+
);
28+
};
29+
};
30+
31+
function replaceAttr(token, attrName, replace, env) {
32+
token.attrs.forEach(function(attr) {
33+
if (attr[0] === attrName) {
34+
attr[1] = replace(attr[1], env, token);
35+
}
36+
});
37+
}

0 commit comments

Comments
 (0)