preaction / Statocles

Static website CMS
http://preaction.me/statocles
Other
84 stars 33 forks source link

Missing argument in sprintf from data in md file #538

Closed neilhwatson closed 7 years ago

neilhwatson commented 7 years ago

Consider this template:

---
title: Winter at The Waves
images:
  gallery:
    - src:     /images/winter/winter-view.jpg
      caption: Lake ice in the winter
    - src:     /images/winter/snowy-owl.jpg
      caption: Winter birds include Snowy Owls
---

Results in:

Missing argument in sprintf at /home/neil/perl5/lib/perl5/Statocles/Store.pm line 185.
Error creating document in "coercion for "images" failed: Not a HASH reference at /home/neil/perl5/lib/perl5/Statocles/Document.pm line 234.
": 
preaction commented 7 years ago

Ah! You fell into my trap! https://github.com/preaction/Statocles/issues/436

TL;DR: The "images" key is not like the "links" key, it does not yet allow an array of images. That could be fixed by making it work more like the links key (so, copy/pasting behaviors over).

neilhwatson commented 7 years ago

I think I only need a generic way to declare data in markdown and process it in a template.

neilhwatson commented 7 years ago

Actually using data: works.

---
title: Winter at The Waves
template: gallery/index.html
data:
  gallery:
    - src:     /static/images/winter/winter-view.jpg
      caption: Lake ice in the winter
    - src:     /static/images/winter/snowy-owl.jpg
      caption: Winter birds include Snowy Owls
---

% for my $i ( @{ $page->data->{gallery} } ){
   <img src="<%= $i->{src} %>" data-caption="<%= $i->{caption} %>" >
% }
preaction commented 7 years ago

Yes, that's what data is best used for. The images and links keys are mostly for theme authors to add ways to customize things that aren't in the main content below (like, a "title" image that could be shown on the blog list page, or metadata images that show up on twitter and facebook #504 ).

So, should we close this one in favor of #436?