Conversation
- Add ShortcodeProcessor to handle HTML and Markdown shortcodes - Built-in shortcodes: toc, youtube, authors, streams - Support for custom user shortcodes in shortcodes/ directory - Add --shortcodes CLI flag to list available shortcodes - Enable shortcodes configuration in marmite.yaml - Add comprehensive documentation and demo posts - Update maskfile with shortcode examples
42bd4e7 to
ce2efa7
Compare
clippy hell
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive shortcodes functionality to Marmite, allowing users to insert reusable content blocks into their markdown files using HTML comment syntax. The implementation includes 11 built-in shortcodes (toc, youtube, authors, streams, series, posts, pages, tags, socials, spotify, card) and supports custom user shortcodes in both HTML and Markdown formats.
Key changes include:
- New shortcode processing system with regex pattern matching and Tera macro integration
- Enhanced Tera functions for data retrieval and content grouping with sorting/limiting capabilities
- CLI command to list available shortcodes with descriptions
- Configuration options to enable/disable shortcodes and customize patterns
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/shortcodes.rs | Core shortcode processing engine with pattern matching, HTML/Markdown rendering, and built-in shortcode definitions |
| src/tera_functions.rs | Enhanced Tera functions with new GetPosts and GetDataBySlug functions, plus improved Group function with sorting/limiting |
| src/site.rs | Integration of shortcode processor into template rendering pipeline with conditional processing |
| src/main.rs | Added --shortcodes CLI flag to list available shortcodes |
| src/embedded.rs | Embedded shortcode files from example directory |
| src/config.rs | Configuration options for enabling shortcodes and custom patterns |
| src/cli.rs | CLI argument for shortcodes listing |
| example/shortcodes/* | Built-in shortcode templates demonstrating various content types and integrations |
| example/content/* | Demo posts showcasing shortcode usage and documentation |
Comments suppressed due to low confidence (1)
src/shortcodes.rs:25
- The default regex pattern is complex and could benefit from being defined as a module constant with documentation explaining its structure.
let default_pattern = r"<!-- \.(\w+)(\s+[^>]+)?\s*-->";
| pub site_data: Data, | ||
| } | ||
|
|
||
| #[allow(clippy::cast_possible_truncation)] |
There was a problem hiding this comment.
The cast truncation warning is being suppressed, but the conversion from u64 to usize on line 106 could potentially lose data on 32-bit systems. Consider adding a runtime check or using TryInto for safer conversion.
| pub site_data: Data, | ||
| } | ||
|
|
||
| #[allow(clippy::cast_possible_truncation)] |
There was a problem hiding this comment.
Same cast truncation issue as in the Group function - the conversion from u64 to usize on line 267 should be handled more safely.
| #[allow(clippy::unused_self)] | ||
| fn extract_description(&self, content: &str) -> Option<String> { |
There was a problem hiding this comment.
The extract_description method is marked as unused_self but could be made into a static function since it doesn't use any instance data.
| #[allow(clippy::unused_self)] | |
| fn extract_description(&self, content: &str) -> Option<String> { | |
| fn extract_description(content: &str) -> Option<String> { |
| } | ||
|
|
||
| impl Function for GetDataBySlug { | ||
| #[allow(clippy::too_many_lines)] |
There was a problem hiding this comment.
The GetDataBySlug::call method is very long and handles multiple content types with similar logic. Consider extracting helper methods for each content type to improve readability and maintainability.
| let is_html = path | ||
| .extension() | ||
| .and_then(|s| s.to_str()) | ||
| .is_some_and(|ext| ext == "html"); |
There was a problem hiding this comment.
The is_some_and method might not be available in older Rust versions. Consider using .map_or(false, |ext| ext == "html") for better compatibility.
| .is_some_and(|ext| ext == "html"); | |
| .map_or(false, |ext| ext == "html"); |
Summary
Test plan
cargo test- all tests passmask fmt- code formattedmask check- no errors (2 warnings about too_many_arguments)mask pedantic- addressed all fixable issues--shortcodesCLI flag works correctly