-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ai generate content & footer link (#35)
![image](https://github.com/user-attachments/assets/0c6d739b-a77c-4f87-a734-c0d6e4e8784a) --------- Co-authored-by: linxin <[email protected]>
- Loading branch information
Showing
7 changed files
with
396 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; | ||
import { get } from "@site/src/api"; | ||
import React, { useEffect, useState } from "react"; | ||
import { useDefaultLocale } from "@site/src/utils"; | ||
|
||
interface AIContentProps { | ||
content?: string; | ||
id: number; | ||
} | ||
const LocalesMap = { | ||
aiGen: { | ||
"zh-CN": "以下内容是 AI 的进一步解读", | ||
"zh-HK": "以下內容是 AI 的進一步解讀", | ||
en: "The following content is a further interpretation by AI.", | ||
}, | ||
disclaimer: { | ||
"zh-CN": "免责声明", | ||
"zh-HK": "免責聲明", | ||
en: "Disclaimer", | ||
}, | ||
}; | ||
export const AIContent: React.FC<AIContentProps> = ({ content, id }) => { | ||
const [AIContent, setAIContent] = useState(content); | ||
const locale = useDefaultLocale() || "en"; | ||
|
||
const { | ||
siteConfig: { | ||
customFields: { apiProxyUrl }, | ||
}, | ||
} = useDocusaurusContext(); | ||
|
||
useEffect(() => { | ||
if (!apiProxyUrl || !id || AIContent) return; | ||
|
||
get(`${apiProxyUrl}/v1/social/wiki/content`, { id }).then((resp) => { | ||
const { data } = resp; | ||
if (data?.content) { | ||
setAIContent(data.content); | ||
} | ||
}); | ||
}, [apiProxyUrl, id]); | ||
|
||
if (!AIContent) return <></>; | ||
return ( | ||
<div className="ai-content pt-8 rounded-lg"> | ||
<div className="flex items-center space-x-4 pb-3 mb-3 border-solid border-b border-t-0 border-r-0 border-l-0 border-[var(--ifm-color-gray-300)]"> | ||
<img | ||
src="https://assets.lbctrl.com/uploads/831466be-e4f8-46a7-aa0b-efcda7a424ff/portai.png" | ||
alt="port-ai" | ||
className="w-7 h-7 rounded-full" | ||
/> | ||
<span className="text-sm">{LocalesMap.aiGen[locale]}</span> | ||
</div> | ||
<div dangerouslySetInnerHTML={{ __html: AIContent }}></div> | ||
<a | ||
href="https://support.longbridgewhale.com/topics/misc/portaidisclaimer" | ||
className="text-sm text-[#37a0ff]" | ||
target="_blank" | ||
> | ||
{LocalesMap.disclaimer[locale]} | ||
</a> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.