preaction / Statocles

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

Array of hashes scrambled #537

Closed neilhwatson closed 7 years ago

neilhwatson commented 7 years ago

Consider this code:

<%
my @images = (
    {
     src => '/images/winter/winter-view.jpg',
     caption => 'Lake ice in the winter',
    },
    {
     src => '/images/winter/snowy-owl.jpg',
     caption => 'Winter birds include Snowy Owls',
    },
);

for my $i ( @images ){
    say "href=$i->{src} data-caption=$i->{caption}";

%>
    <a href="<%= $i->{src} %>" data-caption="<%= $i->{caption} %>"></a>
% }

The output from the say command on the console is:

href=/images/winter/winter-view.jpg data-caption=Lake ice in the winter
href=/images/winter/snowy-owl.jpg data-caption=Winter birds include Snowy Owls

This is expected, but the html source produced in the static files is this:

<a data-caption="Lake ice in the winter" href="/images/winter/winter-view.jpg"></a>
<a data-caption="Winter birds include Snowy Owls" href="/images/winter/snowy-owl.jpg"></a>

Caption and href are reversed.

preaction commented 7 years ago

The HTML is run through parsers multiple times, and then edited as a data structure, and then written back out. I believe that all those times are mostly due to plugins, but one time is especially due to URL rewriting. Is it important that the result be exactly equivalent to the input? If so, I can try to find some ways to make that achievable (by not processing things unnecessarily, for example, and listing which plugins will parse/rewrite your markup).

neilhwatson commented 7 years ago

Good point. The html gets read by some java script that builds gallery page. I think that makes this a bug in there instead of here.

preaction commented 7 years ago

Yeah... I'd be very concerned about that JavaScript, since JS has direct access to an already-parsed DOM tree... The other problem is that I think there's actually no way to avoid at least one parsing/rerendering step, even if the base URL of your site is /... That might be a performance improvement to think about down the line...

But if the JS can't do an image gallery that well, you could write a Statocles app that did it instead ;)

But, since it seems like this isn't (yet) a problem in Statocles, I'll close this for now.