mirror of
https://github.com/langgenius/dify.git
synced 2026-07-26 14:18:35 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: GareArc <garethcxy@dify.ai>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
'use client'
|
|
import { useSuspenseQuery } from '@tanstack/react-query'
|
|
import { useFavicon, useTitle } from 'ahooks'
|
|
import { useEffect } from 'react'
|
|
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
|
|
import { basePath } from '@/utils/var'
|
|
|
|
export default function useDocumentTitle(title: string) {
|
|
const { data } = useSuspenseQuery(systemFeaturesQueryOptions())
|
|
const branding = data.branding
|
|
const prefix = title ? `${title} - ` : ''
|
|
const titleStr = branding.enabled ? `${prefix}${branding.application_title}` : `${prefix}Dify`
|
|
const favicon = branding.enabled ? branding.favicon : `${basePath}/favicon.ico`
|
|
useTitle(titleStr)
|
|
useEffect(() => {
|
|
let apple: HTMLLinkElement | null = null
|
|
if (branding.favicon) {
|
|
document
|
|
.querySelectorAll(
|
|
"link[rel='icon'], link[rel='shortcut icon'], link[rel='apple-touch-icon'], link[rel='mask-icon']",
|
|
)
|
|
.forEach((n) => n.parentNode?.removeChild(n))
|
|
|
|
apple = document.createElement('link')
|
|
apple.rel = 'apple-touch-icon'
|
|
apple.href = branding.favicon
|
|
document.head.appendChild(apple)
|
|
}
|
|
|
|
return () => {
|
|
apple?.remove()
|
|
}
|
|
}, [branding.favicon])
|
|
useFavicon(favicon)
|
|
}
|