
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
astro-auto-title
Advanced tools
A Remark plugin for Astro that automatically adds an <h1> element to markdown using a variable from the frontmatter or vice versa, add the text of <h1> as a variable to frontmatter
Note: This plugin requires Astro version 2.0.0-beta.0 or above
<h1> heading using frontmatter variable<h1> to the frontmatter as a variablemdast and vfile<h1> per document by removing any extras<h1> headings to a lower depthUse this plugin when you have a CMS that enforces a variable in the frontmatter like title but you forget to add a # Heading in the markdown body. This can also be useful when using the getHeadings function from Astro because it can fail if there is no <h1> heading
There are also other useful options like:
mdast and vfile if document has nethier a # Heading or frontmatter variable<h1> to the frontmatter as a variable<h1> to a document by removing extras or shifting their depth downwardsSetup Config:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { autoTitle } from 'astro-auto-title';
export default defineConfig({
markdown: {
remarkPlugins: [
[autoTitle, {
frontmatterToH1: 'title',
h1ToFrontmatter: 'title',
}]
]
}
});
These 3 Markdown Files:
// 1
---
title: H1 Heading
---
This is a description
// 2
# H1 Heading
This is a description
// 3
---
title: I dont override existing h1
---
# H1 Heading
This is a description
Are rendered into this HTML:
<h1>H1 Heading</h1>
<p>This is a description</p>
{
frontmatterToH1: 'title',
h1ToFrontmatter: 'title',
defaultText: (mdast, vfile) => (
// Tries to return a string similar to Astro.url.pathname
// assumes your .md is located in src/pages
vfile.history
.pop()
?.replace(vfile.cwd, '')
.replace(/(\/\/)|(\\)+/g, '/')
.replace('/src/pages','')
.replace('/index.md', '')
.replace('.md', '')
),
override: false,
trimExtraH1: true,
shiftExtraH1: false
}
frontmatterToH1?: string|falseDefault: title
If no <h1> is found in document inject one with the text of this frontmatter variable
If false is passed it uses the text defined in default
Example:
{
frontmatterToH1: 'title'
}
---
title: H1 Heading
---
This is a description
<h1>H1 Heading</h1>
<p>This is a description</p>
h1ToFrontmatter?: string|falseDefault: title
This variable is added to frontmatter containing the first <h1> element's text
If false is passed no variable is added to frontmatter
Example:
{
h1ToFrontmatter: 'title'
}
# Heading defined in file
This is a description
frontmatter = {
title: 'Heading defined in file'
}
defaultText?: string | (MDAST, VFile) => stringDefault
(mdast, vfile) => (
// Tries to return a string similar to Astro.url.pathname
// assumes your .md is located in src/pages
vfile.history
.pop()
?.replace(vfile.cwd, '')
.replace(/(\/\/)|(\\)+/g, '/')
.replace('/src/pages','')
.replace('/index.md', '')
.replace('.md', '')
)
Can be a static string or a function that calculates a default string using the documents mdast tree and vfile
override?: booleanDefault: false
Option to override frontmatter variable if one is already defined in file
trimExtraH1?: booleanDefault: true
Enforces only one <h1> per document, keeps the first <h1> and removes all extras
Example:
# First h1
# Second h1
# Third h1
<h1>First h1</h1>
shiftExtraH1?: 2-6|booleanDefault: false
Note:
trimExtraH1must be set tofalseto use
Enforces only one <h1> per document by keeping the first <h1> and shifting all extra <h1> elements downwards to defined depth
Passing true shifts extra <h1> elements to <h2>
Passing false stops shifting from happening
Example:
{
trimExtraH1: false,
shiftExtraH1: 3
}
# First h1
# Second h1
# Third h1
<h1>First h1</h1>
<h3>Second h1</h3>
<h3>Third h1</h3>
FAQs
Automatically adds title frontmatter as an h1 heading, or vice versa
We found that astro-auto-title demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.