CLI
The MotionLink CLI enables you to transform your Notion pages into text files that can later be consumed by your static site generators. It also comes with Notion Page to Markdown transformers for those many static site generators using Markdown for content. You can learn more about the CLI tool here.
Configuration file
To use the motionlink-cli, one needs to first create a motionlink.config.js file in the root folder of their project. The file should export an array of TemplateRule objects.
/** @type {import("motionlink-cli/lib/models/config_models").TemplateRule[]} */
const rules = [];
module.exports = rules;
TemplateRule
A TemplateRule specifies 4 things, all of which are required fields:
The path to the template file to populate pages with
The path to the output directory where populated pages are to be written
The primary
DatabaseRulewhich specifies how the Notion pages are to be fetched and mappedAn array of secondary
DatabaseRuleobjects. Secondary DatabaseRules come into use when you want to populate the contents of a page from more than one Notion database. For example, if your primary DatabaseRule fetches articles, you can have a secondary DatabaseRule that fetches their authors.
Given below is an example of a TemplateRule
{
template: "page_template.md",
outDir: "./public",
uses: {
database: "articles",
fetchBlocks: true,
map: (page, ctx) => {
// You can access the authors database as follows.
const authors = ctx.others.authors;
return page;
},
},
alsoUses: [
{
database: "authors",
map: (page, ctx) => {
return page;
},
},
],
}
The TemplateRule object has the following type:
export type TemplateRule = {
template: string;
outDir: string;
uses: DatabaseRule;
alsoUses: DatabaseRule[];
};
DatabaseRule
A DatabaseRule tells the tool how data is be fetched from the database.
A DatabaseRule has the following type:
export type DatabaseRule = {
database: string;
fetchBlocks?: boolean;
takeOnly?: number;
map?: (notionPage: NotionPage, context: Context) => NotionPage;
sort?: SortsParams;
/**
* See: https://developers.notion.com/reference/post-database-query#post-database-query-filter
*/
filter?: object;
};
database is an alias of the data source. For example, if it is
articlesthen when running the cli tool you will need to pass an argument of the formarticles=<link_access_key>, where<link_access_key>is the access key of the link to pull the data from. Technically, the data will be pulled from the Notion database the link connects.fetchBlocks is false by default. Page blocks are fetched only when it is true.
takeOnly specifies the number of pages to read from the database (after the sorting). By default it is
undefinedwhich reads all pages.map is passed a notion page that it should transform to any object object it wants. The object returned by map is passed to the template file as is. Normally this is where you generate markdown. You should also set
page._titleto the filename you will like the populated file for the page to have. By default, this is the page id.sort and filter are the same types exported by the Notion API. Use
sortto order pages and filter to exclude certain pages. You want to filter out unpublished pages by reading only for pages whoseStatusproperty isPublished,CompletedorPublic. For example:
filter: {
or: [
{
property: "Status",
select: {
equals: "Published",
},
},
{
property: "Status",
select: {
equals: "Completed",
},
},
{
property: "Status",
select: {
equals: "Public",
},
},
],
}
Learn More
You can learn more about the types used in the motionlink-cli by referring to this file. You can also follow the link to learn more about the context object passed to map which allows you to generate markdown and fetch media.