Skip to Content
Vuesho

Blog

A blog beside your docs.

@vuesho/blog publishes a content source's pages as blog posts. Each post has a page with its authors, its tags, and links to the newer and older posts. The plugin also adds a post index, a tags page and a page per tag.

Setup

Install the Package

npm i @vuesho/blog

Add the Posts

Put the posts in a separate folder, like content/blog:

index.md
hello.md

A collection reads the folder as a separate source, and blogPlugin() takes the source's key. The blog needs its own baseDir, since two sources can't both serve pages at the site root:

vuesho.config.ts
import { blogPlugin } from "@vuesho/blog";
import { createSite, recommendedPreset } from "vuesho/config";
import { defineCollections, defineDocs } from "vuesho/content";

const docs = defineDocs();
const blog = defineCollections({ type: "doc", dir: "content/blog" });

export default createSite({
  docs: docs.toSource(),
  blog: blog.toSource({ baseDir: "blog" }), 
}).plugins(recommendedPreset(), blogPlugin({ source: "blog" }));

With baseDir: "blog", content/blog/hello.md is the page /blog/hello.

Hide the Posts From the Sidebar

!blog in the root meta file hides the posts from the sidebar, but keeps their pages:

content/meta.json
{
  "pages": ["...", "!blog"]
}

Add a link to the index in the navbar:

vuesho.config.ts
createSite(sources).config({
  ui: { layoutProps: { links: [{ text: "Blog", url: "/blog" }] } },
});

Writing Posts

A post is a Markdown page. blogPlugin() adds three fields to its frontmatter: tags, authors and image.

content/blog/hello.md
---
title: Hello World
description: Our first post.
date: 2026-11-01 # Orders the posts, newest first
tags: [Announcement] # Each tag has a page
authors: [fuma] # Keys of the `authors` option of `blogPlugin()`
image: /covers/hello.png # The cover image
---

Our blog is open.

A post without a date comes first. The fields are typed on page.data, and a wrong type fails the build.

Frontmatter Schemas

If your collection has a frontmatter schema, leave tags, authors and image out of it, since the plugin declares them.

Authors

The authors option maps each ID in a post's authors to a profile. An ID without a profile shows as written:

vuesho.config.ts
blogPlugin({
  source: "blog",
  authors: {
    fuma: {
      name: "Fuma Nama",
      title: "Maintainer",
      url: "https://fuma-nama.dev",
      image: "https://github.com/fuma-nama.png",
    },
  },
});

Posts From Other Sources

The posts can come from any content source, or from several. getTags, getAuthors and getImage read a post's tags, authors and cover from other data, like a CMS field. When one returns undefined, the plugin reads the frontmatter field:

vuesho.config.ts
blogPlugin({
  source: ["blog", "news"],
  getTags: (post) => (post.type === "news" ? ["News"] : undefined),
  getImage: (post) => (post.type === "news" ? post.data.cover : undefined),
});

A post's date comes from the getPageCreatedAt hook, which reads date from a Markdown page's frontmatter.

Blog Pages

The plugin adds three pages beside the posts:

  • /blog: the post index, newest first
  • /blog/tags: every tag, with its post count
  • /blog/tags/announcement: the posts with a tag, like Announcement

paths changes their URLs, and false removes a page. With tags: false, a post's tags show without links:

vuesho.config.ts
blogPlugin({
  source: "blog",
  paths: { index: "/news", tags: false }, 
});

With Internationalization, each language has these pages, like /cn/blog. When the posts come from a dynamic source, the pages render on request.

Listing Posts

useBlogPosts() returns the posts in the page's language, newest first, for a custom page like a landing page:

src/pages/index.vue
<script setup lang="ts">
import { useBlogPosts } from "@vuesho/blog/theme";
import { Link } from "vuesho/client";

const posts = useBlogPosts();
</script>

<template>
  <ul>
    <li v-for="post in posts?.slice(0, 3)" :key="post.url">
      <Link :href="post.url">{{ post.title }}</Link>
    </li>
  </ul>
</template>

To render the posts' bodies, return them from the custom page's contentOf, as in Custom Pages.

Posts are in the sitemap, search and the RSS feed, like other pages. To limit the feed to posts, set rss.filter:

vuesho.config.ts
recommendedPreset({
  rss: {
    filter: ({ page }) => page.type === "blog", 
    channel: { title: "Acme Blog" },
  },
});

Customizing the UI

A post renders with the theme's blog.post layout, unless its frontmatter sets another layout. The index, the tags page and each tag's page are the views blog.index, blog.tags and blog.tag. Your theme can replace any of them:

src/theme.ts
import { defineTheme } from "vuesho/theme";
import defaultTheme from "vuesho/theme/default";
import type app from "../vuesho.config";

export default defineTheme<typeof app>({
  extends: defaultTheme,
  views: { "blog.index": () => import("./BlogIndex.vue") }, 
  layouts: { "blog.post": () => import("./BlogPost.vue") }, 
});

A replacement can wrap the built-in pages' components from @vuesho/blog/ui: BlogIndexView, BlogTagsView, BlogTagView and BlogPostView. A view receives its page as the page prop, with the view's props in page.props:

src/BlogIndex.vue
<script setup lang="ts">
import { BlogIndexView } from "@vuesho/blog/ui";
import type { PageOf } from "vuesho/client";
import { HomeShell } from "vuesho/theme";
import type app from "../vuesho.config";

defineProps<{ page: PageOf<typeof app, "blog.index"> }>();
</script>

<template>
  <HomeShell>
    <BlogIndexView v-bind="page.props">
      <template #heading>News</template>
      <template #description>What we're working on.</template>
    </BlogIndexView>
  </HomeShell>
</template>

A post's layout receives the post in page.pageData.blog, with the newer and older posts:

src/BlogPost.vue
<script setup lang="ts">
import { BlogPostView } from "@vuesho/blog/ui";
import type { PageOf } from "vuesho/client";
import { HomeShell, toTocItems } from "vuesho/theme";
import type app from "../vuesho.config";

defineProps<{ page: PageOf<typeof app, "blog"> }>();
</script>

<template>
  <HomeShell>
    <BlogPostView v-if="page.pageData.blog" v-bind="page.pageData.blog" :toc="toTocItems(page.toc)">
      <component :is="page.Content" />
    </BlogPostView>
  </HomeShell>
</template>

@vuesho/blog/types exports the data types, like BlogPost, BlogAuthor and BlogPostViewProps. To edit the components themselves, copy them into your project with vuesho add:

npx vuesho add components/layouts --from @vuesho/blog

Translations

The UI has language packs for zh-CN and zh-TW. For another language, or to change a label, set ui.translations, as in Internationalization:

vuesho.config.ts
createSite(sources).config({
  site: { lang: "ja" },
  ui: {
    translations: {
      "All Tags(blog tags page)": "すべてのタグ",
      "Newer post(blog post navigation)": "新しい記事",
      "Older post(blog post navigation)": "古い記事",
    },
  },
});

Options

Prop

Type

Each entry in authors:

Prop

Type