refactor: Reorganize project structure and update dependencies
- Removed blog, project, and work content files - Updated package dependencies including npm and removed license metadata - Refactored component layouts and page routes - Modified appwrite service for data operations
This commit is contained in:
1 parent
7997eccb12
commit
6ab3254384
51 files changed
+2951
-3221
No files matched your search
+50
-356
@@ -1,6 +1,6 @@
|
||||
import { Client, Databases, Storage } from "appwrite";
|
||||
import type { Models } from "appwrite";
|
||||
import { databases, storage } from "./appwrite"; // Import the already initialized databases and storage instances
|
||||
import type { Models, } from "appwrite";
|
||||
import { Query } from "appwrite";
|
||||
import { databases, } from "./appwrite"; // Import the already initialized databases instances
|
||||
import { remark } from "remark";
|
||||
import remarkRehype from "remark-rehype";
|
||||
import rehypeStringify from "rehype-stringify";
|
||||
@@ -62,6 +62,8 @@ export type WorkExperience = Models.Document & {
|
||||
company: string;
|
||||
role: string;
|
||||
dateStart: Date;
|
||||
content: string;
|
||||
contentHtml?: string; // HTML version of the content
|
||||
dateEnd: Date | string;
|
||||
};
|
||||
|
||||
@@ -73,6 +75,9 @@ export type LegalDocument = Models.Document & {
|
||||
};
|
||||
|
||||
|
||||
// Define a unified type for search results
|
||||
export type SearchEntry = BlogPost | Project;
|
||||
|
||||
// Collection IDs - these should be configured based on your Appwrite setup
|
||||
const BLOG_COLLECTION_ID = process.env.VITE_APPWRITE_BLOG_COLLECTION_ID || "blog";
|
||||
const PROJECTS_COLLECTION_ID = process.env.VITE_APPWRITE_PROJECTS_COLLECTION_ID || "project";
|
||||
@@ -118,7 +123,7 @@ export async function getBlogPostsPaginated(page: number, limit: number): Promis
|
||||
BLOG_COLLECTION_ID,
|
||||
[
|
||||
// Only fetch published posts (not drafts)
|
||||
`draft != true`
|
||||
Query.equal("draft", false)
|
||||
]
|
||||
);
|
||||
|
||||
@@ -164,19 +169,6 @@ export async function getBlogPostById(id: string): Promise<BlogPost> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all available blog templates
|
||||
*/
|
||||
export async function getBlogTemplates(): Promise<Array<{ id: string; name: string; slug: string }>> {
|
||||
// This is a static list of templates for now, but could be fetched from Appwrite
|
||||
return [
|
||||
{ id: "default", name: "Default", slug: "default" },
|
||||
{ id: "feature", name: "Feature", slug: "feature" },
|
||||
{ id: "news", name: "News", slug: "news" }
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get projects from Appwrite database
|
||||
*/
|
||||
@@ -214,7 +206,7 @@ export async function getProjectsPaginated(page: number, limit: number): Promise
|
||||
PROJECTS_COLLECTION_ID,
|
||||
[
|
||||
// Only fetch published projects (not drafts)
|
||||
`draft != true`
|
||||
Query.equal("draft", false)
|
||||
]
|
||||
);
|
||||
|
||||
@@ -270,8 +262,12 @@ export async function getWorkExperiences(): Promise<WorkExperience[]> {
|
||||
DATABASE_ID,
|
||||
WORK_COLLECTION_ID
|
||||
);
|
||||
|
||||
return response.documents;
|
||||
|
||||
// Convert markdown content to HTML for each project
|
||||
return response.documents.map(work => ({
|
||||
...work,
|
||||
contentHtml: convertMarkdownToHTML(work.content)
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("Error fetching work experiences:", error);
|
||||
throw new Error("Failed to fetch work experiences");
|
||||
@@ -296,359 +292,57 @@ export async function getLegalDocuments(): Promise<LegalDocument[]> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new blog post
|
||||
* Perform a search across blog posts and projects using Appwrite SDK
|
||||
*/
|
||||
export async function createBlogPost(postData: Omit<BlogPost, 'id'>): Promise<BlogPost> {
|
||||
export async function searchContent(query: string): Promise<{ posts: BlogPost[], projects: Project[] }> {
|
||||
try {
|
||||
// Validate required fields
|
||||
if (!postData.title || !postData.content) {
|
||||
throw new Error("Title and content are required for blog posts");
|
||||
}
|
||||
|
||||
const response = await databases.createDocument<BlogPost>(
|
||||
// Search in blog collection for the query term
|
||||
const blogResponse = await databases.listDocuments<BlogPost>(
|
||||
DATABASE_ID,
|
||||
BLOG_COLLECTION_ID,
|
||||
"unique()",
|
||||
postData
|
||||
[
|
||||
Query.equal("draft", false),
|
||||
Query.search("title", query),
|
||||
Query.search("summary", query),
|
||||
Query.search("content", query)
|
||||
]
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating blog post:", error);
|
||||
throw new Error("Failed to create blog post");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update an existing blog post
|
||||
*/
|
||||
export async function updateBlogPost(id: string, postData: Partial<BlogPost>): Promise<BlogPost> {
|
||||
try {
|
||||
// Validate that we have data to update
|
||||
if (!postData || Object.keys(postData).length === 0) {
|
||||
throw new Error("No data provided for update");
|
||||
}
|
||||
|
||||
const response = await databases.updateDocument<BlogPost>(
|
||||
DATABASE_ID,
|
||||
BLOG_COLLECTION_ID,
|
||||
id,
|
||||
postData
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML if content was updated
|
||||
if (postData.content !== undefined) {
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error updating blog post:", error);
|
||||
throw new Error("Failed to update blog post");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a blog post
|
||||
*/
|
||||
export async function deleteBlogPost(id: string): Promise<void> {
|
||||
try {
|
||||
await databases.deleteDocument(
|
||||
DATABASE_ID,
|
||||
BLOG_COLLECTION_ID,
|
||||
id
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error deleting blog post:", error);
|
||||
throw new Error("Failed to delete blog post");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a blog post image
|
||||
*/
|
||||
export async function uploadBlogImage(file: File): Promise<string> {
|
||||
try {
|
||||
// Validate file type
|
||||
if (!file.type.startsWith('image/')) {
|
||||
throw new Error("Only image files are allowed for blog images");
|
||||
}
|
||||
|
||||
// Validate file size (max 5MB)
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
throw new Error("Image file size exceeds 5MB limit");
|
||||
}
|
||||
|
||||
const response = await storage.createFile(
|
||||
"blog-images", // bucket ID
|
||||
"unique()",
|
||||
file
|
||||
);
|
||||
|
||||
return response.$id;
|
||||
} catch (error) {
|
||||
console.error("Error uploading blog image:", error);
|
||||
throw new Error("Failed to upload blog image");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
*/
|
||||
export async function createProject(projectData: Omit<Project, 'id'>): Promise<Project> {
|
||||
try {
|
||||
// Validate required fields
|
||||
if (!projectData.title || !projectData.content) {
|
||||
throw new Error("Title and content are required for projects");
|
||||
}
|
||||
|
||||
const response = await databases.createDocument<Project>(
|
||||
// Search in projects collection for the query term
|
||||
const projectResponse = await databases.listDocuments<Project>(
|
||||
DATABASE_ID,
|
||||
PROJECTS_COLLECTION_ID,
|
||||
"unique()",
|
||||
projectData
|
||||
[
|
||||
Query.equal("draft", false),
|
||||
Query.search("title", query),
|
||||
Query.search("summary", query),
|
||||
Query.search("content", query)
|
||||
]
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML
|
||||
// Convert markdown content to HTML for blog posts
|
||||
const blogPostsWithHtml = blogResponse.documents.map(post => ({
|
||||
...post,
|
||||
contentHtml: convertMarkdownToHTML(post.content)
|
||||
}));
|
||||
|
||||
// Convert markdown content to HTML for projects
|
||||
const projectsWithHtml = projectResponse.documents.map(project => ({
|
||||
...project,
|
||||
contentHtml: convertMarkdownToHTML(project.content)
|
||||
}));
|
||||
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
posts: blogPostsWithHtml,
|
||||
projects: projectsWithHtml
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating project:", error);
|
||||
throw new Error("Failed to create project");
|
||||
console.error("Error performing search:", error);
|
||||
throw new Error("Failed to perform search");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update an existing project
|
||||
*/
|
||||
export async function updateProject(id: string, projectData: Partial<Project>): Promise<Project> {
|
||||
try {
|
||||
// Validate that we have data to update
|
||||
if (!projectData || Object.keys(projectData).length === 0) {
|
||||
throw new Error("No data provided for update");
|
||||
}
|
||||
|
||||
const response = await databases.updateDocument<Project>(
|
||||
DATABASE_ID,
|
||||
PROJECTS_COLLECTION_ID,
|
||||
id,
|
||||
projectData
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML if content was updated
|
||||
if (projectData.content !== undefined) {
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error updating project:", error);
|
||||
throw new Error("Failed to update project");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a project
|
||||
*/
|
||||
export async function deleteProject(id: string): Promise<void> {
|
||||
try {
|
||||
await databases.deleteDocument(
|
||||
DATABASE_ID,
|
||||
PROJECTS_COLLECTION_ID,
|
||||
id
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error deleting project:", error);
|
||||
throw new Error("Failed to delete project");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a project image
|
||||
*/
|
||||
export async function uploadProjectImage(file: File): Promise<string> {
|
||||
try {
|
||||
// Validate file type
|
||||
if (!file.type.startsWith('image/')) {
|
||||
throw new Error("Only image files are allowed for project images");
|
||||
}
|
||||
|
||||
// Validate file size (max 5MB)
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
throw new Error("Image file size exceeds 5MB limit");
|
||||
}
|
||||
|
||||
const response = await storage.createFile(
|
||||
"project-images", // bucket ID
|
||||
"unique()",
|
||||
file
|
||||
);
|
||||
|
||||
return response.$id;
|
||||
} catch (error) {
|
||||
console.error("Error uploading project image:", error);
|
||||
throw new Error("Failed to upload project image");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new work experience
|
||||
*/
|
||||
export async function createWorkExperience(workData: Omit<WorkExperience, 'id'>): Promise<WorkExperience> {
|
||||
try {
|
||||
// Validate required fields
|
||||
if (!workData.company || !workData.role) {
|
||||
throw new Error("Company and role are required for work experiences");
|
||||
}
|
||||
|
||||
const response = await databases.createDocument<WorkExperience>(
|
||||
DATABASE_ID,
|
||||
WORK_COLLECTION_ID,
|
||||
"unique()",
|
||||
workData
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error creating work experience:", error);
|
||||
throw new Error("Failed to create work experience");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing work experience
|
||||
*/
|
||||
export async function updateWorkExperience(id: string, workData: Partial<WorkExperience>): Promise<WorkExperience> {
|
||||
try {
|
||||
// Validate that we have data to update
|
||||
if (!workData || Object.keys(workData).length === 0) {
|
||||
throw new Error("No data provided for update");
|
||||
}
|
||||
|
||||
const response = await databases.updateDocument<WorkExperience>(
|
||||
DATABASE_ID,
|
||||
WORK_COLLECTION_ID,
|
||||
id,
|
||||
workData
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error updating work experience:", error);
|
||||
throw new Error("Failed to update work experience");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a work experience
|
||||
*/
|
||||
export async function deleteWorkExperience(id: string): Promise<void> {
|
||||
try {
|
||||
await databases.deleteDocument(
|
||||
DATABASE_ID,
|
||||
WORK_COLLECTION_ID,
|
||||
id
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error deleting work experience:", error);
|
||||
throw new Error("Failed to delete work experience");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new legal document
|
||||
*/
|
||||
export async function createLegalDocument(docData: Omit<LegalDocument, 'id'>): Promise<LegalDocument> {
|
||||
try {
|
||||
// Validate required fields
|
||||
if (!docData.title || !docData.content) {
|
||||
throw new Error("Title and content are required for legal documents");
|
||||
}
|
||||
|
||||
const response = await databases.createDocument<LegalDocument>(
|
||||
DATABASE_ID,
|
||||
LEGAL_COLLECTION_ID,
|
||||
"unique()",
|
||||
docData
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating legal document:", error);
|
||||
throw new Error("Failed to create legal document");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update an existing legal document
|
||||
*/
|
||||
export async function updateLegalDocument(id: string, docData: Partial<LegalDocument>): Promise<LegalDocument> {
|
||||
try {
|
||||
// Validate that we have data to update
|
||||
if (!docData || Object.keys(docData).length === 0) {
|
||||
throw new Error("No data provided for update");
|
||||
}
|
||||
|
||||
const response = await databases.updateDocument<LegalDocument>(
|
||||
DATABASE_ID,
|
||||
LEGAL_COLLECTION_ID,
|
||||
id,
|
||||
docData
|
||||
);
|
||||
|
||||
// Convert markdown content to HTML if content was updated
|
||||
if (docData.content !== undefined) {
|
||||
return {
|
||||
...response,
|
||||
contentHtml: convertMarkdownToHTML(response.content)
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error updating legal document:", error);
|
||||
throw new Error("Failed to update legal document");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a legal document
|
||||
*/
|
||||
export async function deleteLegalDocument(id: string): Promise<void> {
|
||||
try {
|
||||
await databases.deleteDocument(
|
||||
DATABASE_ID,
|
||||
LEGAL_COLLECTION_ID,
|
||||
id
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error deleting legal document:", error);
|
||||
throw new Error("Failed to delete legal document");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a public URL for a file
|
||||
*/
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
import { Client, Storage, Databases } from "appwrite";
|
||||
import { Client, Databases } from "appwrite";
|
||||
|
||||
const client = new Client();
|
||||
|
||||
@@ -29,5 +29,4 @@ if (typeof window === 'undefined') {
|
||||
.setProject(projectId); // Your Project ID
|
||||
}
|
||||
|
||||
export const storage = new Storage(client);
|
||||
export const databases = new Databases(client);
|
||||
Reference in new issue
Block a user