🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

astro-default-frontmatter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-default-frontmatter

A few plugins for defining default frontmatter for your markdown in Astro

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
5
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Astro Default Frontmatter

This is a simple collection of remark plugins for Astro that allows you to define a default frontmatter for you markdown files

Plugins:

If you want to see how these plugins work you can check out the Stackblitz Demo

defaultLayout

Option/Argument Type: string

Define a default layout for ALL markdown in your project

Example

//astro.config.mjs
import { defineConfig } from 'astro/config';
import { defaultLayout } from 'astro-default-frontmatter';

export default defineConfig({
  markdown: {
    remarkPlugins: [
      [defaultLayout, "~/layouts/DefaultLayout.astro"]
    ]
  }
});

defaultFrontmatter

Option/Argument Type: Record<string, any>

Define a default frontmatter for ALL markdown in your project

Example

//astro.config.mjs
import { defineConfig } from 'astro/config';
import { defaultFrontmatter } from 'astro-default-frontmatter';

export default defineConfig({
  markdown: {
    remarkPlugins: [
      [defaultFrontmatter, {
        layout: "~/layouts/DefaultLayout.astro",
        title: 'Default Title'
      }]
    ]
  }
});

defaultFrontmatterAdvanced

Option/Argument Type:

Array<{
  dirs: string[];
  frontmatter: Record<string, unknown>;
  replace?: boolean;
}>

Define a default frontmatter based on what directory the file is in

Options should be in order from less specific dirs --> more specific dirs to stop frontmatters from overlapping './' -> './src' -> './src/content' -> './src/content/1.md'

dirs

Type: Array<string>

A list of directories that frontmatter will be applied to

frontmatter

Type: Record<string, any>

Frontmatter object that will be applied to all directories in dirs

replace

Type: boolean

Replace the frontmatter entirely instead of spreading new values ontop of old values

Examples

Stackblitz Demo

Or

//astro.config.mjs
import { defineConfig } from 'astro/config';
import { defaultFrontmatterAdvanced } from 'astro-default-frontmatter';

const Options = [
  {
    dirs: ['./'],
    frontmatter: { layout: "~/layouts/DefaultLayout.astro" },
  },
  {
    dirs: ['./src/content'],
    frontmatter: { layout: "~/layouts/DirectoryLayout.astro" },
  },
  {
    dirs: ['./src/content/2.md'],
    frontmatter: { layout: "~/layouts/FileLayout.astro"  }
  },
  {
    dirs: ['./src/content/5.md'],
    frontmatter: {},
    replace: true
  }
]

export default defineConfig({
  markdown: {
    remarkPlugins: [
      [defaultFrontmatterAdvanced, Options]
    ],
  },
});

Output:

1.md -> {
    "layout": "../layouts/FrontmatterLayout.astro",
    "title": "Title From File"
}
2.md -> {
    "layout": "../layouts/FileLayout.astro"
}
3.md -> {
    "layout": "../layouts/DirectoryLayout.astro"
}
4.md -> {
    "layout": "../layouts/DirectoryLayout.astro"
}
5.md -> {}

Keywords

astro

FAQs

Package last updated on 21 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts