Blog System in ShadcnKit
Understanding and using the built-in blog functionality in ShadcnKit
Blog System in ShadcnKit
ShadcnKit comes with a pre-configured blog system that supports multiple languages and dynamic routing. This guide will help you understand its structure and how to use it.
Key Components
-
Content Management
app/content/article.ts
: Defines the structure of blog postsapp/content/articles/
: Contains individual article content
-
Routing and Pages
app/[locale]/blog/[slug]/page.tsx
: Dynamic route for individual blog postsapp/[locale]/blog/page.tsx
: Blog index page
-
Utility Functions
app/content/functions/get-all-slugs.ts
: Generates slugs for all blog postsapp/content/functions/get-blog-slug.ts
: Retrieves blog posts by slug
-
SEO and Sitemap
app/sitemap.ts
: Generates a sitemap for your blogapp/robots.ts
: Configures robots.txt for search engines
How It Works
-
Content Definition: Blog posts are defined in
article.ts
with multilingual support. -
Dynamic Routing: The
[slug]
and[locale]
parameters in the file structure enable dynamic routing for different languages and blog posts. -
Content Retrieval: The
getBlogs
function fetches the appropriate content based on the slug and locale. -
SEO Optimization: Metadata, sitemaps, and robots.txt are automatically generated for better search engine visibility.
Customization
To add or modify blog posts:
- Create a new file in
app/content/articles/
for your blog post content. - Add the blog post metadata to the
blogs
array inapp/content/article.ts
. - Create translations for your blog post in the respective language files (e.g.,
en.json
,fr.json
,ar.json
).
Internationalization
The blog system supports multiple languages:
- Content is stored with translations for each supported language.
- The
[locale]
parameter in the URL determines the displayed language. - Translations are managed through JSON files in the
messages
directory.
SEO Features
- Dynamic metadata generation for each blog post
- Automatic sitemap generation including all blog posts
- Configurable robots.txt for search engine crawling
Usage Example
To create a new blog post:
- Add your content to a new file in
app/content/articles/
:
- Update
app/content/article.ts
:
- The new blog post will automatically be available at
/[locale]/blog/your-blog-post-slug
and included in the sitemap.
By leveraging this blog system, you can easily manage and expand your blog content within ShadcnKit, benefiting from built-in internationalization and SEO features.