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
- Install Dendron CLI
From CLIGo to text β
Start anchor installation not found
- Install Dendron
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
- Create a symlink of your current package. This lets you use your package locally in other projects
npm link
- Go to your workspace root.
cd $WORKSPACE_ROOT
- If you don't have a
package.json
already , create one by runningnpm init -y
npm init -y
- Link to your created pod
npm link hello-pod
- 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 VS Code, 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.
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
From Sdk Reference
Go to text β
- 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)
Backlinks