add blog to project

This commit is contained in:
mahdiarghyani
2025-11-09 13:56:03 +03:30
parent 24a91baaf5
commit c7e5eb0713
26 changed files with 3310 additions and 11 deletions
+14
View File
@@ -0,0 +1,14 @@
---
title: "This is a Draft Post"
description: "This post is in draft mode and should not appear in production."
date: "2024-11-10"
tags: ["draft", "test"]
author: "Ali Arghyani"
draft: true
---
# Draft Post
This is a draft post that should only be visible in development mode.
It will be filtered out in production using the `draft: true` frontmatter field.
@@ -0,0 +1,108 @@
---
title: "Getting Started with Nuxt Content"
description: "Learn how to build a powerful blog with Nuxt Content v3, featuring markdown support, syntax highlighting, and Vue component integration."
date: "2024-11-09"
tags: ["nuxt", "vue", "typescript", "tutorial"]
image: "/img/blog/nuxt-content-cover.jpg"
author: "Ali Arghyani"
draft: false
---
# Getting Started with Nuxt Content
Nuxt Content is a powerful file-based CMS that allows you to write content in Markdown, YAML, CSV, or JSON and query it with a MongoDB-like API. In this tutorial, we'll explore how to set up and use Nuxt Content v3 in your Nuxt 4 application.
## Why Nuxt Content?
Nuxt Content offers several advantages for content-driven applications:
- **File-based**: Write content in Markdown files with Git version control
- **Type-safe**: Full TypeScript support with auto-generated types
- **Powerful queries**: MongoDB-like API for filtering and sorting
- **Syntax highlighting**: Built-in code highlighting with Shiki
- **MDC syntax**: Embed Vue components directly in Markdown
## Installation
Installing Nuxt Content is straightforward:
```bash
pnpm add @nuxt/content
```
Then add it to your `nuxt.config.ts`:
```typescript
export default defineNuxtConfig({
modules: ['@nuxt/content']
})
```
## Creating Content
Create a `content/` directory in your project root and start writing Markdown files:
```markdown
---
title: "My First Post"
description: "This is my first blog post"
date: "2024-11-09"
---
# Hello World
This is my first post using Nuxt Content!
```
## Querying Content
Use the `queryContent()` composable to fetch your content:
```vue
<script setup>
const { data: posts } = await useAsyncData('posts', () =>
queryContent('blog')
.sort({ date: -1 })
.find()
)
</script>
```
## Rendering Content
Use the `ContentRenderer` component to render your Markdown:
```vue
<template>
<ContentRenderer :value="post" />
</template>
```
## Advanced Features
### Code Highlighting
Nuxt Content uses Shiki for beautiful syntax highlighting:
```javascript
// This code will be highlighted automatically
const greeting = (name) => {
console.log(`Hello, ${name}!`)
}
```
### MDC Components
You can use Vue components in your Markdown:
```markdown
::alert{type="info"}
This is an informational alert!
::
```
## Conclusion
Nuxt Content provides a powerful and flexible way to manage content in your Nuxt applications. With its file-based approach, powerful querying capabilities, and seamless Vue integration, it's perfect for blogs, documentation sites, and content-heavy applications.
Happy coding! 🚀
@@ -0,0 +1,133 @@
---
title: "TypeScript Best Practices for Vue 3"
description: "Discover essential TypeScript patterns and best practices for building type-safe Vue 3 applications with Composition API."
date: "2024-11-08"
tags: ["typescript", "vue", "best-practices", "composition-api"]
image: "/img/blog/typescript-vue.jpg"
author: "Ali Arghyani"
draft: false
---
# TypeScript Best Practices for Vue 3
TypeScript has become an essential tool for building robust Vue 3 applications. In this guide, we'll explore best practices for leveraging TypeScript's type system with Vue 3's Composition API.
## Type-Safe Props
Define props with proper TypeScript interfaces:
```vue
<script setup lang="ts">
interface Props {
title: string
count?: number
items: string[]
}
const props = defineProps<Props>()
</script>
```
## Typed Composables
Create reusable composables with full type safety:
```typescript
export function useCounter(initialValue = 0) {
const count = ref<number>(initialValue)
const increment = (): void => {
count.value++
}
const decrement = (): void => {
count.value--
}
return {
count: readonly(count),
increment,
decrement
}
}
```
## Generic Components
Build flexible components with generics:
```vue
<script setup lang="ts" generic="T extends { id: string }">
interface Props {
items: T[]
onSelect: (item: T) => void
}
const props = defineProps<Props>()
</script>
```
## Type-Safe Event Emits
Define emits with proper typing:
```vue
<script setup lang="ts">
interface Emits {
(e: 'update', value: string): void
(e: 'delete', id: number): void
}
const emit = defineEmits<Emits>()
</script>
```
## Utility Types
Leverage TypeScript utility types:
```typescript
// Pick specific properties
type UserPreview = Pick<User, 'id' | 'name' | 'email'>
// Make all properties optional
type PartialUser = Partial<User>
// Make all properties required
type RequiredUser = Required<User>
// Exclude properties
type UserWithoutPassword = Omit<User, 'password'>
```
## Type Guards
Implement type guards for runtime type checking:
```typescript
function isUser(value: unknown): value is User {
return (
typeof value === 'object' &&
value !== null &&
'id' in value &&
'name' in value
)
}
```
## Async Data Typing
Type your async data properly:
```typescript
const { data, pending, error } = await useAsyncData<User[]>(
'users',
() => $fetch('/api/users')
)
```
## Conclusion
TypeScript enhances Vue 3 development by providing type safety, better IDE support, and improved code maintainability. By following these best practices, you'll build more robust and maintainable applications.
Remember: TypeScript is a tool to help you, not hinder you. Start simple and gradually add more type safety as needed.