Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ai-summary): 新增文章ai摘要 #905

Draft
wants to merge 5 commits into
base: 6.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,13 @@ plugins:
wordLimit: 1000 # 摘要字数限制 (⚠️危险:更改此变量损失已消耗过的key,因为你提交的内容发生了变化。)
typewriter: true # 打字机效果

# 文章AI摘要
# 免费,但是有bug
aisummary:
enable: true
apiurl: https://ai.ning0818.top # 使用vercel部署"https://github.com/ning0818/ai-postsummary"
key: # 留空

############################### Plugins ############################### > end

############################### Rightmenu ############################### > start
Expand Down
3 changes: 3 additions & 0 deletions layout/_partial/article.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<%- partial('meta', {post: post, position: 'top'}) %>
<div id="layoutHelper-page-plugins"></div>
<div id="post-body" itemprop="articleBody">
<% if (theme.plugins.aisummary.enable) { %>
<%- partial('../_plugins/aisummary/script') %>
<% } %>
<%- post.content %>
</div>
<% if (page.link) { %>
Expand Down
32 changes: 32 additions & 0 deletions layout/_plugins/aisummary/script.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<link rel="stylesheet" href="https://jsd.onmicrosoft.cn/gh/ning0818/CDN-Files/ai.css">
<link rel="stylesheet" href="https://jsd.onmicrosoft.cn/gh/ning0818/CDN-Files/aisummary.css">
<script src="https://jsd.onmicrosoft.cn/gh/ning0818/CDN-Files/app.js"></script>
<div class="ai-summary">
<div class=title>
<svg xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink width=20px height=20px viewBox="0 0 48 48">
<g stroke=none stroke-width=1 fill=none fill-rule=evenodd>
<path d="M34.717885,5.03561087 C36.12744,5.27055371 37.079755,6.60373651 36.84481,8.0132786 L35.7944,14.3153359 L38.375,14.3153359 C43.138415,14.3153359 47,18.1768855 47,22.9402569 L47,34.4401516 C47,39.203523 43.138415,43.0650727 38.375,43.0650727 L9.625,43.0650727 C4.861585,43.0650727 1,39.203523 1,34.4401516 L1,22.9402569 C1,18.1768855 4.861585,14.3153359 9.625,14.3153359 L12.2056,14.3153359 L11.15519,8.0132786 C10.920245,6.60373651 11.87256,5.27055371 13.282115,5.03561087 C14.69167,4.80066802 16.024865,5.7529743 16.25981,7.16251639 L17.40981,14.0624532 C17.423955,14.1470924 17.43373,14.2315017 17.43948,14.3153359 L30.56052,14.3153359 C30.56627,14.2313867 30.576045,14.1470924 30.59019,14.0624532 L31.74019,7.16251639 C31.975135,5.7529743 33.30833,4.80066802 34.717885,5.03561087 Z M38.375,19.4902885 L9.625,19.4902885 C7.719565,19.4902885 6.175,21.0348394 6.175,22.9402569 L6.175,34.4401516 C6.175,36.3455692 7.719565,37.89012 9.625,37.89012 L38.375,37.89012 C40.280435,37.89012 41.825,36.3455692 41.825,34.4401516 L41.825,22.9402569 C41.825,21.0348394 40.280435,19.4902885 38.375,19.4902885 Z M14.8575,23.802749 C16.28649,23.802749 17.445,24.9612484 17.445,26.3902253 L17.445,28.6902043 C17.445,30.1191812 16.28649,31.2776806 14.8575,31.2776806 C13.42851,31.2776806 12.27,30.1191812 12.27,28.6902043 L12.27,26.3902253 C12.27,24.9612484 13.42851,23.802749 14.8575,23.802749 Z M33.1425,23.802749 C34.57149,23.802749 35.73,24.9612484 35.73,26.3902253 L35.73,28.6902043 C35.73,30.1191812 34.57149,31.2776806 33.1425,31.2776806 C31.71351,31.2776806 30.555,30.1191812 30.555,28.6902043 L30.555,26.3902253 C30.555,24.9612484 31.71351,23.802749 33.1425,23.802749 Z" fill=#425aef fill-rule=nonzero></path>
</g>
</svg>
<div class=title>智能摘要</div>
</div>
<div class=content id=ai-summary>获取中……</div>
</div>
<script>
function ai_summary() {
Ning.console.debug(`AI摘要插件
API URL: <%= theme.plugins.aisummary.apiurl %>;
Key: <%= theme.plugins.aisummary.key %>
发送的内容: ` + (document.title + " " + document.getElementById("post").innerText.replaceAll("\n", " ")).substring(0, 201)),
fetch("<%= theme.plugins.aisummary.apiurl %>/?key=<%= theme.plugins.aisummary.key %>&content=" + (document.title + " " + document.getElementById("post").innerText.replaceAll("\n", " ")).substring(0, 201)).then(function(t) {
t.json().then(function(t) {
document.getElementById("ai-summary").innerHTML = t.summary
}).catch(function(t) {
document.getElementById("ai-summary").innerHTML = "代码出现故障:" + t
})
}).catch(function(t) {
document.getElementById("ai-summary").innerHTML = "代码出现故障:" + t
})
}
Ning.onload.add(ai_summary)
</script>