Astro Loader for Obsidian Vaults πŸͺπŸ”—

by Spaceship CO 8/4/2025

astro-loader-obsidian is a content loader for Astro that lets you treat your Obsidian vault as a native content collection. Easily integrate your markdown notes, assets, and internal links into your Astro site with minimal setup.

✨ Features

πŸš€ Use Cases

🧰 Need a Full Theme?

Check out astro-theme-spaceship β€” a ready-to-use theme built specifically for publishing Obsidian vaults with Astro. It includes:

πŸ“¦ Installation

npm install astro-loader-obsidian

πŸ”§ Usage

  1. Setup your Astro config to include the loader:
// content.config.mjs
import { ObsidianDocumentSchema, ObsidianMdLoader } from "astro-loader-obsidian";
import { defineCollection } from 'astro:content';

export const collections = {
	documents: defineCollection({
		loader: ObsidianMdLoader({
			base: 'src/content/vault',
			url: 'docs',
		}),
		schema: ({ image }) => ObsidianDocumentSchema.extend({
      image: image().optional(),
      // or
      cover: image().optional(),
    }),
	}),
};
  1. Use your documents as content in Astro components or pages:
import { getCollection } from 'astro:content';

const documents = await getCollection('documents');
  1. Linking between notes works automatically:
<a href={document.data.permalink}>Read: {note.data.title}</a>

🧠 Frontmatter Support

Astro Loader respects frontmatter metadata in your Obsidian notes. You can use:

---
title: "My Note"
date: 2025-04-06
tags: [astro, obsidian]
published: true
---

These fields will be accessible via the data object in your content collections.

πŸ“ Directory Structure

Example vault structure:

vault/
β”œβ”€β”€ My Note.md
β”œβ”€β”€ My Other Note.md
β”œβ”€β”€ images/
β”‚   └── image.png

Will be available in Astro as:

/docs/my-note
/docs/my-other-note
/images/image.png

πŸ§ͺ Type Safety

You can extend the schema for your frontmatter using Zod’s extend features:

// content.config.mjs
import { defineCollection, z } from 'astro:content';

export const collections = {
	documents: defineCollection({
		loader: ObsidianMdLoader({
			base: 'src/content/vault',
			url: 'docs',
		}),
		schema: ({ image }) => ObsidianDocumentSchema.extend({
      image: image().optional(),
      // or
      cover: image().optional(),
      myCustomProperty: z.string().optional(),
    }),
	}),
};

πŸ› οΈ Configuration Options

OptionTypeDescription
patternstringGlob pattern to match files. Defaults to **/*.md
assetsPatternstringGlob pattern to match assets. Defaults to **/*.{svg,png,jpg,jpeg,avif,webp,gif,tiff,ico}
basestringBase directory to resolve the glob pattern from. Relative to the root directory, or an absolute file URL. Defaults to .
urlstringBase URL where this content should be served. Defaults to collection name. Used for autogenerated permalink
i18nbooleanEnables i18n routing
authorstringDefault author

πŸ™Œ Contributing

Contributions welcome! Feel free to open issues or PRs for bugs, features, or docs improvements.

πŸ“„ License

MIT License Β© aitorllj93


Built with β˜„οΈ Astro and 🧠 Obsidian