GithubHelp home page GithubHelp logo

Comments (12)

james2doyle avatar james2doyle commented on June 18, 2024

bump @NeoBlack

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

Yes, this is a problem or a bug. We can add a counter, if key exist, this way no page will be lost.

from phile.

james2doyle avatar james2doyle commented on June 18, 2024

That would be cool. Then the priority when there is a conflict would be ordered by filename right? since that is the default page order when first read from the directory?

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

result would be:

test
test_1
test_2

if three pages has the sorting value "test"

from phile.

james2doyle avatar james2doyle commented on June 18, 2024

Ok so for something like meta.date how would that work? You wouldn't want to augment the actual value of the meta property

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

maybe we have here an other problem. meta:date will be handled as any other meta information (parsed as string), but should be set automatic to the file modification date!?

from phile.

james2doyle avatar james2doyle commented on June 18, 2024

I dont think so. Because if you modify a file then it would jump to the "top" of the list. So updating articles that were published in the past would make it look like they were new.

Or are you saying that a conflicting attribute would then be resolved based on which file is newer? I still think that using the alphabetical filename to resolve conflicts might be easier. In this case:

puppies-are-fun.md
  • meta.title = Puppies Are Fun
  • meta.date = 2014/02/10
kittens-are-cute.md
  • meta.title = Kittens Are Cute
  • meta.date = 2014/02/10

In this case kittens would be at the top if ordered by date. Because K comes before P.

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

ok, right. no automatic detection. but 2014/02/10 would be 2014/01/10_1, 2014/01/10_2 etc. otherwise we should define a second sorting, eg:

$config['pages_order_by']='meta:date,meta:title'

if only one meta field is in config, a conflict will be solved by adding the counter.

from phile.

james2doyle avatar james2doyle commented on June 18, 2024

Frank I think I know what you are saying after looking at the code in the Phile\Repository. This would be a simple solution right now:

// semi pseudo code
if (isset($sorted_pages['_'.$page->getMeta()->get($metaKey)])) {
  $sorted_pages['_'.$page->getMeta()->get($metaKey).'_'.$counter] = $page;
} else {
  $sorted_pages['_'.$page->getMeta()->get($metaKey)] = $page;
}
$counter++;

In this case Frank is right, having 2 sorts would be nice because, personally, I would want to go by Title after the custom meta is done.

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

ok, here is my solution for sorting with counter if only one sorting key is defined:

$sorted_pages = array();
foreach ($pages as $page) {
    if ($page->getMeta()->get($metaKey) !== null) {
        $key = '_'.$page->getMeta()->get($metaKey);
        if (array_key_exists($key, $sorted_pages)) {
            $counter = 1;
            $tmp = $key;
            while (array_key_exists($tmp, $sorted_pages)) {
                $tmp = $key . '_' . $counter++;
            }
            $key = $tmp;
        }
        $sorted_pages[$key] = $page;
    } else {
        $sorted_pages[] = $page;
    }
}

if we have more then one sorting key defined, the sorting logic is a little bit more complex, but possible :)

from phile.

kursusHC avatar kursusHC commented on June 18, 2024

Thanks Franck I've just tested it and it works very well !

Indeed it would be awesome to have several meta for sorting : if the first one is not present the second one is selected. That would prevent things like ordering menu items with a quite irrelevant "date" value.

from phile.

NeoBlack avatar NeoBlack commented on June 18, 2024

We will fix this bug and close this issue. I open a new issue as feature request for sorting by multiple fields.

from phile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.