Skip to content

feat: add shortcodes functionality#320

Merged
rochacbruno merged 22 commits intomainfrom
feat/shortcodes
Aug 1, 2025
Merged

feat: add shortcodes functionality#320
rochacbruno merged 22 commits intomainfrom
feat/shortcodes

Conversation

@rochacbruno
Copy link
Copy Markdown
Owner

Summary

  • Adds powerful shortcodes functionality to Marmite
  • Implements built-in shortcodes (toc, youtube, authors, streams)
  • Supports custom user shortcodes in HTML and Markdown formats

Test plan

  • Run cargo test - all tests pass
  • Run mask fmt - code formatted
  • Run mask check - no errors (2 warnings about too_many_arguments)
  • Run mask pedantic - addressed all fixable issues
  • Test with example site using new shortcodes
  • Add comprehensive documentation and demo posts
  • Verify --shortcodes CLI flag works correctly

- 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

This comment was marked as outdated.

@rochacbruno rochacbruno requested a review from Copilot August 1, 2025 20:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)]
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
pub site_data: Data,
}

#[allow(clippy::cast_possible_truncation)]
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cast truncation issue as in the Group function - the conversion from u64 to usize on line 267 should be handled more safely.

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +139
#[allow(clippy::unused_self)]
fn extract_description(&self, content: &str) -> Option<String> {
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#[allow(clippy::unused_self)]
fn extract_description(&self, content: &str) -> Option<String> {
fn extract_description(content: &str) -> Option<String> {

Copilot uses AI. Check for mistakes.
}

impl Function for GetDataBySlug {
#[allow(clippy::too_many_lines)]
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
let is_html = path
.extension()
.and_then(|s| s.to_str())
.is_some_and(|ext| ext == "html");
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_some_and method might not be available in older Rust versions. Consider using .map_or(false, |ext| ext == "html") for better compatibility.

Suggested change
.is_some_and(|ext| ext == "html");
.map_or(false, |ext| ext == "html");

Copilot uses AI. Check for mistakes.
@rochacbruno rochacbruno merged commit 786b222 into main Aug 1, 2025
3 checks passed
@rochacbruno rochacbruno deleted the feat/shortcodes branch August 16, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants