Fumapress
The site generator

Blog

Build a blog system with Fumapress.

Installation

This plugin is included in fumapress.

Fumadocs MDX

If you use Fumadocs MDX, create a new collection for blog:

source.config.ts
import { defineDocs } from "fumadocs-mdx/config";
import { blogMetaSchema, blogPageSchema } from "fumapress/adapters/mdx/schema";

export const blog = defineDocs({
  dir: "content/blog",
  docs: {
    async: true,
    schema: blogPageSchema,
    postprocess: {
      includeProcessedMarkdown: true,
    },
  },
  meta: {
    schema: blogMetaSchema,
  },
});

Add the new collection as blog content source (and give the original one a name like docs), then enable the plugin:

press.config.tsx
import { defineConfig } from "fumapress";
import { loader } from "fumadocs-core/source";
import { blog, docs } from "./.source/server";
import { blogPlugin } from "fumapress/plugins/blog";

export default defineConfig({
  loader: loader(
    {
      docs: docs.toFumadocsSource(),
      blog: blog.toFumadocsSource({
        baseDir: "blog",
      }),
    },
    {
      baseUrl: "/",
    },
  ),
})
  .usePlugins(blogPlugin());

The plugin overrides the renderer for blog pages, by default, all pages from the blog content source are rendered as blog posts.

You can also define a isBlog() option to determine whether the page is a blog post

press.config.tsx
import { defineConfig } from "fumapress";
import { blogPlugin } from "fumapress/plugins/blog";

export default defineConfig({
  // ...
}).usePlugins(
  blogPlugin({
    isBlog: (page) => page.type === "blog",
  }),
);

Other Content Sources

If you don't use Fumadocs MDX, you can keep the your loader config, but make sure to define the isBlog() option like:

press.config.tsx
import { defineConfig } from "fumapress";
import { blogPlugin } from "fumapress/plugins/blog";
import { myCms } from "./my-cms";

export default defineConfig({
  loader: loader(myCms.toStaticSource(), {
    baseUrl: "/",
  }),
}).usePlugins(
  blogPlugin({
    // since it is not using multi-source, `page.type` will be `undefined`.
    // you need to detect it from other properties, like page path.
    isBlog: (page) => page.path.startsWith("blog/"),
  }),
);

Options

paths

The plugin will create additional pages, you can override their pathnames.

press.config.tsx
import { defineConfig } from "fumapress";
import { blogPlugin } from "fumapress/plugins/blog";

export default defineConfig({
  // ...
}).usePlugins(
  blogPlugin({
    paths: {
      index: "/blog",
      tags: "/blog/tags",
    },
  }),
);

You can set to false to disable a certain page.

layouts

Override the UI.

press.config.tsx
import { defineConfig } from "fumapress";
import { blogPlugin } from "fumapress/plugins/blog";
// blog layouts
import { createBlogLayout, createBlogLayoutPage } from "fumapress/layouts/blog";
import { createBlogIndexPage } from "fumapress/layouts/blog.index";
import { createBlogTagPage, createBlogTagsPage } from "fumapress/layouts/blog.tags";

export default defineConfig({
  // ...
}).usePlugins(
  blogPlugin({
    layouts: {
      // shared layout for blog
      layout: createBlogLayout(),
      // renderer for blog pages
      page: createBlogLayoutPage(),
      // renderer for blog's index page
      index: createBlogIndexPage(),
      // renderer for blog's tags list
      tags: createBlogTagsPage(),
      // renderer for blog's tag info page
      tag: createBlogTagPage(),
    },
  }),
);

Last updated on

On this page