Skip to content

Commit

Permalink
Merge branch 'main' into feat/search-history
Browse files Browse the repository at this point in the history
  • Loading branch information
heweikang committed Aug 17, 2024
2 parents b84bb72 + 495b321 commit 82298a7
Show file tree
Hide file tree
Showing 22 changed files with 5,790 additions and 1,689 deletions.
6 changes: 6 additions & 0 deletions app/components/chat.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@
flex-wrap: nowrap;
}
}

.chat-model-name {
font-size: 12px;
color: var(--black);
margin-left: 6px;
}
}

.chat-message-container {
Expand Down
5 changes: 5 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ function _Chat() {
</>
)}
</div>
{!isUser && (
<div className={styles["chat-model-name"]}>
{message.model}
</div>
)}

{showActions && (
<div className={styles["chat-message-actions"]}>
Expand Down
41 changes: 41 additions & 0 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,46 @@ export function PreCode(props: { children: any }) {
);
}

function CustomCode(props: { children: any }) {
const ref = useRef<HTMLPreElement>(null);
const [collapsed, setCollapsed] = useState(true);
const [showToggle, setShowToggle] = useState(false);

useEffect(() => {
if (ref.current) {
const codeHeight = ref.current.scrollHeight;
setShowToggle(codeHeight > 400);
ref.current.scrollTop = ref.current.scrollHeight;
}
}, [props.children]);

const toggleCollapsed = () => {
setCollapsed((collapsed) => !collapsed);
};
return (
<>
<code
ref={ref}
style={{
maxHeight: collapsed ? "400px" : "none",
overflowY: "hidden",
}}
>
{props.children}
{showToggle && collapsed && (
<div
className={`show-hide-button ${
collapsed ? "collapsed" : "expanded"
}`}
>
<button onClick={toggleCollapsed}>查看全部</button>
</div>
)}
</code>
</>
);
}

function escapeDollarNumber(text: string) {
let escapedText = "";

Expand Down Expand Up @@ -211,6 +251,7 @@ function _MarkDownContent(props: { content: string }) {
]}
components={{
pre: PreCode,
code: CustomCode,
p: (pProps) => <p {...pProps} dir="auto" />,
a: (aProps) => {
const href = aProps.href || "";
Expand Down
3 changes: 2 additions & 1 deletion app/config/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import md5 from "spark-md5";
import { DEFAULT_MODELS } from "../constant";
import { DEFAULT_MODELS, DEFAULT_GA_ID } from "../constant";

declare global {
namespace NodeJS {
Expand Down Expand Up @@ -211,6 +211,7 @@ export const getServerSideConfig = () => {
cloudflareKVTTL: process.env.CLOUDFLARE_KV_TTL,

gtmId: process.env.GTM_ID,
gaId: process.env.GA_ID || DEFAULT_GA_ID,

needCode: ACCESS_CODES.size > 0,
code: process.env.CODE,
Expand Down
1 change: 1 addition & 0 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,5 @@ export const internalAllowedWebDavEndpoints = [
"https://app.koofr.net/dav/Koofr",
];

export const DEFAULT_GA_ID = "G-89WN60ZK2E";
export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }];
7 changes: 6 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getClientConfig } from "./config/client";
import type { Metadata, Viewport } from "next";
import { SpeedInsights } from "@vercel/speed-insights/next";
import { getServerSideConfig } from "./config/server";
import { GoogleTagManager } from "@next/third-parties/google";
import { GoogleTagManager, GoogleAnalytics } from "@next/third-parties/google";
const serverConfig = getServerSideConfig();

export const metadata: Metadata = {
Expand Down Expand Up @@ -56,6 +56,11 @@ export default function RootLayout({
<GoogleTagManager gtmId={serverConfig.gtmId} />
</>
)}
{serverConfig?.gaId && (
<>
<GoogleAnalytics gaId={serverConfig.gaId} />
</>
)}
</body>
</html>
);
Expand Down
Loading

0 comments on commit 82298a7

Please sign in to comment.