My First Blog Post

01/07/2022

Here are some rules/recommendations, tips & ticks for creating new posts in AstroPaper blog theme.

Table of contents

Frontmatter

Frontmatter is the main place to store some important information about the blog post (article). Frontmatter lies at the top of the article and is written in YAML format. Read more about frontmatter and its usage in astro documentation.

Here is the list of frontmatter property for each post.

PropertyDescriptionRemark
titleTitle of the post. (h1)required*
descriptionDescription of the post. Used in post excerpt and site description of the post.required*
pubDatetimePublished datetime in ISO 8601 format.required*
authorAuthor of the post.default = SITE.author
postSlugSlug for the post. Will automatically be slugified.default = slugified title
featuredWhether or not display this post in featured section of home pagedefault = false
draftMark this post ‘unpublished’.default = false
tagsRelated keywords for this post. Written in array yaml format.default = others
ogImageOG image of the post. Useful for social media sharing and SEO.default = SITE.ogImage or generated OG image
canonicalURLCanonical URL (absolute), in case the article already exists on other source.default = Astro.site + Astro.url.pathname

Only title, description and pubDatetime fields in frontmatter must be specified.

Title and description (excerpt) are important for search engine optimization (SEO) and thus AstroPaper encourages to include these in blog posts.

slug is the unique identifier of the url. Thus, slug must be unique and different from other posts. The whitespace of slug needs to be separated with - or _ but - is recommended. However, even if you don’t write the correct slug, AstroPaper will automatically slugify your incorrect slug. If slug is not specified, the slugified title of the post will be used as slug.

If you omit tags in a blog post (in other words, if no tag is specified), the default tag others will be used as a tag for that post. You can set the default tag in the /src/content/config.ts file.

// src/content/config.ts
export const blogSchema = z.object({
  // ---
  draft: z.boolean().optional(),
  tags: z.array(z.string()).default(['others']), // replace "others" with whatever you want
  // ---
});

Sample Frontmatter

Here is the sample frontmatter for a post.

# src/content/blog/sample-post.md
---
title: The title of the post
author: your name
pubDatetime: 2022-09-21T05:17:19Z
postSlug: the-title-of-the-post
featured: true
draft: false
tags:
  - some
  - example
  - tags
ogImage: ''
description: This is the example description of the example post.
canonicalURL: https://example.org/my-article-was-already-posted-here
---

Adding table of contents

By default, a post (article) does not include any table of contents (toc). To include toc, you have to specify it in a specific way.

Write Table of contents in h2 format (## in markdown) and place it where you want it to be appeared on the post.

For instance, if you want to place your table of contents just under the intro paragraph (like I usually do), you can do that in the following way.

---
# some frontmatter
---

Here are some recommendations, tips & ticks for creating new posts in AstroPaper blog theme.

## Table of contents

<!-- the rest of the post -->

Headings

There’s one thing to note about headings. The AstroPaper blog posts use title (title in the frontmatter) as the main heading of the post. Therefore, the rest of the heading in the post should be using h2 ~ h6.

This rule is not mandatory, but highly recommended for visual, accessibility and SEO purposes.

Storing Images for Blog Content

Here are two methods for storing images and displaying them inside a markdown file.

Note! If it’s a requirement to style optimized images in markdown you should use MDX.

You can store images inside src/assets/ directory. These images will be automatically optimized by Astro through Image Service API.