Logseq plugin samples for beginner 🌱

  • By Logseq
  • Last update: Sep 21, 2022
  • Comments: 13

Logseq Plugin Samples

This repository contains sample code illustrating the Logseq Plugin API. You can read, play with or adapt from these samples to create your own plugins.

Plugins API: https://logseq.github.io/plugins/

Prerequisites

You need to have node and npm(or yarn) installed on your system to run the examples. Then install the latest Logseq Desktop App from here.

Using nvm to install node and npm

For those who are not familiar with the installation of Node.js and NPM, a simple solution would be to install Node Version Manager (NVM)(link). The installation is straightforward: just download and run the installation bash script. You may need to give access permissions to the script.

After installing nvm, using the command nvm install 16(for current) or nvm install 14(for LTS), you'll be able to install the current version of node and npm on your machine. Because nvm installs locally, there is no need for the sudo command.

For those familiar, nvm acts similarly to anaconda: the same way you can select your version of python with anaconda, you can choose your version of node.js.

Usage

  • git clone https://github.com/logseq/logseq-plugin-samples
  • open Logseq Desktop client and turn on Developer mode in user settings panel
  • open the toolbar dot menus and navigate to plugins page
  • read the README file of the sample you want to load, then determine if it should be rebuilt (npm install && npm run build)
  • navigate to the plugins dashboard: tp
  • click Load unpacked plugin button, then select the sample directory to load it

Getting Started

License

MIT

Github

https://github.com/logseq/logseq-plugin-samples

Comments(13)

  • 1

    Journals Calendar change first day to Monday

    hey, I love this plugin, would be interested to learn how to change the first day to monday. I opened the file logseq-journals-calendar.json but since it's an empty file I couldn't figure out if there's an existing way to change the first day of the week

    image

    Let me know if it there's an existing way, if not this would be a great feature for those of use that prefer monday as the first day of the week

    Thanks a lot!

  • 2

    No slash command for pomodoro timer

    I installed the plugin sample for pomodoro, and can't see the slash command for creating a new pomodoro for some reason. This happened to me on earlier versions of logseq as well. Not sure what could be the problem. I restarted logseq after installing it as wel

    https://user-images.githubusercontent.com/31581044/156960126-4463261d-22a5-4029-ac37-ca7a748b077c.mp4

    l

  • 3

    fail to install on Macbook Air M1 - logseq-journals-calendar

    logseq-journals-calendar Here is the error message when run npm install && npm run build

    > [email protected] postinstall /Users/royyang/Repos/logseq-plugin-samples/logseq-journals-calendar/node_modules/core-js
    > node -e "try{require('./postinstall')}catch(e){}"
    
    Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
    
    The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
    > https://opencollective.com/core-js 
    > https://www.patreon.com/zloirock 
    
    Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
    
    
    > [email protected] postinstall /Users/royyang/Repos/logseq-plugin-samples/logseq-journals-calendar/node_modules/esbuild
    > node install.js
    
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN [email protected] No repository field.
    npm WARN [email protected] No license field.
    
    added 344 packages from 321 contributors and audited 344 packages in 14.485s
    
    31 packages are looking for funding
      run `npm fund` for details
    
    found 0 vulnerabilities
    
    
    > [email protected] build /Users/royyang/Repos/logseq-plugin-samples/logseq-journals-calendar
    > vite build
    
    
    <--- Last few GCs --->
    
    [94570:0x120008000]       70 ms: Scavenge 6.3 (9.2) -> 5.3 (10.0) MB, 0.3 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 
    [94570:0x120008000]       77 ms: Scavenge 6.8 (10.0) -> 5.9 (10.5) MB, 0.4 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 
    [94570:0x120008000]       85 ms: Scavenge 7.6 (14.5) -> 6.5 (15.2) MB, 0.3 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 
    
    
    <--- JS stacktrace --->
    
    FATAL ERROR: wasm code commit Allocation failed - process out of memory
     1: 0x1047d99d8 node::Abort() [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     2: 0x1047d9b58 node::errors::TryCatchScope::~TryCatchScope() [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     3: 0x1048f3330 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     4: 0x1048f32c4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     5: 0x104e88cbc v8::internal::wasm::WasmCodeAllocator::AllocateForCodeInRegion(v8::internal::wasm::NativeModule*, unsigned long, v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     6: 0x104e89950 v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(int, v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     7: 0x104e88618 v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     8: 0x104e89760 v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptr<v8::internal::Counters>, std::__1::shared_ptr<v8::internal::wasm::NativeModule>*) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
     9: 0x104e8bcd4 v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine*, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    10: 0x104e977e8 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, unsigned long) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    11: 0x104e66b34 v8::internal::wasm::AsyncCompileJob::CreateNativeModule(std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, unsigned long) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    12: 0x104e66cfc v8::internal::wasm::AsyncCompileJob::GetOrCreateNativeModule(std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, unsigned long) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    13: 0x104e6f360 v8::internal::wasm::AsyncCompileJob::PrepareAndStartCompile::RunInForeground(v8::internal::wasm::AsyncCompileJob*) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    14: 0x104e6f12c v8::internal::wasm::AsyncCompileJob::CompileTask::RunInternal() [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    15: 0x104836c08 node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task> >) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    16: 0x1048358a0 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    17: 0x104fecc00 uv__async_io [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    18: 0x104ffe7c0 uv__io_poll [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    19: 0x104fed090 uv_run [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    20: 0x104811f40 node::NodeMainInstance::Run() [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    21: 0x1047b27d0 node::Start(int, char**) [/Users/royyang/.nvm/versions/node/v14.16.0/bin/node]
    22: 0x19f2edf34 start [/usr/lib/system/libdyld.dylib]
    [1]    94568 abort      npm run build
    
  • 4

    yarn.lock contains private proxy server?

    Tried to run yarn install in logseq-query-playground and got network timeout errors running yarn install

    Looking at log I was finding error connecting to https://arti.freewheel.tv/api/npm/... At first, I thought it was some proxy on my end and was confused where this came from then I realized these URLs come from the yarn.lock file and was able to resolve the issue by deleting the yarn.lock file before running yarn install

    ➜  logseq-query-playground git:(master) βœ— yarn install
    yarn install v1.22.17
    [1/4] πŸ”  Resolving packages...
    [2/4] 🚚  Fetching packages...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    error An unexpected error occurred: "https://arti.freewheel.tv/api/npm/fw-npm/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.0.0.tgz: ETIMEDOUT".
    info If you think this is a bug, please open a bug report with the information provided in "/Users/kurt.harriger/projects/logseq-plugins/logseq-plugin-samples/logseq-query-playground/yarn-error.log".
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    
  • 5

    @parcel/core: Unexpected output file type .html in target "main"

    When trying to run npm run build for the sample "logseq-reddit-hot-news", the following error is encountered. @parcel/core: Unexpected output file type .html in target "main"

    The above error refers to the package.json file, where parcel expects a .js or .ts file. However, for the plugin, a .html file is needed in target 'main'.

    I've created a pull request for the fix.

  • 6

    Added targets attribute to package.json

    Encountered @parcel/core: Unexpected output file type .html in target "main" when trying to run npm build. Unable to fix it by changing from main to default as the plugin will not run.

  • 7

    Hello World build fails

    npm i && npm run build fails with an error for the Hello World plugin (it worked e.g. for emoji picker):

    
    > [email protected] build
    > parcel build --public-url . --no-source-maps index.html
    
    🚨  /Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/@logseq/libs/dist/lsplugin.user.js: Unexpected token: punc (.)
        at Z.get (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/terser/dist/bundle.min.js:1:525)
        at Object.errorToJson (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/@parcel/utils/src/errorUtils.js:9:20)
        at Pipeline.process (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/Pipeline.js:29:26)
        at async Object.run (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/worker.js:15:12)
        at async Bundler.loadAsset (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/Bundler.js:577:19)
        at async /Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/Bundler.js:610:13
        at async Promise.all (index 2)
        at async Bundler.loadAsset (/Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/Bundler.js:599:21)
        at async /Users/mschmidtkorth/Github/MSK/logseq-plugin-samples/logseq-hello-world/node_modules/parcel-bundler/src/Bundler.js:610:13
        at async Promise.all (index 0)```
  • 8

    remove `barWrap.innerHTML = ''` to restore the original toolbar

    • the line barWrap.innerHTML = '' deletes the original mind-elixir toolbar
    • removing this line will restore the original toolbar (controls to zoom and center view) and appends the CLOSE button at its end image
  • 9

    [Feature request] One day back and forth

    It would be awesome if calendar drop-down would have next and previous days buttons. Scenario: I am on 3rd of June 2022 page, pressing previous day would direct me to 2nd of June 2022 page Also it would be awesome to have go to today button. It is actually similar to how Outlook is handling this: Screenshot 2022-07-04 at 09 56 31

  • 10

    pomodoro timer not refresh by time automaticly

    pomodoro timer not refresh by time automaticly, and only refresh when click the block

    https://user-images.githubusercontent.com/98093788/174101153-8175fe82-3091-4aea-a1c9-0581813e77b3.mov

    logseq v0.7.4 macos13.0beta macbookpro M1 2020

  • 11

    sample logseq-slash-commands: the slash command doesn't work

    I tried the sample logseq-slash-commands in logseq version 0.6.2. Type slash command /Big in a block. The slash command didn't show in the slash command list.

  • 12

    Hello World Plugin Block Context Menu Example Broken

    The current example of a block menu item in the hello world is logseq.Editor.registerBlockContextMenu (line 15). I believe this need to be changed to logseq.Editor.registerBlockContextMenuItem.

    Thanks!

  • 13

    Example for adding a shortcut

    Hi! I've been experimenting with a few knowledge bases and tried Logseq for a while. I'm currently on Trilium Notes.

    Trilium Notes is very scriptable and allows users to bind keyboard shortcuts to their own JavaScript. I currently have one for "create issue", which creates a note with a particular template (basically to make it an issue for my simple in-Trillium issue tracker).

    It would be probably also useful for writers of Logseq plugins to have an example of how to do this properly (especially given that logseq has changeable shortcuts).