コンテンツにスキップ
このページの翻訳は LLM によって生成されています。誤りに気づいた場合は GitHub で issue を開いてお知らせください。

コンテンツとブログ

varshaはAstroのコンテンツコレクションを使用して、ブログ記事とドキュメントページの両方を管理します。このガイドでは、コンテンツの作成、コレクションの管理、ブログ記事の公開方法について説明します。

コンテンツコレクションについて

Section titled “コンテンツコレクションについて”

Astroのコンテンツコレクションは、Markdown/MDXコンテンツを管理するための型安全な方法を提供します。varshaには2つのコレクションがあります:

コレクションディレクトリ目的
blogsrc/content/blog/ブログ記事
docssrc/content/docs/Starlightドキュメント(自動処理)

コレクションスキーマはsrc/content/config.tsで定義されています。

新しいブログ記事を作成するには、src/content/blog/に.mdまたは.mdxファイルを追加します:

src/content/blog/launch-announcement.md
---
title: "Launching varsha: A Premium Website Starter"
description: "Today we're launching varsha, a beautiful Astro starter template."
pubDate: "2025-01-15"
author: "Your Name"
tags: ["launch", "announcement", "astro"]
---
Today we're excited to announce the launch of **varsha**, our premium
website starter template built on Astro.
## Why varsha?
We built varsha because we were tired of starting every new project from
scratch. Every website needs a hero section, features grid, footer,
documentation, and blog — varsha gives you all of that out of the box.
## What's included
- 18+ beautiful themes
- Starlight documentation with search
- Blog with MDX support
- SEO optimization
- Zero-config deployment
フィールド型必須説明
titlestringはい記事タイトル
descriptionstringはいSEOと記事一覧のための短い説明
pubDatestringはい公開日("YYYY-MM-DD"形式)
authorstringいいえ著者名
tagsstring[]いいえタグの配列
heroImagestringいいえヒーロー画像のパス
draftbooleanいいえtrueの場合、記事が公開されない

MDXを使用すると、Markdownコンテンツ内でJSXコンポーネントを使用できます。ブログ記事でMDXを使用するには、ファイル拡張子を.mdxにします:

src/content/blog/feature-showcase.mdx
---
title: "Feature Showcase"
description: "See varsha components in action."
pubDate: "2025-01-20"
---
import { Card, CardGrid } from '@astrojs/starlight/components';
## Built-in Components
Here are some components you can use in MDX:
<CardGrid>
<Card title="Fast" icon="rocket">
Zero JavaScript by default means lightning-fast pages.
</Card>
<Card title="Beautiful" icon="sparkles">
18+ themes with carefully designed color palettes.
</Card>
</CardGrid>

ブログ記事はsrc/pages/blog/index.astroのブログ一覧ページに自動的に表示されます。このページはコンテンツコレクションから記事を取得します:

---
import { getCollection } from 'astro:content';
import Layout from '../../layouts/BlogPost.astro';
const posts = await getCollection('blog', ({ data }) => {
return import.meta.env.DEV || !data.draft;
});
const sortedPosts = posts.sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
);
---

下書き中の記事はdraft: trueを設定します:

---
title: "Coming Soon"
description: "This post is not ready yet."
pubDate: "2025-02-01"
draft: true
---

ドラフトは開発環境では表示されますが、プロダクションビルドでは除外されます。

ドキュメントページはStarlightによって処理され、src/content/docs/にあります。ドキュメントページは以下のfrontmatterを使用します:

---
title: "Page Title"
description: "A short description for SEO and the sidebar."
---

ローカライズ版ドキュメントはja/およびzh-cn/サブディレクトリに配置します。

ブログ記事やドキュメントで画像を使用する場合:

  1. 最適化が必要な画像はsrc/assets/に配置し、MDXでインポート
  2. 最適化が不要な静的画像はpublic/に配置
---
title: "Post with Images"
description: "A post demonstrating images."
pubDate: "2025-01-25"
---
import myImage from '../../assets/my-image.png';
![Alt text](../../../assets/my-image.png)

varshaはブログのRSSフィードを自動生成する場合があります。設定を確認し、@astrojs/rssインテグレーションを追加してフィードを有効にすることを検討してください。

  1. 説明的な説明文を書く — descriptionフィールドはSEOと記事一覧のカードに使用されます
  2. 一貫した日付形式を使用する — YYYY-MM-DDに固める
  3. タグを効果的に使う — 関連コンテンツをグループ化するのに役立ちます
  4. 長い記事には見出しを使う — スキャンしやすいよう、コンテンツを##セクションに分割
  5. ドラフトを本番環境にデプロイしない — デプロイ前にdraft: trueを確認
  6. MDXコンポーネントは控えめに使う — コンテンツを過度にカスタムコンポーネントに依存させない

SEOとメタデータ

コンテンツが検索エンジンとソーシャル共有で最適化されていることを確認します。

SEOとメタデータ →