|
|
@@ -3,12 +3,6 @@ import MarkdownIt from 'markdown-it';
|
|
|
import { full as emoji } from 'markdown-it-emoji';
|
|
|
import DOMPurify from 'dompurify';
|
|
|
|
|
|
-
|
|
|
-// FIXME: A dynamic API for posts soontm?
|
|
|
-const postFileNames = [
|
|
|
- '20250715.md',
|
|
|
-];
|
|
|
-
|
|
|
const scrollableTablesPlugin = (md) => {
|
|
|
const defaultRenderOpen = md.renderer.rules.table_open || function (tokens, idx, options, env, self) {
|
|
|
return self.renderToken(tokens, idx, options);
|
|
|
@@ -37,6 +31,7 @@ md.use(scrollableTablesPlugin)
|
|
|
.use(emoji);
|
|
|
|
|
|
function App() {
|
|
|
+ const [postFileNames, setPostFileNames] = useState([]);
|
|
|
const [selectedPost, giveFoxHerHeir] = useState(null);
|
|
|
const [markdownPosts, setMarkdownPosts] = useState({});
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
@@ -47,32 +42,37 @@ function App() {
|
|
|
setLoading(true);
|
|
|
const posts = {};
|
|
|
try {
|
|
|
+ const indexRes = await fetch('/posts/index.json');
|
|
|
+ if (!indexRes.ok) throw new Error(`Failed to fetch index.json: ${indexRes.statusText}`);
|
|
|
+ const fileNames = await indexRes.json();
|
|
|
+ setPostFileNames(fileNames);
|
|
|
await Promise.all(
|
|
|
- postFileNames.map(async (fileName) => {
|
|
|
+ fileNames.map(async (fileName) => {
|
|
|
const response = await fetch(`/posts/${fileName}`);
|
|
|
- if (!response.ok) {
|
|
|
- console.error(`Failed to fetch ${fileName}: ${response.statusText}`);
|
|
|
- throw new Error(`Failed to fetch ${fileName}: ${response.statusText}`);
|
|
|
- }
|
|
|
+ if (!response.ok) throw new Error(`Failed to fetch ${fileName}: ${response.statusText}`);
|
|
|
+
|
|
|
const markdown = await response.text();
|
|
|
const tensorRelease = fileName.replace('.md', '');
|
|
|
const titleMatch = markdown.match(/title:\s*(.*)/);
|
|
|
const descMatch = markdown.match(/desc:\s*(.*)/);
|
|
|
|
|
|
const title = titleMatch ? md.renderInline(titleMatch[1]) : "No Title";
|
|
|
- const description = descMatch ? md.renderInline(descMatch[1]) : md.renderInline(markdown.substring(0, 150) + "...");
|
|
|
+ const description = descMatch
|
|
|
+ ? md.renderInline(descMatch[1])
|
|
|
+ : md.renderInline(markdown.substring(0, 150) + "...");
|
|
|
|
|
|
posts[tensorRelease] = {
|
|
|
fullContent: markdown,
|
|
|
- title: title,
|
|
|
- description: description,
|
|
|
+ title,
|
|
|
+ description,
|
|
|
};
|
|
|
})
|
|
|
);
|
|
|
+
|
|
|
setMarkdownPosts(posts);
|
|
|
} catch (e) {
|
|
|
console.error("Error fetching posts:", e);
|
|
|
- setError("Failed to load posts. Please check if the .md files are in the public/posts directory.");
|
|
|
+ setError("Failed to load posts. Please check if index.json and .md files exist in public/posts/");
|
|
|
} finally {
|
|
|
setLoading(false);
|
|
|
}
|
|
|
@@ -80,6 +80,7 @@ function App() {
|
|
|
getTingyun();
|
|
|
}, []);
|
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
const updatePostFromUrl = () => {
|
|
|
const path = window.location.pathname;
|