How to update config option ":default-home" from javascript?

I had a powershell script in a Windows Scheduled Task that would replace each day the journal name with the current day, in the preferred format.

I am trying to rely less and less on external shell for whatever customization I need in Logseq.

I was wondering what is the internal representation of :default-home {:page ""} and if, instead of replacing a string in the file we could just modify, with javascript, the variable Logseq is reading that config.edn into.

Try logseq.api.set_current_graph_configs({"default-home": {"page": ""}})

is there a way to get the “today’s journal” page name from the API? As it depends on the date preferences, it wouldn’t be wise to hard code it in a specific date format…

No, the API covers only generic requirements. The rest should be coded in javascript.

If you’re trying to make it so your home page is always the journal page for today, you could make a sneaky redirection page with this content and set that as your default home page:

- #+BEGIN_QUERY
  {:inputs [:today]
   :query
   [:find (pull ?p [:block/name])
    :in $ ?t
    :where
    [?p :block/journal? true]
    [?p :block/journal-day ?t]]
   :view (fn [[p]] (call-api "push_state" :page {:name (:block/name p)}))}
  #+END_QUERY

It’ll query for the page with today’s date, then when it goes to render it, instead trigger a redirection.

2 Likes

This is interesting and worth trying for sure…

@mentaloid, this works nicely but I either need to set an internal variable that holds this information (and not write it in config.edn ) or have a way to tell Logseq on exit to reset the value of the page to “” because it actually writes the today’s date in config.edn with the above api call but it remains the same for tomorrow when I open Logseq.

So i need to reset it back to nothing so Logseq would fire up Journals upon startup and I am relying on that to setup the :default-home page.

I tried several ways to include, in custom.js, but I get nothing for app.on('before-quit', (event) => {

Thanks.

What if you read instead the name with a query, like @iant did?

const query = `[
 :find ?name
 :in $ ?t
 :where
   [?p :block/journal-day ?t]
   [?p :block/name ?name]
]`

const todayJournalName = logseq.api.datascript_query(query, ":today")[0][0]

Ok, i didn’t know how to run a query from javascript, this is excelent, thanks.

Can also run javascript from a query, but not from its :where part.

ok, now I can use:

logseq.api.set_current_graph_configs({"default-home": {"page": todayJournalPage}});

but how can I use javascript to push state or perform some refresh? Because ritght after loading, pressing G H is not doing anything and the current loaded page is Journals. If I do any sort of navigation G H gets me to the current day’s journal which means it either re-read the config that was just set or some other sort of internal refresh is going on…

logseq.App.pushState('page', { name: todayJournalPage });

doesn’t seem to work, it makes custom.js not load properly…

Edit: found it :slight_smile:

logseq.api.push_state('page', { name: todayJournalPage });