slidev-addon-audience-filter
v1.0.2
Published
Filter slides based on audience using showFor/hideFor frontmatter
Readme
slidev-addon-audience-filter
A Slidev addon that filters slides based on the target audience. Use showFor and hideFor frontmatter properties to control which slides are visible for which audience.
Features
- Audience-based filtering: Show or hide slides based on the active audience
- Flexible configuration: Set audience via environment variable or headmatter
- Bypass mode: Disable filtering for IDE editing with
AUDIENCE=bypass - Comma-separated or array syntax: Supports both formats for audience lists
Installation
npm install slidev-addon-audience-filterUsage
1. Wire up the preparser in your project
Important: Slidev applies the preparser from the project root on the initial load only. Addon preparsers are resolved too late to filter the first render, so the entry point must live in your project. Create
setup/preparser.tsin your Slidev project:
import {createAudienceFilterPreparser} from 'slidev-addon-audience-filter'
export default createAudienceFilterPreparser()After creating or changing setup/preparser.ts, fully stop and restart the dev
server (a hot reload is not enough for preparser changes).
You do not need to add this package to the addons: list — the
setup/preparser.ts stub above is what activates the filter.
2. Set the active audience
Option A: Environment variable (recommended for CLI)
AUDIENCE=live slidevOption B: Headmatter in slides.md
---
audience: live
---3. Mark slides with showFor or hideFor
---
showFor: live
---
# This slide is only visible for the "live" audience
---
hideFor: beginners
---
# This slide is hidden from "beginners" but visible to everyone else
---
showFor: architects,leads
---
# This slide is visible for "architects" and "leads"How It Works
- The addon reads the active audience from the
AUDIENCEenvironment variable or theaudienceheadmatter field - For each slide, it checks the
showForandhideForfrontmatter properties - If a slide has
hideForand the active audience matches, the slide is disabled - If a slide has
showForand the active audience does NOT match, the slide is disabled - Slides without
showFororhideForare always visible
Priority
AUDIENCEenvironment variable (highest priority)audienceheadmatter field- No audience set = no filtering (all slides visible)
Bypass Mode
Set AUDIENCE=bypass to disable all filtering. This is useful when editing slides in an IDE:
AUDIENCE=bypass slidevAudience List Syntax
Both comma-separated strings and arrays are supported:
# Comma-separated
showFor: architects,leads
# Array
showFor:
- architects
- leadsValues are case-insensitive and trimmed automatically.
License
MIT
Author
Denis Sowa
Contributing
Contributions are welcome! Please open an issue or pull request on GitHub.
