Skip to content

Commit

Permalink
Merge branch 'dev' and release 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
chihuo2104 committed Feb 17, 2024
2 parents bb7b0d6 + 3fc0ce5 commit d87868f
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 102 deletions.
2 changes: 1 addition & 1 deletion components/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ onMounted(async () => {
})
</script>
<template>
<div class="my-2 mx-2 p-2 shadow-md hover:shadow-xl transition-all grid lg:grid-cols-2 backdrop-blur-sm overflow-y-auto" style="background-color: rgba(255,255,255,0.3)" :class="{ imageshow: showImg }">
<div class="my-2 mx-2 shadow-md hover:shadow-xl transition-all grid lg:grid-cols-2 backdrop-blur-sm overflow-y-auto" style="background-color: rgba(255,255,255,0.3)" :class="{ imageshow: showImg }">
<div class="lazyloadimg flex content-center justify-center transition-all" id="img">
<img :data-src="props.img" src="/loading.svg" class="lazy" alt="" v-if="showImg"/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/CommentSys/Waline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Waline } from '@waline/client/component';
import '@waline/client/dist/waline.css';
</script>
<template>
<Waline :serverURL="props.backend" :path="path" />
<Waline :serverURL="props.backend" :path="props.path" />
</template>
<style>
.wl-panel{
Expand All @@ -17,4 +17,4 @@ import '@waline/client/dist/waline.css';
.wl-input,.wl-editor:focus {
background: transparent;
}
</style>
</style>
4 changes: 2 additions & 2 deletions components/ImageCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ onMounted(async () => {
})
</script>
<template>
<div class="my-2 mx-2 p-2 shadow-md hover:shadow-xl transition-all backdrop-blur-sm overflow-y-auto" style="background-color: rgba(255,255,255,0.3)">
<div class="my-2 mx-2 shadow-md hover:shadow-xl transition-all backdrop-blur-sm overflow-y-auto" style="background-color: rgba(255,255,255,0.3)">
<div class="lazyloadimg flex content-center justify-center transition-all" id="img">
<img :data-src="props.img" src="/loading.svg" class="lazy min-h-fit" alt="" v-if="showImg"/>
</div>
<div>
<div class="p-2">
<!-- Title & Content -->
<h1 class="font-bold text-xl">{{ props.title }}</h1>
<div>
Expand Down
3 changes: 2 additions & 1 deletion composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const useConfig = () => {
return {
model: 'mocks',
url: '',
ignorebeta: false
ignorebeta: false,
aikey: ''
}
})
return modifyData
Expand Down
28 changes: 21 additions & 7 deletions mocks/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export default {
ghcacheurl: '//ghavatar.chicdn.cn/u/', // The github avatar cdn url (Default https://avatars.githubusercontent.com/ )
d: 'monsterid' // The d you want to show like GRAVATAR_URL/[ID]?d=[this is D] (valine type is supported)
},
ghauth: {
enabled: false, //temporaity false.
client_id: '204a53c84ec3ff5e5a82'
// Due to the sucerty problem, the client secret is not supported on chiblog v1.1.3 and above.
// proxy_url: 'https://ghproxy.moekonnyaku.workers.dev/' // You can deploy this in the cloudflare workers. Code: https://p.atri.tk/j3i
// The ghauth authenation url is no longer supported, please use the server get way instead.
},
// ghauth: {
// enabled: false, //temporaity false.
// client_id: '204a53c84ec3ff5e5a82'
// // Due to the sucerty problem, the client secret is not supported on chiblog v1.1.3 and above.
// // proxy_url: 'https://ghproxy.moekonnyaku.workers.dev/' // You can deploy this in the cloudflare workers. Code: https://p.atri.tk/j3i
// // The ghauth authenation url is no longer supported, please use the server get way instead.
// },
backend: {
enabled: true, // enable your comment backend system
type: 'waline', // The next will be like disqus, valine and so on.(Serverless options) You can deploy the code in the cloudflare workers. Code: https://p.atri.tk/Mm4 Guide: https://chiblog.apps.chihuo2104.dev/comment-service/workers (WIP)
Expand All @@ -41,6 +41,20 @@ export default {
// url: 'http://127.0.0.1:8080/'
}
},
seo: { // SEO option.
description: true, //enable description
robots: {
enabled: true, // enable robots.txt option
content: "User-agent: *", // you can generate it in somewhere or just copy it in some domains '\n\n' means enter.
// sitemap option. We will automatically create sitemap in your robots.txt so you do not need to add the same.
sitemap: true,
}
},
ai: { // ai option
type: 'gemini', // Now supports Gemini.
enabled: true, // You should input your API_KEY as an environment varible!
abstract: true // Abstract the articles
},
footer: '', // the footer will show below the copyright statement. support html tag
announcement: '', // the announcement will show in the index page. support html tag
background: {
Expand Down
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default defineNuxtConfig({
runtimeConfig: {
chiblogConfigType: '',
chiblogConfigUrl: '',
chiblogIgnoreBetaTip: false
chiblogIgnoreBetaTip: false,
chiblogAiApiKey: ''
},

vite: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint-plugin-vue": "^9.15.1"
},
"dependencies": {
"@google/generative-ai": "^0.2.1",
"@mdi/js": "^7.1.96",
"@nuxtjs/tailwindcss": "^6.9.4",
"@vitejs/plugin-legacy": "^4.0.3",
Expand Down
47 changes: 8 additions & 39 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import mockcomments from '@/mocks/comments'
// import { useStore } from '@/store'
// import { ref } from 'vue'
import { marked } from 'marked'
import addMediaHeader from '~/scripts/addMediaHeader'
// import { useRouter } from 'vue-router'
// import { processExpression } from '@vue/compiler-core'
// import { useAlldata } from '~~/composables/useData'
Expand Down Expand Up @@ -49,45 +50,13 @@ if ($store.value.model === 'production') {
posts = $store.value.all.posts
settings = $store.value.all.settings
comments = $store.value.all.comments
useHead({
// title: '文章列表 - ' + settings.site.title
title: settings.site.title + ' - ' + settings.site.desc,
meta: [
{
name: 'description',
content: settings.site.desc
},
{
name: 'twitter:image:src',
content: settings.site.articleimage.enabled
? settings.site.articleimage.images[
Math.floor(Math.random() * settings.site.articleimage.images.length)
]
: ''
},
{
name: 'twitter:card',
content: 'summary_large_image'
},
{
name: 'twitter:title',
content: settings.site.title + ' - ' + settings.site.desc
},
{
name: 'twitter:description',
content:
settings.site.title + ' - ' + settings.site.desc + '- Engined by chiblog.'
},
{
name: 'twitter:creator',
content: '@' + settings.site.author.name
},
{
name: 'twitter:site',
content: '@' + settings.site.author.name
}
]
})
addMediaHeader(useHead,
settings.site.title + ' - ' + settings.site.desc,
settings.site.desc,
settings.site.articleimage.enabled ? settings.site.articleimage.images[Math.floor(Math.random() * settings.site.articleimage.images.length)] : '',
settings.site.author.name,
settings.site.title
)
} else {
posts = mockposts
settings = mocksettings
Expand Down
63 changes: 24 additions & 39 deletions pages/posts/[path].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Icon from '@/components/Icon'
import incposts from '@/mocks/posts'
import setting from '@/mocks/settings'
import addMediaHeader from '~/scripts/addMediaHeader'
const $route = useRoute()
const $store = useAlldata()
Expand All @@ -19,6 +20,7 @@ let posts = reactive({})
let settings = reactive({})
const postComments = ref(0)
let china = false
const aigc = ref('正在生成中...')
function renderTime(time) {
const currentTime = new Date()
Expand Down Expand Up @@ -77,45 +79,13 @@ if (post.banner === undefined) {
}
}
useHead({
title: post.title + ' - ' + settings.site.title,
meta: [
{
name: 'description',
content:
post.desc +
' - 本文首发于' +
settings.site.title +
',由' +
post.author +
'撰写,版权所有。'
},
{
name: 'twitter:image:src',
content: post.banner,
},
{
name: 'twitter:card',
content: 'summary_large_image'
},
{
name: 'twitter:title',
content: post.title + ' - ' + settings.site.title
},
{
name: 'twitter:description',
content: post.desc + ',由' + post.author + '撰写 - Engined by chiblog'
},
{
name: 'twitter:site',
content: '@' + settings.site.author.name
},
{
name: 'twitter:creator',
content: '@' + settings.site.author.name
}
]
})
addMediaHeader(useHead,
post.title + ' - ' + settings.site.title,
post.desc + ' - 本文首发于' + settings.site.title + ',由' + post.author + '撰写.',
post.banner,
settings.site.author.name,
settings.site.title
)
const reltime = computed(() => {
return renderTime(post.time)
Expand All @@ -134,6 +104,17 @@ function renderNumber(num) {
}
}
if (settings.site.ai.enabled) {
useFetch("/api/abstract?pid=" + post.id).then((resp) => {
if (resp.data.value.status === 200) {
aigc.value = resp.data.value.result
} else {
aigc.value = '获取失败,请刷新页面后再试'
}
})
}
</script>
<template>
<ImageCard :img="post.banner">
Expand All @@ -148,6 +129,10 @@ function renderNumber(num) {
<div><Icon name="views" /><span id="busuanzi_value_page_pv">加载中</span></div>
</div>
<div>
<div class='text-xl m-4 p-4 border-r-2 border-2 border-gray-400' v-if='settings.site.ai.enabled'>
<div class='font-bold accent-cyan-300'>文章概述 Powered by Google Gemini <small>Beta</small></div>
<div class='text-lg'>{{aigc}}</div>
</div>
<Content :content="post.content" />
<p v-if="post.tags !== undefined" id="tags" style="font-size: 18px">
<Icon name="tag" />
Expand Down
47 changes: 47 additions & 0 deletions scripts/addMediaHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export default function (useHead: Function, title: String, desc: String, img: String, author: String, site: String ) {
useHead({
title: title,
meta: [
{
name: 'description',
content: desc
},
{
name: 'twitter:image:src',
content: img
},
{
name: 'twitter:card',
content: 'summary_large_image'
},
{
name: 'twitter:title',
content: title
},
{
name: 'twitter:description',
content: desc + '- Engined by chiblog.'
},
{
name: 'twitter:creator',
content: '@' + author
},
{
name: 'twitter:site',
content: '@' + author
},
{
name: 'og:site_name',
content: site
},
{
name: 'og:description',
content: desc
},
{
name: 'article:author',
content: author
}
]
})
}
65 changes: 65 additions & 0 deletions server/api/abstract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//@ts-ignore
import {defineEventHandler} from 'h3'
import posts from '@/mocks/posts'
import settings from '@/mocks/settings'
import {GoogleGenerativeAI} from '@google/generative-ai'

export default defineEventHandler(async (event) => {
const query = getQuery(event)
const config = useRuntimeConfig(event)
let res = []
if (config.chiblogConfigType === "production") {
res = (await (await fetch(config.chiblogConfigUrl)).json()).data
} else {
res = {posts: posts, settings: settings}
}
if (query.pid === undefined) {
setResponseStatus(event,400)
return ''
}
if (res.settings.site.ai.enabled === undefined) {
setResponseStatus(event,403)
return ''
}
if (config.chiblogAiApiKey === '') {
setResponseStatus(event,401)
return ''
}

//@ts-ignore
const resp = res.posts.find(element => element.id === parseInt(query.pid))
if (resp === undefined) {
setResponseStatus(event,404)
return ''
}

setResponseHeader(event, "Content-Type", "application/json;charset=utf8")
setResponseHeader(event, "Cache-Control", "public, max-age=86400")

console.log(query.cid)

const genAI = new GoogleGenerativeAI(config.chiblogAiApiKey)
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: "gemini-pro"})
const prompt = "请给这篇文章生成一段简单的概述,只需要生成一段话,不需要输出其他无关的任何内容。\n" + resp.content

console.log(prompt)

const result = await model.generateContent(prompt)
try {
const response = await result.response
const text = response.text();

return JSON.stringify({
status: 200,
result: text,
})
} catch (e) {
console.log(e)
return JSON.stringify({
status: 400,
result: 'failed',
})
}

})

0 comments on commit d87868f

Please sign in to comment.