LogoMkSaaS Docs

Blog

Learn how to create, manage, and customize blog posts with multi-language support

MkSaaS includes a powerful blog system built with Content Collections and MDX. The blog system supports multi-language content, categories, authors, and rich content formatting, making it ideal for SaaS marketing, announcements, tutorials, and knowledge base articles.

Blog System Structure

The blog system is built using Content Collections and integrates with internationalization.

blog-card.tsx
blog-grid.tsx
blog-category-filter.tsx
blog-toc.tsx

Configuration

The blog system can be configured in src/config/website.tsx:

src/config/website.tsx
export const websiteConfig = {
  // ...other config
  blog: {
    paginationSize: 9, // Number of posts per page
    relatedPostsSize: 3, // Number of related posts to show
  },
  // ...other config
}

Blog Collections

MkSaaS uses the following blog-related content collections:

Creating Blog Content

Adding a New Blog Post

  1. Create a new MDX file in the content/blog directory:
content/blog/my-first-post.mdx
---
title: My First Blog Post
description: This is a brief description of my first blog post.
image: /images/blog/my-first-post.jpg
date: 2023-12-01T00:00:00.000Z
published: true
categories: ["tutorial", "announcement"]
author: "mksaas"
---
 
# Introduction
 
This is my first blog post. Here I'll talk about something interesting.
 
## Section 1
 
Some content here...
 
## Section 2
 
More content here...
  1. Ensure your author and categories exist in their respective content collections.

Adding a New Author

Create a new MDX file in the content/author directory:

content/author/john-doe.mdx
---
slug: john-doe
name: John Doe
avatar: /images/authors/john-doe.jpg
---

Adding a New Category

Create a new MDX file in the content/category directory:

content/category/tutorial.mdx
---
slug: tutorial
name: Tutorial
description: Step-by-step guides to learn new features
---

Multi-language Support

MkSaaS blog system fully supports internationalization. You can create content in multiple languages using the following file naming convention:

  1. Default locale (e.g., English): filename.mdx
  2. Other locales (e.g., Chinese): filename.zh.mdx

Multi-language Blog Post Example

For an English blog post:

content/blog/welcome-post.mdx
---
title: Welcome to our Blog
description: Our first official blog post
image: /images/blog/welcome.jpg
date: 2023-12-01T00:00:00.000Z
published: true
categories: ["announcement"]
author: "mksaas"
---
 
Content in English...

For the same post in Chinese:

content/blog/welcome-post.zh.mdx
---
title: 欢迎来到我们的博客
description: 我们的第一篇官方博客文章
image: /images/blog/welcome.jpg
date: 2023-12-01T00:00:00.000Z
published: true
categories: ["announcement"]
author: "mksaas"
---
 
Content in Chinese...

The system will automatically match the post with the appropriate language based on the user's locale.

Multi-language Authors and Categories

Follow the same pattern for authors and categories:

content/author/mksaas.zh.mdx
---
slug: mksaas
name: MkSaaS 团队
avatar: /images/authors/mksaas.jpg
---
content/category/announcement.zh.mdx
---
slug: announcement
name: 公告
description: 官方平台公告和更新
---

Customizing the Blog Schema

To add new fields to blog posts, authors, or categories:

  1. Modify the schema in content-collections.ts
  2. Update the transform function as needed
  3. Update components to display the new fields
content-collections.ts
export const posts = defineCollection({
  name: 'post',
  directory: 'content/blog',
  include: '**/*.mdx',
  schema: (z) => ({
    title: z.string(),
    description: z.string(),
    image: z.string(),
    date: z.string().datetime(),
    published: z.boolean().default(true),
    categories: z.array(z.string()),
    author: z.string(),
    estimatedTime: z.number().optional(),
    // Add the new field
    featured: z.boolean().default(false),
  }),
  // ...transform logic remains the same
});

Then, you can use this field in your blog posts:

content/blog/important-post.mdx
---
title: Important Announcement
description: Read this important announcement
image: /images/blog/announcement.jpg
date: 2023-12-01T00:00:00.000Z
published: true
categories: ["announcement"]
author: "mksaas"
featured: true
---
 
Content here...

Advanced Usage

Changing Blog Post Card Layout

Customize the blog card component in src/components/blog/blog-card.tsx:

src/components/blog/blog-card.tsx
// Modify card styling
<div className="group flex flex-col border rounded-lg overflow-hidden h-full bg-card shadow-sm hover:shadow-md transition-shadow">
  {/* ... rest of the component */}
</div>

Querying Posts Programmatically

You can query posts programmatically using Content Collections:

import { allPosts } from 'content-collections';
 
// Get all published posts
const publishedPosts = allPosts.filter(post => post.published);
 
// Get featured posts
const featuredPosts = allPosts.filter(post => post.featured);
 
// Get posts by category
const tutorialPosts = allPosts.filter(post => 
  post.categories.some(category => category.slug === 'tutorial')
);
 
// Get posts by author
const authorPosts = allPosts.filter(post => post.author.slug === 'john-doe');

Best Practices

  1. Use High-Quality Images: Use properly sized and optimized images for blog posts
  2. Consistent Categories: Maintain a consistent set of categories across posts
  3. Strong Meta Content: Write compelling titles and descriptions for SEO benefits
  4. Structured Content: Use proper headings and sections in your blog post content
  5. Include Table of Contents: For longer posts, ensure headings are organized for TOC
  6. International Content: Keep translations consistent across all localized content
  7. Optimize Images: Use responsive images and lazy loading for better performance

Next Steps

Now that you understand how to work with the blog system in MkSaaS, you might want to explore these related features: