diff --git a/src/content/files/README.md b/public/files/README.md similarity index 100% rename from src/content/files/README.md rename to public/files/README.md diff --git a/src/content/files/casual_film_critic.md b/public/files/casual_film_critic.md similarity index 100% rename from src/content/files/casual_film_critic.md rename to public/files/casual_film_critic.md diff --git a/src/content/files/concerts.md b/public/files/concerts.md similarity index 100% rename from src/content/files/concerts.md rename to public/files/concerts.md diff --git a/src/content/files/directing.md b/public/files/directing.md similarity index 100% rename from src/content/files/directing.md rename to public/files/directing.md diff --git a/src/content/files/doodling.md b/public/files/doodling.md similarity index 100% rename from src/content/files/doodling.md rename to public/files/doodling.md diff --git a/src/content/files/favourite_films.md b/public/files/favourite_films.md similarity index 100% rename from src/content/files/favourite_films.md rename to public/files/favourite_films.md diff --git a/src/content/files/jamming_with_jaryd.md b/public/files/jamming_with_jaryd.md similarity index 100% rename from src/content/files/jamming_with_jaryd.md rename to public/files/jamming_with_jaryd.md diff --git a/src/content/files/mario_kart.md b/public/files/mario_kart.md similarity index 100% rename from src/content/files/mario_kart.md rename to public/files/mario_kart.md diff --git a/src/content/files/mini_builds.md b/public/files/mini_builds.md similarity index 100% rename from src/content/files/mini_builds.md rename to public/files/mini_builds.md diff --git a/src/content/files/personal_site.md b/public/files/personal_site.md similarity index 100% rename from src/content/files/personal_site.md rename to public/files/personal_site.md diff --git a/src/content/files/resonant.md b/public/files/resonant.md similarity index 100% rename from src/content/files/resonant.md rename to public/files/resonant.md diff --git a/src/content/files/socratica.md b/public/files/socratica.md similarity index 100% rename from src/content/files/socratica.md rename to public/files/socratica.md diff --git a/src/content/files/uw_blueprint.md b/public/files/uw_blueprint.md similarity index 100% rename from src/content/files/uw_blueprint.md rename to public/files/uw_blueprint.md diff --git a/src/content/filesystem.json b/src/content/filesystem.json index f49fc0a..2c67f44 100644 --- a/src/content/filesystem.json +++ b/src/content/filesystem.json @@ -8,19 +8,19 @@ "id": "casual_film_critic", "name": "Casual Film Critic.txt", "type": "file", - "path": "/src/content/files/casual_film_critic.md" + "path": "/files/casual_film_critic.md" }, { "id": "directing", "name": "Directing.txt", "type": "file", - "path": "/src/content/files/directing.md" + "path": "/files/directing.md" }, { "id": "favourite_films", "name": "Favourites.txt", "type": "file", - "path": "/src/content/files/favourite_films.md" + "path": "/files/favourite_films.md" } ] }, @@ -33,13 +33,13 @@ "id": "jamming_with_jaryd", "name": "Jamming With Jaryd.txt", "type": "file", - "path": "/src/content/files/jamming_with_jaryd.md" + "path": "/files/jamming_with_jaryd.md" }, { "id": "concerts", "name": "Concerts.txt", "type": "file", - "path": "/src/content/files/concerts.md" + "path": "/files/concerts.md" } ] }, @@ -52,25 +52,25 @@ "id": "socratica", "name": "Socratica.txt", "type": "file", - "path": "/src/content/files/socratica.md" + "path": "/files/socratica.md" }, { "id": "mario_kart", "name": "Mario Kart.txt", "type": "file", - "path": "/src/content/files/mario_kart.md" + "path": "/files/mario_kart.md" }, { "id": "uw_blueprint", "name": "UW Blueprint.txt", "type": "file", - "path": "/src/content/files/uw_blueprint.md" + "path": "/files/uw_blueprint.md" }, { "id": "doodling", "name": "Doodling.txt", "type": "file", - "path": "/src/content/files/doodling.md" + "path": "/files/doodling.md" } ] }, @@ -83,19 +83,19 @@ "id": "resonant", "name": "Resonant.txt", "type": "file", - "path": "/src/content/files/resonant.md" + "path": "/files/resonant.md" }, { "id": "mini_builds", "name": "Mini Builds.txt", "type": "file", - "path": "/src/content/files/mini_builds.md" + "path": "/files/mini_builds.md" }, { "id": "personal_site", "name": "Personal Site.txt", "type": "file", - "path": "/src/content/files/personal_site.md" + "path": "/files/personal_site.md" } ] }, @@ -103,6 +103,6 @@ "id": "readme", "name": "README.txt", "type": "file", - "path": "/src/content/files/README.md" + "path": "/files/README.md" } ] \ No newline at end of file diff --git a/src/pages/PersonalPage.tsx b/src/pages/PersonalPage.tsx index 6d0f35a..7cb2160 100644 --- a/src/pages/PersonalPage.tsx +++ b/src/pages/PersonalPage.tsx @@ -11,6 +11,7 @@ type FileItem = { name: string; type: "file" | "folder"; path: string; + content?: string; children?: FileItem[]; }; @@ -24,18 +25,18 @@ type WindowState = { parentId?: string; }; -async function loadMarkdownContent(path: string): Promise { - try { - // Using dynamic import to load markdown files - const content = await import( - /* @vite-ignore */ - path - ); - return content.markdown; - } catch (error) { - console.error(`Error loading markdown file: ${path}`, error); - return "Error loading content"; - } +// Helper function to recursively process the file system +function processFileSystem(items: FileItem[]): FileItem[] { + return items.map((item) => { + if (item.type === "folder" && item.children) { + return { ...item, children: processFileSystem(item.children) }; + } + if (item.type === "file" && item.path) { + // For files, we'll load the content here + return { ...item, content: "" }; // Initialize with empty content + } + return item; + }); } function PersonalPage() { @@ -45,12 +46,43 @@ function PersonalPage() { const [disabledItems, setDisabledItems] = useState>(new Set()); useEffect(() => { - setFileSystem(fileSystemData as FileItem[]); + const processedFileSystem = processFileSystem(fileSystemData as FileItem[]); + setFileSystem(processedFileSystem); + + // Load all file contents + const loadAllContents = async () => { + const loadContent = async (items: FileItem[]): Promise => { + const promises = items.map(async (item) => { + if (item.type === "file" && item.path) { + try { + const response = await fetch(item.path); + const content = await response.text(); + return { ...item, content }; + } catch (error) { + console.error(`Error loading file: ${item.path}`, error); + return { ...item, content: "Error loading content" }; + } + } + if (item.type === "folder" && item.children) { + const children = await loadContent(item.children); + return { ...item, children }; + } + return item; + }); + + return Promise.all(promises); + }; + + const updatedFileSystem = await loadContent(processedFileSystem); + setFileSystem(updatedFileSystem); + }; + + loadAllContents(); }, []); const isDisabled = (id: string) => disabledItems.has(id); - const openWindow = async (item: FileItem, parentId?: string) => { + const openWindow = (item: FileItem, parentId?: string) => { // Check if window is already open const existingWindow = windows.find((w) => w.id === item.id); if (existingWindow) { @@ -65,12 +97,11 @@ function PersonalPage() { return newSet; }); - if (item.type === "file" && item.name.endsWith(".txt")) { - const content = await loadMarkdownContent(item.path); + if (item.type === "file") { const newWindow: WindowState = { id: item.id, title: item.name, - content: content, + content: item.content || "Error: Content not loaded", zIndex: maxZIndex + 1, isOpen: true, windowType: "text",