Skip to content

Add project shortcode templates#84

Open
samdark wants to merge 1 commit into
masterfrom
add-project-shortcodes
Open

Add project shortcode templates#84
samdark wants to merge 1 commit into
masterfrom
add-project-shortcodes

Conversation

@samdark

@samdark samdark commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

  • add project-level shortcode templates from content/shortcodes/*.php for binary users
  • support inline and block Hugo-style shortcode syntax before Markdown rendering in pages and feeds
  • document template variables, update the roadmap, and add tests plus a benchmark

Tests

  • make test -- --filter ProjectShortcodeProcessorTest
  • make psalm
  • make test
  • BENCH_FILTER=ProjectShortcodeProcessorBench make bench

Summary by CodeRabbit

  • New Features

    • Added support for project-level shortcodes with Hugo-style syntax ({{< name ... >}}), enabling users to define custom shortcodes in content/shortcodes/ without modifying configuration.
  • Documentation

    • Added comprehensive guide covering shortcode syntax, template creation, and usage examples.
  • Tests

    • Added test coverage and performance benchmarks for shortcode expansion functionality.

Copilot AI review requested due to automatic review settings June 13, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces project-level shortcode support for static binary users. A new ProjectShortcodeProcessor expands Hugo-style shortcodes from content/shortcodes/ templates before markdown processing, with directory discovery via parent traversal and template rendering via output buffering. The processor is wired into content and feed pipelines, covered by unit tests and performance benchmarks, and documented for users.

Changes

Project Shortcodes Feature

Layer / File(s) Summary
ProjectShortcodeProcessor implementation
src/Processor/Shortcode/ProjectShortcodeProcessor.php
Processor expands Hugo-style shortcodes ({{< name ... >}}...{{< /name >}} and {{< name ... /}}) by detecting markers, discovering shortcode template directories through parent traversal until finding shortcodes/ or hitting config.yaml, matching shortcode names via regex, resolving .php template files, and rendering them with output buffering while passing attributes, inner content, and entry context.
Pipeline integration
config/common/di/content-pipeline.php
ProjectShortcodeProcessor is registered in both content and feed processor pipelines via DI configuration as a constructor-injected reference alongside existing shortcode processors.
Unit tests
tests/Unit/Processor/ProjectShortcodeProcessorTest.php
Four test cases verify inline shortcodes with return values, block shortcodes with inner content, echo-based output capture, and unknown shortcode passthrough; uses temporary filesystem fixtures and Entry helper.
Performance benchmarks
benchmarks/ProjectShortcodeProcessorBench.php
PhpBench benchmark measures processor performance with 100 shortcode invocations, 100 revisions, 3 iterations, and 1 warmup; includes fixture setup and recursive directory cleanup.
Documentation and roadmap
docs/plugins.md, roadmap.md
User documentation explains Hugo-style syntax, content/shortcodes/ directory structure, template variables, output modes (return or echo, Markdown or HTML), and unknown shortcode handling; roadmap marks feature complete.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A shortcode hops into the fold,
Hugo-style templates to hold,
Directory walks, output buffered bright,
Tested and benchmarked—all feels right!
Static sites gain dynamic flair,
With rabbit-approved shortcodes to share. 🎀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add project shortcode templates' accurately captures the main feature being introduced—a new shortcode processor that enables project-level shortcode templates loaded from content/shortcodes/ for binary users.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-project-shortcodes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/Processor/Shortcode/ProjectShortcodeProcessor.php (1)

120-120: ⚡ Quick win

Consider documenting the === 1 return value convention.

Line 120's logic $result === 1 ? $output : $output . (string) $result relies on a subtle PHP behavior: when a require statement has no explicit return, it returns 1. This allows templates to use either echo (captured via output buffering) or return (appended to output), but the exact-equality check against 1 is not self-documenting.

Consider adding an inline comment explaining this convention, or documenting it in the class-level docblock.

📝 Suggested inline comment
-        return $result === 1 ? $output : $output . (string) $result;
+        // require returns 1 when template has no explicit return; use only buffered output in that case
+        return $result === 1 ? $output : $output . (string) $result;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Processor/Shortcode/ProjectShortcodeProcessor.php` at line 120, The
ternary in ProjectShortcodeProcessor method returning "$result === 1 ? $output :
$output . (string) $result" relies on PHP's require returning 1 when no explicit
return is used; add a short inline comment at that line explaining that
"require" with no return yields int(1) so the code distinguishes between echoed
output (buffered) and returned string, and also update the class-level docblock
of ProjectShortcodeProcessor to document this convention for template authors
(mentioning that templates may either echo or return content and that a raw
integer 1 means "no return").
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/Processor/Shortcode/ProjectShortcodeProcessor.php`:
- Line 120: The ternary in ProjectShortcodeProcessor method returning "$result
=== 1 ? $output : $output . (string) $result" relies on PHP's require returning
1 when no explicit return is used; add a short inline comment at that line
explaining that "require" with no return yields int(1) so the code distinguishes
between echoed output (buffered) and returned string, and also update the
class-level docblock of ProjectShortcodeProcessor to document this convention
for template authors (mentioning that templates may either echo or return
content and that a raw integer 1 means "no return").

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46f5aa16-1f28-4ca6-a28d-ee50f762ced6

📥 Commits

Reviewing files that changed from the base of the PR and between 315ad8d and dbd0a66.

📒 Files selected for processing (6)
  • benchmarks/ProjectShortcodeProcessorBench.php
  • config/common/di/content-pipeline.php
  • docs/plugins.md
  • roadmap.md
  • src/Processor/Shortcode/ProjectShortcodeProcessor.php
  • tests/Unit/Processor/ProjectShortcodeProcessorTest.php

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