Skip to content

Allow configuring file extension (e.g. .md) for files generated by perron:sync_sources #174

@m-lague

Description

@m-lague

Summary

When using the programmatic content feature (perron:sync_sources), Perron always
generates files with a .erb extension. There is currently no way to specify that
the generated files should use a different extension, such as .md.

Current behavior

Given a resource class with source_template, running bin/rails perron:sync_sources
always produces .erb files:

app/content/posts/
  1.erb
  2.erb
  3.erb

Even when the template content is pure Markdown (front matter + body), the generated
file is .erb, which bypasses the Markdown parser and feels inconsistent with
manually-created .md resources.

Expected / desired behavior

It would be useful to configure the file extension at the resource level so that
generated files can be .md for Markdown-heavy content (blog posts, documentation
pages, editorial content, etc.).

A possible API could look like:

class Content::Post < Perron::Resource
  source :posts, format: :md

  def self.source_template(sources)
    post = sources.posts

    <<~TEMPLATE
      ---
      title: #{post.title}
      date: #{post.published_at}
      ---

      #{post.body}
    TEMPLATE
  end
end

Or alternatively via a dedicated class-level macro:

class Content::Post < Perron::Resource
  source :posts
  source_format :md
end

Context

  • Perron version: 0.18
  • Ruby version: 4.0.2
  • Rails version: 8.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions