benjypng / logseq-powerblocks-plugin

logseq-powerblocks-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sponsor this project on Github or get me a coffee if you like this plugin!

Overview

This plugin was created as I had some unique workflows that Logseq templates were not able to support. It allows the creation of 3 types of "PowerBlocks":

  1. Sticky button templates (buttons that remain on the page)
  2. Button templates
  3. Normal templates

Button templates allow the adding of templates using a button, while normal templates work like regular templates. A list of supported syntaxes can be found below.

Instructions

Creating the PowerBlocks

  1. From anywhere in Logseq, create a block like the below. #powerblocks, #powerblocks-stickybutton and #powerblocks-button cannot be changed.
### To create a sticky button template

- Buy milk #powerblocks-stickybutton
  - Today is <%DATE:5 days later%>

### To create a button template

- Buy milk #powerblocks-button
  - Today is <%DATE:5 days later%>

### To create a normal template

- testing #powerblocks
  - Today is <%DATE:5 days later%>
  1. The syntaxes currently available can be found in the next section.

Using the PowerBlocks

  1. Trigger the PowerBlocks menu by typing /Insert PowerBlock
  2. Select either a button/sticky button template (⏺ ) or a normal template (📃) that you have created.
  3. Button templates can be used within a Logseq template if you prefer..

Syntaxes (General)

Below is the list of available syntaxes. I may consider adding to the list, but as I am not sure how useful anyone will find this plugin, it is likely only syntaxes I use will be added.

  • <%PB:time%> Inserts a powerblock in your template, e.g. "time". This only works for buttons.

  • <%DATE:next tuesday%> In this example, if the template is used on a journal page, it will be relative to the journal day. But if used on a page, it will be relative to today.

  • <%DAY%> This simply replaces the syntax with the current day.

  • <%TIME%> This simply replaces the syntax with the current time.

  • <%TIMEAMPM%> This adds in time but in AM/PM format.

  • <%YEAR%> This simply replaces the syntax with the current year.

  • <%INPUT:How are you feeling today?%> When including this syntax in a block, there will be an input where the placeholder will appear in the prompt. After submitting it, the values will be added to your template.

  • <%RANDOMTAG:quotes%> Use this syntax to get a random block that is tagged. In the above example, it will return a random block that is tagged with "quotes", or belongs to a page called "quotes".

  • <%CURRENTPAGENAME%> Get the name of the page that this syntax is being used at.

  • <%CURRENTPAGEURL%> Get the Logseq URL of the page that this syntax is being used at.

  • <%WEEKSSINCEDATE:28 Feb 1990%> Get the number of weeks since a specific date (accepts NLP). For the above example, the syntax will return the number of calendar weeks since the 28th of February, 1990.

  • <%SIDEBAROPEN:uuid%> If your template or button contains this syntax, the right sidebar will immediately open with the indicated block.

  • <%GETPROPERTY:[[page]],property%> Gets the value of the stated property from the stated page.

Syntaxes (CONDITIONAL)

Below is the list of syntaxes that rely on conditions specified. Blocks with the conditions will only appear if it matches the parameters.

  • <%IFDAYOFWEEK:1"%> Block containing this syntax will only be added if the day of the week matches the day indicated. 0 is Sunday, 1 is Monday and so on. If you would like the block to be added on multiple days, simply add the values separated by ,, e.g. <%IFDAYOFWEEK:1,2,4%>.

  • <%IFMONTHOFYEAR:2%> Block containing this syntax will only be added if the month of the year matches the month indicated. 0 is January, 1 is February and so on. If you would like the block to be added on multiple days, simply add the values separated by ,, e.g. <%IFMONTHOFYEAR:1,2,4%>.

  • <%IFYEAR:2023%> Block containing this syntax will only be added if the year matches the year indicated.. If you would like the block to be added on multiple days, simply add the values separated by ,, e.g. <%YEAR:2022,2023%>.

  • <%IFDATE:tomorrow%> Block containing this syntax will only be added if the date mentioned in the block matches the current date.

  • <%IFDATEOFMONTH:15%> Block containing this syntax will only be added if the date mentioned in the block matches the current date of every month.

AND / OR Conditions

You can use AND OR conditions with the above conditional syntaxes. Below are some examples on how you can use it.

  • <%AND <%IFDAYOFWEEK:2%> <%IFMONTHOFYEAR:0%> %> Hello World With the above block, Hello World will only be inserted every Tuesday of January.

  • <%OR <%IFDAYOFWEEK:1%> <%IFDAYOFWEEK:5%> %> Hello World With the above block, Hello World will be rendered every Tuesday and every Friday.

Credits

Big shoutout to David Vargas and the work he has done for Roam's Smart Blocks. Also thanks to R.J. Nestor for his sharing on how he used Smart Blocks and for inspiring me to do the same in Logseq.

Once again, chrono-node for supplying the date parser.

About

logseq-powerblocks-plugin

License:MIT License


Languages

Language:TypeScript 90.0%Language:CSS 6.9%Language:JavaScript 2.0%Language:HTML 1.0%