generated from template/astro-template
feat: md preview
This commit is contained in:
44
src/apps/preview/md.tsx
Normal file
44
src/apps/preview/md.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { ToastProvider } from '@/modules/toast/Provider';
|
||||
import { query } from '@/modules/query';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { MarkdownPreview } from '@/components/html/md/Preview';
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
<ToastProvider>
|
||||
<Main />
|
||||
</ToastProvider>
|
||||
);
|
||||
};
|
||||
const Main = () => {
|
||||
const [mdUrl, setMdUrl] = useState<string>('');
|
||||
const [markdown, setMarkdown] = useState<string>('');
|
||||
useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const md = url.searchParams.get('md');
|
||||
if (md) {
|
||||
setMdUrl(md);
|
||||
}
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!mdUrl) return;
|
||||
getMdContent(mdUrl);
|
||||
}, [mdUrl]);
|
||||
const getMdContent = async (url: string) => {
|
||||
console.log('url', url);
|
||||
const res = await query.fetchText({
|
||||
url: url,
|
||||
});
|
||||
if (res.code === 200) {
|
||||
console.log('Markdown content fetched:', res.data);
|
||||
setMarkdown(res.data);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='bg-white w-full h-full py-2 '>
|
||||
<MarkdownPreview content={markdown} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user