examples: add example plugins

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9eac30c7d4c1c89178f4930b215e523d6a6a6964
This commit is contained in:
raf 2026-02-03 22:29:19 +03:00
commit 708f8a0b67
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
5 changed files with 945 additions and 0 deletions

View file

@ -0,0 +1,103 @@
# Markdown Metadata Extractor Plugin
This example plugin demonstrates how to create a metadata extractor plugin for Pinakes.
## Overview
The Markdown Metadata Extractor enhances Pinakes' built-in markdown support by:
- Parsing YAML and TOML frontmatter
- Extracting metadata from frontmatter fields
- Converting frontmatter tags to Pinakes media tags
- Extracting custom fields from frontmatter
## Features
- **Frontmatter Parsing**: Supports both YAML (`---`) and TOML (`+++`) frontmatter formats
- **Tag Extraction**: Automatically extracts tags from frontmatter and applies them to media items
- **Custom Fields**: Preserves all frontmatter fields as custom metadata
- **Configuration**: Configurable via `plugin.toml` config section
## Frontmatter Example
```markdown
---
title: "My Document"
author: "John Doe"
date: "2024-01-15"
tags: ["documentation", "example", "markdown"]
category: "tutorials"
draft: false
---
# My Document
Content goes here...
```
## Implementation
The plugin implements the `MetadataExtractor` trait from `pinakes-plugin-api`:
```rust
#[async_trait]
impl MetadataExtractor for MarkdownMetadataPlugin {
async fn extract_metadata(&self, path: &PathBuf) -> PluginResult<ExtractedMetadata> {
// 1. Read the file
// 2. Parse frontmatter
// 3. Extract metadata fields
// 4. Return ExtractedMetadata
}
fn supported_types(&self) -> Vec<String> {
vec!["markdown".to_string()]
}
}
```
## Building
The plugin is compiled to WebAssembly:
```bash
cargo build --target wasm32-wasi --release
wasm-strip target/wasm32-wasi/release/markdown_metadata.wasm
cp target/wasm32-wasi/release/markdown_metadata.wasm .
```
## Installation
```bash
# Copy plugin directory to Pinakes plugins directory
cp -r examples/plugins/markdown-metadata ~/.config/pinakes/plugins/
# Or via API
curl -X POST http://localhost:3000/api/v1/plugins/install \
-H "Content-Type: application/json" \
-d '{"source": "/path/to/markdown-metadata"}'
```
## Configuration
The plugin can be configured through the `config` section in `plugin.toml`:
- `extract_tags`: Extract tags from frontmatter (default: true)
- `parse_yaml`: Parse YAML frontmatter (default: true)
- `parse_toml`: Parse TOML frontmatter (default: true)
- `max_file_size`: Maximum file size to process in bytes (default: 10MB)
## Security
This plugin has minimal capabilities:
- **Filesystem**: No write access, read access only to files being processed
- **Network**: Disabled
- **Environment**: No access
## Testing
```bash
cargo test
```
## License
MIT

View file

@ -19,3 +19,33 @@ wasm = "markdown_metadata.wasm"
extract_tags = { type = "boolean", default = true, description = "Extract tags from YAML frontmatter" }
parse_yaml = { type = "boolean", default = true, description = "Parse YAML frontmatter" }
max_file_size = { type = "integer", default = 10485760, description = "Maximum file size in bytes (10MB)" }
[plugin]
name = "markdown-metadata"
version = "1.0.0"
api_version = "1.0"
author = "Pinakes Contributors"
description = "Enhanced Markdown metadata extractor with frontmatter parsing"
homepage = "https://github.com/notashelf/pinakes"
license = "MIT"
kind = ["metadata_extractor"]
[plugin.binary]
wasm = "markdown_metadata.wasm"
[capabilities]
network = false
[capabilities.filesystem]
read = []
write = []
# Plugin configuration
[config]
# Extract frontmatter tags as media tags
extract_tags = true
# Parse YAML frontmatter
parse_yaml = true
# Parse TOML frontmatter
parse_toml = true
# Maximum file size to process (in bytes)
max_file_size = 10485760 # 10MB