니디걸오버도즈
This commit is contained in:
parent
d4c8c9d9c5
commit
5be9625af3
25 changed files with 208 additions and 29 deletions
40
src/hooks/use-readme-waka.ts
Normal file
40
src/hooks/use-readme-waka.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function useReadmeWaka() {
|
||||
const [wakaContent, setWakaContent] = useState<string>('');
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchWakaContent = async () => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
'https://raw.githubusercontent.com/imnyang/imnyang/refs/heads/main/README.md'
|
||||
);
|
||||
if (!response.ok) throw new Error('Failed to fetch README');
|
||||
|
||||
const text = await response.text();
|
||||
const startMarker = '<!--START_SECTION:waka-->';
|
||||
const endMarker = '<!--END_SECTION:waka-->';
|
||||
|
||||
const startIdx = text.indexOf(startMarker);
|
||||
const endIdx = text.indexOf(endMarker);
|
||||
|
||||
if (startIdx !== -1 && endIdx !== -1) {
|
||||
const content = text.slice(startIdx + startMarker.length, endIdx).trim();
|
||||
setWakaContent(content);
|
||||
} else {
|
||||
setError('Could not find waka section');
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Unknown error');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchWakaContent();
|
||||
}, []);
|
||||
|
||||
return { wakaContent, isLoading, error };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue