Skip to content

Commit eeb9244

Browse files
Clarify usage of compile function in COMPILE.md (#312)
- Make it easier to understand that user need to define his own compile function. - Make the step work out of the box, the added step appears directly in the "user steps" tab when script is copy pasted into a .js file
1 parent 64ab6a4 commit eeb9244

1 file changed

Lines changed: 39 additions & 35 deletions

File tree

docs/COMPILE.md

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,45 @@ To add a user script to Longform, first create a folder somewhere in your vault
9797
Next, add your first step as a `.js` file. Every step must export an object in the following shape:
9898

9999
```js
100+
101+
compile = (input, context) => {
102+
/**
103+
Function that is executed during compilation. It may be `async`.
104+
Errors encountered during execution should be thrown and will
105+
be handled by Longform.
106+
@param input If the step is of kind Scene or Join (see context),
107+
this will be *an array* containing elements of type:
108+
{
109+
path: string; // path to scene
110+
name: string; // file name of scene
111+
contents: string; // text contents of scene
112+
metadata: CachedMetadata; // Obsidian metadata of scene
113+
indentationLevel?: number; // The indent level (starting at zero) of the scene
114+
}
115+
where each element corresponds to a scene (and thus the step has access to all scenes at once in `input`).
116+
If the step is of kind Manuscript (see context), this will be of type:
117+
{
118+
// text contents of manuscript
119+
contents: string;
120+
}
121+
@param context The execution context of the step, including the step
122+
kind and option values:
123+
{
124+
kind: string; // "Scene" | "Join" | "Manuscript"
125+
optionValues: { [id: string]: unknown } // Map of option IDs to values
126+
projectPath: string; // path in vault to compiling project
127+
draft: Draft; // The Draft type describing your project
128+
app: App; // Obsidian app
129+
}
130+
@note For an example of using `context` to determine the shape of `input`, see
131+
https://github.com/kevboh/longform/blob/main/src/compile/steps/strip-frontmatter.ts
132+
@returns If of kind "Scene" or "Manuscript", the same shape as `input`
133+
with the appropriate changes made to `contents`. If of kind "Join",
134+
the same shape as a "Manuscript" step input.
135+
*/
136+
return;
137+
}
138+
100139
module.exports = {
101140
// object that describes the step and its configuration
102141
description: {
@@ -138,41 +177,6 @@ module.exports = {
138177
},
139178
],
140179
},
141-
142-
/**
143-
Function that is executed during compilation. It may be `async`.
144-
Errors encountered during execution should be thrown and will
145-
be handled by Longform.
146-
@param input If the step is of kind Scene or Join (see context),
147-
this will be *an array* containing elements of type:
148-
{
149-
path: string; // path to scene
150-
name: string; // file name of scene
151-
contents: string; // text contents of scene
152-
metadata: CachedMetadata; // Obsidian metadata of scene
153-
indentationLevel?: number; // The indent level (starting at zero) of the scene
154-
}
155-
where each element corresponds to a scene (and thus the step has access to all scenes at once in `input`).
156-
If the step is of kind Manuscript (see context), this will be of type:
157-
{
158-
// text contents of manuscript
159-
contents: string;
160-
}
161-
@param context The execution context of the step, including the step
162-
kind and option values:
163-
{
164-
kind: string; // "Scene" | "Join" | "Manuscript"
165-
optionValues: { [id: string]: unknown } // Map of option IDs to values
166-
projectPath: string; // path in vault to compiling project
167-
draft: Draft; // The Draft type describing your project
168-
app: App; // Obsidian app
169-
}
170-
@note For an example of using `context` to determine the shape of `input`, see
171-
https://github.com/kevboh/longform/blob/main/src/compile/steps/strip-frontmatter.ts
172-
@returns If of kind "Scene" or "Manuscript", the same shape as `input`
173-
with the appropriate changes made to `contents`. If of kind "Join",
174-
the same shape as a "Manuscript" step input.
175-
*/
176180
compile: compile,
177181
};
178182
```

0 commit comments

Comments
 (0)