preaction / Statocles

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

correct sorting if there is more than one blog entry per day #512

Closed kbucheli closed 7 years ago

kbucheli commented 7 years ago

In my blog I have the problem that I have can have more than one blog entry per day and they should be in chronological order as it is a travel blog. Please do not cheat ;-)

preaction commented 7 years ago

Thanks for the patch! But, before I can merge, there are a couple issues:

There are two different dates in the blog: One is the date the post should be ordered in on all the post list pages, which is currently the date in the URL, the other is the date on the document. The URL date is what gets set when someone does statocles blog post --date XXXX-XX-XX. It doesn't set the document date at all. So, someone could set whatever value they wanted for the date attribute, including one far in the past or future. We can discuss the wisdom of that, but that'll probably take a while.

So, for now, to avoid unnecessary upgrade pain, the posts need to be sorted by their URL "date" first. The posts could then be additionally sorted by the date field inside the document to resolve conflicts, with the knowledge that changing the date field may change the ordering of the post list pages if there's more than one post on that day.

So this is part of the way there, but you will still need to sort by the date portion of the path. You can sort by multiple criteria in a single sort call with sort { $a->foo cmp $b->foo || $a->bar cmp $b->bar }.

Also, there needs to be a test for this. This change should've made the tests fail, which means there may be a bug in the tests. The t/app/blog/pages.t test tests all the blog pages using the data found in t/share/app/blog. The document t/share/app/blog/2014/04/30/plug/index.markdown has a date attribute of 2014-04-30 00:00:00 as expected, but t/share/app/blog/2014/04/23/slug/index.markdown has a date of 2014-04-30 06:50:35 which should make it come later in the list of posts. If you change your patch to sort by the path date and then the document date, the tests should pass as-is, but it's still something worth checking up on.

So, if you want to try writing a test for this, please do. If you have any questions or need any help, let me know. Otherwise I can write the test, but it might be a few weeks before I can get to it.

P.S.: We could also discuss other ways to solve this in the future, including allowing the user to control how new post paths are generated. So then you could add the hour to the post path, or do something wildly different like use /blog/2014-01-01T01-23/my-post-title instead of /blog/2014/01/01/my-post-title, or even just a single post number like /blog/1-my-first-post/ and /blog/2-my-second-post. This is a larger undertaking though, so we might want to just fix the issue you're having first.

kbucheli commented 7 years ago

For the wisdom of having "fake" dates is the user responsible not the tool :-). It should just do something useful with it. Is there an easy way to get the date from the path except for parsing it? Configurable path or even easy programmable path creating would be nice. Especially as german especial characters as umlauts can properly be asciified, but that is nothing I expect to work by default. And I would only need at max a monthly structure. Something similar I made once in a different project, but not in Perl :-(

preaction commented 7 years ago

It isn't so much about fake dates as it is that I was imagining the date field inside the document to be the last time the blog post was updated (if, for example, you need to edit it after an event is over or with further details or something), which now that I think of it is kind of a bad idea. If I want a last updated date, I should just add back the last_updated attribute. That will be less confusing than it is now, considering this PR.

But it still remains that the existing behavior is being relied upon (even though we're pre-1.0). So I think if we combine your change here, add back the path sorting, and then allow users to change how the paths are created, we can keep the current behavior mostly the same and allow for greater customization for blogs that need it. And then you can organize your blog by month, and inside that month it will be organized by the date field in the blog post.

preaction commented 7 years ago

I've combined your change with my change and produced https://github.com/preaction/Statocles/commit/404024eb085cde9670ce3082e8808cd2fcbc6b52. Is there any way you can test it before I do a release to see if it does what you expect? Otherwise I can release it and you can test it and report back.

kbucheli commented 7 years ago

Yes, the order is now correct. Thank you very much!

preaction commented 7 years ago

Thanks. I'll make a release right now (though the Pod::Weaver problems in #513 mean that tests might fail when you install).