This post will quickly familiarize you with the entire structure of the Astro AntfuStyle Theme project.
Project Structure Overview#
Opening the project in your editor will reveal the following folders and files:
The above annotations provide a brief overview of the roles of directories and files in this theme project. Below, you’ll find additional details on the project structure along with recommendations for its organization.
Understanding the Pages
and Content
Directories#
The src/pages/
directory is a critical part of Astro, responsible for generating website pages, with each page corresponding to a route based on its file name. While Astro supports .astro
, .md
, and .mdx
files for this purpose, this theme exclusively uses .astro
and .mdx
files for generating pages (the reasoning behind this will be explained below).
The src/content/
directory is another reserved directory in Astro. It is designated for organizing content collections (supporting .md
and .mdx
files) and data collections (supporting .yaml
and .json
files). Additionally, it supports type-checking frontmatter and JSON using zod schemas. Each new directory created inside src/content/
represents a new content or data collection (with the directory name serving as the collection name). This is where you’ll store the real content of your site.
It is recommended to review the Astro’s Content Collections Docs to get a basic understanding of what Collections are and how to define them.
Page-Collection Mapping and Zod Schema#
Here’s how the theme’s pages correlate to collections and utilize zod schemas for type-checking:
URL Path | Page File Location | Content/Data Collection Path | Zod Schema for Collection |
---|---|---|---|
/ | src/pages/index.mdx | src/content/home/ | - |
/blog | src/pages/blog/index.mdx | src/content/blog/ | postSchema |
/blog/post-name /blog/sequences/one/two/three | src/pages/blog/[...slug].astro | src/content/blog/ | postSchema |
/projects | src/pages/projects.mdx | src/content/projects/ | projectsSchema |
/changelog | src/pages/changelog/index.mdx | src/content/changelog/ | postSchema |
/changelog/xxx | src/pages/changelog/[slug].astro | src/content/changelog/ | postSchema |
/feeds | src/pages/feeds.mdx | Data fetched externally | - |
/streams | src/pages/streams.mdx | src/content/streams/ | streamsSchema |
Further explanation on the decision process of when to use which file format in theme development:
.astro
: Used for reusable components (src/components/
), constructing page layouts (src/layouts/
), and generating multiple static pages through dynamic routing ( src/pages/blog/[...slug].astro
, as only .astro
files can handle Astro API calls).
.mdx
: Used for generating single static pages through static routing (src/pages/xxx.mdx
), and when component-style markup and JS expressions are needed in posts (this theme does not cover such usage).
.md
: Used for authoring text-heavy content like blog posts and documentation where no components are needed (src/content/blog/xxx.md
, src/content/home/index.md
, src/content/changelog/xxx.md
).
.json
: Used for list data (src/content/projects/data.json
, src/content/streams/data.json
).
This structure improves maintainability and scalability, and adherence to the file usage rules in this theme is recommended.
Reasons for .mdx
in src/pages/
.mdx
in src/pages/
Supports component imports, simplifying the organization of page structures with layout/view components.
Processed through Astro’s remark and rehype pipelines, enabling custom remark plugins to automatically generate matching OG images for each page.
Additionally, the .mdx
files in the src/pages/
are also defined as content collections. See Recreate Current Pages - Creating Pages for more details.
Wrapping Up#
This article provides a clear overview of the theme project’s structure and the reasoning behind its organization. By following these guidelines, you can maintain a scalable and manageable setup, while still having the flexibility to adapt it to your needs.
You can also explore Managing Image Assets, or dive deeper into the tech stack used in the theme to familiarize yourself with its features.
If you encounter any issues, find errors, or see opportunities for improvement as you explore the theme, feel free to join the discussion, or submit an issue or pull request. Your feedback is highly appreciated!
Thank you for your interest in this project! 😊