Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date sorting of articles on Index Page #66

Open
jlank opened this issue Dec 22, 2010 · 5 comments
Open

Date sorting of articles on Index Page #66

jlank opened this issue Dec 22, 2010 · 5 comments

Comments

@jlank
Copy link

jlank commented Dec 22, 2010

The issue I am experiencing is this: I created two posts on the same date, the first with a lowercase title, the second with an uppercase title. The index page displays the first post above the second one, giving the impression that the first post was posted after the second one. I believe it is due to the fact that the index is sorted by date, then by slug. Since the page is sorting on the ASCII value of the slug, lowercase letters have a higher value than upper case values. I am going to fork toto and try to come up with a more accurate sorting algorithm for the index page, it might take a few ticks, I'm new to Ruby :]

JLank

@micahwalter
Copy link

i am having the same issue... any progress on this one yet?

@ixti
Copy link

ixti commented Aug 9, 2011

Toto sort articles by their basenames:

    def self.articles ext
      Dir["#{Paths[:articles]}/*.#{ext}"].sort_by {|entry| File.basename(entry) }
    end

That means that you can override it in your config.ru to meet your needs, for example:

module Toto
  class Site
    def self.articles ext
      Dir["#{Paths[:articles]}/*.#{ext}"].sort_by {|entry| File.ctime(entry) }
    end
  end
end

@danielpcox
Copy link

I don't think Git preserves the ctime of files, so when I deploy to heroku everything is all out of order with this script. I think a true fix would have to include the time as well as the date in the front matter.

@ixti
Copy link

ixti commented Sep 17, 2011

Hmm. Yes, git does not preserve ctime.
Well. For me it doesn't make any sense to create more than one post per day (I can't allow myself write more than once per week :)). But obviously there are many of those who can.

@danielpcox your solution is the most obvious, I guess.

Another option (or probably additional) is to proide a "sorting" block, so it would be possible to "override" default sorting policy (not sure is it needed or not).

After all. Initial issue still can be solved without lots of modifictions :)) It's possible to put a special marker in the metadata:

ts: 1316279620

And then while showing posts list you can sort articles like this:

@articles.sort{ |a,b| (a.ts.nil? ? 1 : a.ts.to_i) <=> (b.ts.nil? ? 1 : b.ts.to_i) }

Anyway, I like the ide about having time somehow. But (!) I believe it should not affect filenames. So for example I cn understand time in place of metadata nd then sort using that metadata, but not in the filenames. I believe that filename 2011-09-17-foo-bar.txt looks more easier to read than 2011-09-17-19-17-foo-bar.txt

@ixti
Copy link

ixti commented Sep 17, 2011

I'm not really interested in this feature (at least on the current codebase of toto - I believe we need to cleanup the core). But I have prepared possible solution as a separate branch. It has been tested, so I would like to get some responses (at least before I will merge it into my master).

@micahwalter, @danielpcox your comments are very appreciated.
@cloudhead, your review of pull request is very-very appreciated (as you know your child better thn me - so probably you'll suggest more elegant solution ;))

Pull request: #101
Branch: https://github.com/ixti/toto/tree/issue-66

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

No branches or pull requests

4 participants