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

Random list of pages #574

Open
f6cm opened this issue Oct 22, 2021 · 5 comments
Open

Random list of pages #574

f6cm opened this issue Oct 22, 2021 · 5 comments
Assignees

Comments

@f6cm
Copy link

@f6cm f6cm commented Oct 22, 2021

I’d like to be able able to view a random list of pages, from a source. Ideally, I would be something like:

´´´dataview
LIST
FROM #Quotes
SORT RANDOM
LIMIT 5
´´´

Which would output a list of 5 random quotes.
I don’t think it’s already possible. Or maybe via dataviewjs ?

Thanks for this amazing plugin and the wonderful job you’re doing!

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Oct 23, 2021

The tricky part about this is getting the right level of random - Dataview views internally refresh frequently, and during refreshes you probably don't want to see the list shuffle every time. Should random change every hour? Every day?

I'm planning on implementing this via a random(rowId, duration) function as well as a RANDOMIZE command.

@f6cm
Copy link
Author

@f6cm f6cm commented Oct 24, 2021

Good point!

What you suggested is certainly the best implementation, with a RANDOMIZE command and the ability to set a default cache duration.
I think it covers all the different needs people may have with this function.

Thanks!

@mediapathic
Copy link

@mediapathic mediapathic commented Feb 24, 2022

I came to request this feature, but instead am adding a +1! For a use case, I'm wanting to use this to create a "writing inbox" query that presents me with a random order of things I can work on to avoid getting stuck.

Thank you!

EDIT: In discussing this with @AB1908 on the discord, they cooked up this dataviewjs query that works as a workaround for now. It seems to refresh in legacy editor when switching to reading view, but neither of us can figure out how to force a refresh in Live Preview in a sane way.

function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

var results = dv.pages("#writinginbox or #to/expand")
                    .sort(page => page.file.mtime, "desc");
shuffleArray(results);
dv.table(
  ["File Size", "File"],
  results
    .map(page => [page.file.size, page.file.link])
);

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Feb 24, 2022

You can force refreshes via dv.index.touch(), for what it's worth. If you also want something that only changes on a specific cadence (every hour, every day), you can use a fixed random seed.

@Jahteo
Copy link

@Jahteo Jahteo commented Mar 2, 2022

Just wanted to add that came to add a FR & instead I'm impressed this is already on the docket with even better feature details planned. @blacksmithgu, you're fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants