Developing a Pod

Summary

  • status: WORK_IN_PROGRESS šŸš§

In this module, we'll go over how to create a custom pod. You can clone the end result here

Pre-requisites

Tutorial

Create your pod

  • NOTE: this tutorial goes over developing using javascript. All Dendron packages are typed and can also be developed using typescript
mkdir hello-pod
npm init -y
npm install --save @dendronhq/pods-core
touch index.js

Open index.js and add the following

const { PublishPod } = require("@dendronhq/pods-core");

class HelloPod extends PublishPod {
  static id = "hello";
  static description = "Add a hello statement";

  async plant(opts) {
    const { note } = opts;
    const body = note.body;
    return ["Hello World", body].join("\n");
  }
}

module.exports = {
  pods: [HelloPod],
};

Testing your pod

  1. Create a symlink of your current package. This lets you use your package locally in other projects
    npm link
    
  2. Go to your workspace root.
    cd $WORKSPACE_ROOT
    
  3. If you don't have a package.json already , create one by running npm init -y
    npm init -y
    
  4. Link to your created pod
    npm link hello-pod
    
  5. Excecute your pod
    dendron-cli publishPod --wsRoot . --podId hello --podPkg hello-pod --podSource custom --config fname=dendron,vaultName=vault,dest=stdout
    
    • since I was running this in a new Dendron vault, I got the following output.
    • you can change the value of the fname config to an existing note's file name to run it against that note.

The Trail šŸ„¾

Here are the basics of Dendron so you can get started growing your knowledge base.

  • Create your first note.
    • Dendron uses the lookup command to create. So, hit CMD+L (or ctrl+L if you're on Windows) to bring up the lookup bar, type in a new note name and hit enter to create it. You can also run the lookup command through the command palette "Dendron: Lookup".
    • Wiki-style links are supported. If the note doesn't exist, we'll create the note for you. For example, just try this link (Private) from the editor view.
  • Find your notes. Dendron really shines when you need to look up notes quickly. For this, you use drumroll the lookup command (again). Just hit CMD/ctrl+L and you can search your entire set of notes.
  • To delete a note, navigate to it and use the "Dendron: Delete Node" command. As with everything else in VSCode, bring up the command palette with CMD/ctrl+shift+P and run the command.
  • Use a snippet for quick note templates
  • Insert an image
  • Create some links
  • Publish your vault
  • Join us on discord and discuss all things knowledge management with your fellow trail blazers.
  • For more information, see Dendron's basic concepts

### Pass in custom configuration values

We're going to make our publishing a little more dynamoc by using custom configuration. 

Modify your pod to accept a new configuration parameter

```js
const { PublishPod } = require("@dendronhq/pods-core");

class HelloPod extends PublishPod {
  static id = "hello";
  static description = "Add a hello statement";

  get config() {
    return super.config.concat([
      {
        key: "name",
        description: "dev.to api key",
        type: "string",
      },
    ]);
  }

  async plant(opts) {
    const { note, config } = opts;
    const body = note.body;
    return [`Hello ${config.name}`, body].join("\n");
  }
}

module.exports = {
  pods: [HelloPod],
};

Below is a diff to make the changes a bit more obvious. diff of code

Run the pod again the the additional argument.

```sh
dendron-cli publishPod --wsRoot . --podId hello --podPkg hello-pod --podSource remote --config fname=dendron,vaultName=vault,dest=stdout,name=Albert
```
Hello Albert

## The Trail šŸ„¾
...

Use Note Metadata

Pods have full access to all the metadata attached to a note. You can see the pod arguments below

  • opts
    • engine: DEngineClientV2
    • config: PublishPodConfig
    • note: NotePropsV2
export type NotePropsV2 = {
  id: string;
  title: string;
  desc: string;
  links: DLink[];
  fname: string;
  updated: string;
  created: string;
  parent: DNodePointerV2 | null;
  children: DNodePointerV2[];
  body: string;
  custom?: any;
  schema?: { moduleId: string; schemaId: string };
  vault: DVault;
  ...
};

TODO - You can see an example of this here (Private)

Using Typescript

TODO - You can see an example of this here (Private)