
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-remark-description
Advanced tools
Remark plugin for Astro to automatically add description text to the frontmatter of markdown files
astro-remark-descriptionAutomatically add a description to the frontmatter of your markdown in Astro
1) Install using the command npm i astro-remark-description
2) Add plugin to astro.config.mjs
import { defineConfig } from 'astro/config';
import remarkDescription from 'astro-remark-description'
export default defineConfig({
markdown: {
remarkPlugins: [
[remarkDescription, {}]
]
}
});
nameType: string
Default: 'description'
Name of key inside frontmatter
htmlType: boolean
Default: false
Render node to a string of HTML
overrideType: boolean
Default: false
true: if frontmatter property already exists, replace it
false: if frontmatter property already exists, skip file
skipType: number
Default: 0
Number of nodes to skip before grabbing text
For example, if the first pragraph contains an image, use { skip: 1 } to get the text of the next paragraph
nodeType: unist-util-is test
Tag name tests: "blockquote" | "break" | "code" | "definition" | "delete" | "emphasis" | "footnoteDefinition" | "footnoteReference" | "heading" | "html" | "image" | "imageReference" | "inlineCode" | "link" | "linkReference" | "list" | "listItem" | "paragraph" | "strong" | "table" | "tableCell" | "tableRow" | "text" | "thematicBreak" | "yaml" | "root"
Default: 'paragraph'
A test for finding nodes when looping over markdown to get text
parentType: 'paragraph' | 'root' | 'blockquote' | 'delete' | 'emphasis' | 'footnoteDefinition' | 'heading' | 'link' | 'linkReference' | 'list' | 'listItem' | 'strong' | 'table' | 'tableCell' | 'tableRow'
Default: 'root'
Type of the parent node
For exmaple, if the text for your description is inside a list, the parent must be 'listItem'
transformFunction to transfrom the description text before it is added to the frontmatter
Type:
type transform = (
description: string,
data: {
path: string,
cwd: string,
frontmatter: Record<string, any> | undefined
node: Node
}
) => any
Example 1:
Only use the first sentence of description text
{
transform: (desc) => desc.split('.')[0] + '.'
}
Example 2:
Capitalize all description text
{
transform: (desc) => desc.toUpperCase()
}
filterA function to control the plugin options of each file
Type:
type filter = (
options: Options,
data: {
path: string,
cwd: string,
frontmatter: Record<string, any> | undefined
}
) => Options | false | null | undefined | void
Example 1:
Skip over any files that have scrape: false in the frontmatter or are located inside the "projects" collection
{
filter: (options, { path, frontmatter }) => {
if (!frontmatter.scrape || path.startsWith('/src/content/projects'))
return false // Return falsey value to skip
return options
}
}
Example 2:
Apply an edge case to a specific file
{
filter: (options, { path }) => {
if (path == '/src/content/blog/post-3.md')
options.skip = 2 // skip first 2 paragraphs
return options
}
}
import { defineConfig } from 'astro/config';
import remarkDescription from 'astro-remark-description'
export default defineConfig({
markdown: {
remarkPlugins: [
[remarkDescription, { name: 'excerpt' }]
]
}
});
import { defineConfig } from 'astro/config';
import remarkDescription from 'astro-remark-description'
export default defineConfig({
markdown: {
remarkPlugins: [
[remarkDescription, {
name: 'excerpt',
override: true,
// Uppercase first letter in description
transform: (desc) => desc[0].toUpperCase() + desc.slice(1)letter,
filter: (options, { path }) => {
// Skip file if not inside a collection
if (!path.startsWith('/src/content'))
return false
// Use heading for description in 'projects' collection
if (!path.startsWith('/src/content/projects'))
options.node = 'heading'
// Edge case: first paragraph is an image, use the second
if (path === '/src/content/blog/post-3.md')
options.skip = 1
return options
},
}]
]
}
});
remarkDirective to target a nodeimport { defineConfig } from 'astro/config';
import remarkDescription from 'astro-remark-description'
import remarkDirective from 'remark-directive'
export default defineConfig({
markdown: {
remarkPlugins: [
remarkDirective,
[remarkDescription, {
node: node => node.type === 'containerDirective' && node.name === 'description'
}]
]
}
});
# Heading
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sed.
:::description
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sed.
:::
import { defineConfig } from 'astro/config';
import remarkDescription from 'astro-remark-description'
export default defineConfig({
markdown: {
remarkPlugins: [
[remarkDescription, {
name: 'excerpt',
node: (node, i, parent) => {
const sibling = parent?.children[i + 1]
return sibling?.type === 'html' && sibling?.value === '<!-- more -->'
}
}]
]
}
});
# Heading
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sed.
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sed.
<!-- more -->
FAQs
Remark plugin for Astro to automatically add description text to the frontmatter of markdown files
We found that astro-remark-description 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.