fix: always show custom landing page, remove backend home_page_content override
The backend home_page_content setting was overriding the custom OasisRelay landing page with old content. Since we have a fully custom landing page now, remove the API check entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,11 +17,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect, useState, useRef } from 'react';
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { API } from '../../helpers';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { useActualTheme } from '../../context/Theme';
|
||||
import { marked } from 'marked';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
import NoticeModal from '../../components/layout/NoticeModal';
|
||||
@@ -79,53 +77,10 @@ const FaqItem = ({ question, children, defaultOpen }) => {
|
||||
首页主组件
|
||||
────────────────────────────────────────────── */
|
||||
const Home = () => {
|
||||
const { i18n } = useTranslation();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const actualTheme = useActualTheme();
|
||||
const cachedContent = localStorage.getItem('home_page_content') || '';
|
||||
const [homePageContentLoaded, setHomePageContentLoaded] = useState(!!cachedContent);
|
||||
const [homePageContent, setHomePageContent] = useState(cachedContent);
|
||||
const [noticeVisible, setNoticeVisible] = useState(false);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
/* 服务端配置的自定义首页内容(Markdown 或外链 URL) */
|
||||
const displayHomePageContent = async () => {
|
||||
const cached = localStorage.getItem('home_page_content') || '';
|
||||
setHomePageContent(cached);
|
||||
try {
|
||||
const res = await API.get('/api/home_page_content');
|
||||
const { success, data } = res.data;
|
||||
if (success && data && data.trim() !== '') {
|
||||
let content = data;
|
||||
if (!data.startsWith('https://')) {
|
||||
content = marked.parse(data);
|
||||
}
|
||||
setHomePageContent(content);
|
||||
localStorage.setItem('home_page_content', content);
|
||||
|
||||
if (data.startsWith('https://')) {
|
||||
const iframe = document.querySelector('iframe');
|
||||
if (iframe) {
|
||||
iframe.onload = () => {
|
||||
iframe.contentWindow.postMessage({ themeMode: actualTheme }, '*');
|
||||
iframe.contentWindow.postMessage({ lang: i18n.language }, '*');
|
||||
};
|
||||
}
|
||||
}
|
||||
setHomePageContentLoaded(true);
|
||||
} else {
|
||||
// 没有自定义内容,显示默认首页
|
||||
localStorage.removeItem('home_page_content');
|
||||
setHomePageContent('');
|
||||
setHomePageContentLoaded(true);
|
||||
}
|
||||
} catch (e) {
|
||||
// 网络错误/无后端,直接显示默认首页,不报错
|
||||
setHomePageContent('');
|
||||
setHomePageContentLoaded(true);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const checkNoticeAndShow = async () => {
|
||||
const lastCloseDate = localStorage.getItem('notice_close_date');
|
||||
@@ -145,24 +100,7 @@ const Home = () => {
|
||||
checkNoticeAndShow();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
displayHomePageContent().then();
|
||||
}, []);
|
||||
|
||||
/* 如果管理员设置了自定义首页内容,则显示那个 */
|
||||
if (homePageContentLoaded && homePageContent !== '') {
|
||||
return (
|
||||
<div className='overflow-x-hidden w-full'>
|
||||
{homePageContent.startsWith('https://') ? (
|
||||
<iframe src={homePageContent} className='w-full h-screen border-none' />
|
||||
) : (
|
||||
<div className='mt-[60px]' dangerouslySetInnerHTML={{ __html: homePageContent }} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── 默认 Landing Page ── */
|
||||
/* ── Landing Page ── */
|
||||
return (
|
||||
<div className='lp-root'>
|
||||
<NoticeModal
|
||||
|
||||
Reference in New Issue
Block a user