-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4b88cb
commit 8aa4b84
Showing
4 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { updateAbout } from "@/models/about.server"; | ||
import { createContact } from "@/models/contact.server"; | ||
import { createExperience } from "@/models/experience.server"; | ||
import { createProject } from "@/models/project.server"; | ||
import { readFileSync } from "fs"; | ||
import { join } from "path"; | ||
|
||
async function loadDataFromFile() { | ||
const filePath = join(__dirname, "./data-dev.json"); | ||
const data = JSON.parse(readFileSync(filePath, "utf8")); | ||
|
||
// Upload projects | ||
for (const project of data.projects) { | ||
await createProject(project); | ||
} | ||
|
||
// Upload experiences | ||
for (const experience of data.experience) { | ||
await createExperience(experience); | ||
} | ||
|
||
// Upload contacts | ||
for (const contact of data.messages) { | ||
await createContact(contact); | ||
} | ||
|
||
// Set About data | ||
await updateAbout(data.about); | ||
} | ||
|
||
loadDataFromFile(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { getAbout } from "@/models/about.server"; | ||
import { getAllMessages } from "@/models/contact.server"; | ||
import { getAllExperiences } from "@/models/experience.server"; | ||
import { getAllProjects } from "@/models/project.server"; | ||
|
||
export default function Download() { | ||
const getData = async () => { | ||
const [about, projects, experience, messages] = await Promise.all([ | ||
await getAbout(), | ||
await getAllProjects(), | ||
await getAllExperiences(), | ||
await getAllMessages(), | ||
]); | ||
return { about, projects, experience, messages }; | ||
}; | ||
|
||
const saveData = async () => { | ||
const allData = await getData(); | ||
const dataStr = | ||
"data:text/json;charset=utf-8," + | ||
encodeURIComponent(JSON.stringify(allData, null, 2)); | ||
const downloadAnchorNode = document.createElement("a"); | ||
downloadAnchorNode.setAttribute("href", dataStr); | ||
downloadAnchorNode.setAttribute("download", "data.json"); | ||
document.body.appendChild(downloadAnchorNode); // required for firefox | ||
downloadAnchorNode.click(); | ||
downloadAnchorNode.remove(); | ||
}; | ||
|
||
return ( | ||
<Button variant="link" onClick={saveData}> | ||
Download Data | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters