Logseq Plugin Samples

repository·master·Indexed 18 days ago

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

A collection of sample implementations of the Logseq Plugin API serving as a reference for developers. Includes examples for using Logseq.App hooks like onInputSelectionEnd, registering slash commands, manipulating editor appearance via provideUI and provideStyle, and utilizing Logseq.DB for Datascript queries. Featured samples include a translator, emoji picker, Pomodoro timer, IMDb Top 250 importer for DB graphs, and various theme implementations.

Tokens
12.3K
Snippets
63
Records
81
Agent score
63%

What's inside logseq-plugin-samples

  1. How the plugin uses Logseq DB APIs to write data

    master

    The plugin demonstrates how to manipulate a Logseq DB graph using the logseq.Editor API. Key methods used in index.tsx include:

    • Creating Metadata & Tags:

      • logseq.Editor.upsertProperty(...): Creates or updates properties.
      • logseq.Editor.createTag(...): Creates new tags like #movie or #director.
      • logseq.Editor.addTagProperty(...): Attaches properties specifically to a tag.
    • Importing Individual Items:

      • logseq.Editor.createPage(...): Creates the actual movie page.
      • logseq.Editor.addBlockTag(...): Applies tags to specific blocks/pages.
      • logseq.Editor.upsertBlockProperty(...): Sets property values on a block.

    Performance Tip: The plugin uses a 100ms throttle between imports via setTimeout to avoid overwhelming the Logseq process.

  2. Run the Pomodoro Timer Sample plugin

    master

    To run this sample locally, ensure you are using at least Logseq App version 0.4.6. Follow these steps:

    1. Build the project: Run the following commands in your terminal to install dependencies and build the plugin:
      yarn && yarn build
    2. Install in Logseq: Open the Logseq Desktop client, go to the plugin settings, and select 'Load unpacked plugin', then point to the directory containing the built files.
    yarn && yarn build
  3. Set up the development environment for IMDb Top 250 Importer

    master

    The plugin uses Vite and React 18. To start developing:

    1. Install dependencies:
      npm install
    2. Start the development server:
      npm run dev
    3. In Logseq, enable Developer mode and load the plugin from the project folder.

    The development entry point is configured in package.json at http://localhost:5173.

    To build the plugin for production:

    npm run build
    npm install
    npm run dev
    npm run build
  4. Run the logseq-awesome-fonts sample plugin

    master

    To run this sample plugin locally, follow these steps:

    1. Build the project: Open your terminal in the plugin directory and run:
      npm install && npm run build
    2. Load into Logseq: Open the Logseq Desktop client, go to the plugin settings, and select Load unpacked plugin to point to the built plugin directory.
    npm install && npm run build
  5. Load a plugin sample into Logseq Desktop

    master

    Follow these steps to run a sample plugin from this repository in your local Logseq instance:

    1. Clone the repository:
      git clone https://github.com/logseq/logseq-plugin-samples
    2. Enable Developer Mode: Open the Logseq Desktop client, go to the user settings panel, and turn on Developer mode.
    3. Prepare the sample: Navigate to the specific sample directory. Check its README.md to see if it requires a build step. If it does, run:
      npm install && npm run build
    4. Open Plugins Dashboard: In Logseq, use the keyboard shortcut <kbd>t</kbd><kbd>p</kbd> to navigate to the plugins page.
    5. Load the plugin: Click the Load unpacked plugin button and select the directory of the sample you wish to load.

    Note: To ensure stability and performance, keep the @logseq/libs SDK up-to-date.

    git clone https://github.com/logseq/logseq-plugin-samples
    npm install && npm run build
  6. Install Base16 LoqSeq color schemes

    master

    You can apply Base16 color schemes to Logseq using one of two methods:

    1. Manual Installation:

      • Browse the css folder in this repository to find a color scheme you like.
      • Copy the contents of that CSS file.
      • Paste the contents into your Logseq configuration file at logseq/custom.css.
    2. Browser Extension:

      • Use a CSS management tool like Stylus to apply the styles.
  7. Install prerequisites for Logseq plugin development

    master

    To run and develop Logseq plugin samples, you need the following installed on your system:

    1. Node.js and npm (or yarn): Required to manage dependencies and build the samples.
    2. Logseq Desktop App: The latest version from the Logseq releases page.

    If you are unsure how to install Node.js, it is recommended to use Node Version Manager (NVM). You can install NVM via their installation script, then install Node using:

    nvm install 22 # For current version
    # OR
    nvm install 20 # For LTS version
    nvm install 22