Is there an easy way to have weekly or monthly journals?

It looks like the home page can either be today’s journal, or some static page. I prefer to keep a weekly or monthly journal to simplify the list of pages and graph structure. I can do this externally by updating the config with a cron job, but is there a way to set a templated home page or use the CLI to launch with a custom file name?

1 Like

Instead of updating the home page itself to correspond to the weekly journal, I update a query on a static homepage going to the weekly journal. Since logseq is iterating rapidly I figure this is safer (and it works better for my workflow).

The launcher script I use is this

#!/usr/bin/env bash

# logseq launcher that iterates weekly journals

# journal pages have the form
# - [[<monday date in year-month-day>]]
#          .
#          .
# - [[<sunday date in year-month-day>]]

# PREREQUISITE: homepage must exist and contain a query for the journal of the form
# {{query (page "<page name>")}}
# this script will update the query but not initially create it

# CHANGEME: ensure these variables are consistent with your filesystem layout
#           and desired names
LOGSEQ_BIN="$HOME/.local/bin/logseq-bin"               # logseq binary location
GRAPH_PATH="$HOME/documents/kdb"                       # default graph path
HOMEPAGE_PATH="$GRAPH_PATH/pages/home.md"              # default homepage
WEEKLY_PAGE_TEMPLATE="weekly-%Y-%U"                    # UNIX date-compatible template for weekly journal page
WEEKLY_HOMEPAGE_QUERY_REGEX=$'query (page "weekly[^"]*")'  # sed-compatible regex for the weekly journal query
# NOTE: be careful that the weekly page name and regex are compatible
#       the easiest way to do this is have a unique prefix for the weekly
#       pages, and use that prefix in the regex

# find start and end dates
enddate=`date -dsunday +"%Y-%m-%d"`
startdate=`date --date "$enddate - 6 days" +"%Y-%m-%d"`

# create the name and path for this week's journal page
weeklypage=`date --date "$startdate" +"$WEEKLY_PAGE_TEMPLATE"`
weeklypath="$GRAPH_PATH/pages/$weeklypage.md"

# create this week's homepage query for this week's journal
weeklyquery=`date --date "$startdate" +"query (page \"$weeklypage\")"`

# if the weekly page doesn't yet exist
if [[ ! -f "$weeklypath" ]]; then

  # insert each weekday into the journal page
  curr="$startdate"
  while true; do
    echo "- [[$curr]]"
    [ "$curr" \< "$enddate" ] || break
    curr=$( date +%Y-%m-%d --date "$curr +1 day" )
  done > $weeklypath

  # update the query
  sed -i "s/$WEEKLY_HOMEPAGE_QUERY_REGEX/$weeklyquery/" $HOMEPAGE_PATH
fi

# launch logseq
$LOGSEQ_BIN

If there is enough interest I might be able to convert this to a more general plugin, though I’d probably have the plugin create templated files on trigger dates and leave the user to make more complex queries.

1 Like