ページとレイアウト
ページとレイアウトの作成方法について詳しく学びます。
varshaはAstroのコンテンツコレクションを使用して、ブログ記事とドキュメントページの両方を管理します。このガイドでは、コンテンツの作成、コレクションの管理、ブログ記事の公開方法について説明します。
Astroのコンテンツコレクションは、Markdown/MDXコンテンツを管理するための型安全な方法を提供します。varshaには2つのコレクションがあります:
| コレクション | ディレクトリ | 目的 |
|---|---|---|
blog | src/content/blog/ | ブログ記事 |
docs | src/content/docs/ | Starlightドキュメント(自動処理) |
コレクションスキーマはsrc/content/config.tsで定義されています。
新しいブログ記事を作成するには、src/content/blog/に.mdまたは.mdxファイルを追加します:
---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 premiumwebsite starter template built on Astro.
## Why varsha?
We built varsha because we were tired of starting every new project fromscratch. 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| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
title | string | はい | 記事タイトル |
description | string | はい | SEOと記事一覧のための短い説明 |
pubDate | string | はい | 公開日("YYYY-MM-DD"形式) |
author | string | いいえ | 著者名 |
tags | string[] | いいえ | タグの配列 |
heroImage | string | いいえ | ヒーロー画像のパス |
draft | boolean | いいえ | trueの場合、記事が公開されない |
MDXを使用すると、Markdownコンテンツ内でJSXコンポーネントを使用できます。ブログ記事でMDXを使用するには、ファイル拡張子を.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/サブディレクトリに配置します。
ブログ記事やドキュメントで画像を使用する場合:
src/assets/に配置し、MDXでインポートpublic/に配置---title: "Post with Images"description: "A post demonstrating images."pubDate: "2025-01-25"---
import myImage from '../../assets/my-image.png';
varshaはブログのRSSフィードを自動生成する場合があります。設定を確認し、@astrojs/rssインテグレーションを追加してフィードを有効にすることを検討してください。
descriptionフィールドはSEOと記事一覧のカードに使用されますYYYY-MM-DDに固める##セクションに分割draft: trueを確認ページとレイアウト
ページとレイアウトの作成方法について詳しく学びます。
SEOとメタデータ
コンテンツが検索エンジンとソーシャル共有で最適化されていることを確認します。