-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmotionlink.config.js
More file actions
137 lines (118 loc) · 3.21 KB
/
Copy pathmotionlink.config.js
File metadata and controls
137 lines (118 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Run this script with:
*
* @example
* npx motionlink tutorials=<tutorials_link_access_key> blogPosts=<blog_posts_link_access_key>
*/
const markdownService = require("motionlink-cli/lib/services/markdown_service");
const ObjectTransformers = markdownService.ObjectTransformers;
const sanitize = require("sanitize-filename");
/** @type {import("motionlink-cli/lib/models/config_models").TemplateRule[]} */
const rules = [
// To build the articles
{
template: "motionlink_templates/tutorial_template.md",
outDir: "docs",
alsoUses: [],
uses: {
database: "tutorials",
fetchBlocks: true,
filter: {
or: [
{
property: "Status",
select: {
equals: "Published",
},
},
],
},
map: (page, context) => {
page.otherData.rank = page.data.properties.Rank.number;
// Assuming the title has no formatting.
page._title = ObjectTransformers.transform_all(
page.data.properties.Title.title
);
page.otherData.title =
"# " +
ObjectTransformers.transform_all(page.data.properties.Title.title);
page.otherData.content = context.genMarkdownForBlocks(page.blocks);
return page;
},
},
},
// To Capture the getting started Tutorial page in the docusaurus.config.js file
{
template: "motionlink_templates/docusaurus.config_template.js",
outDir: ".",
alsoUses: [],
uses: {
database: "tutorials",
fetchBlocks: false,
filter: {
or: [
{
property: "Status",
select: {
equals: "Published",
},
},
],
},
sort: [
{
property: "Rank",
direction: "ascending",
},
],
takeOnly: 1,
map: (page, _) => {
// Assuming the title has no formatting.
page.otherData.introDocId = ObjectTransformers.transform_all(
page.data.properties.Title.title
);
page._title = "docusaurus.config";
return page;
},
},
},
// To build the blog posts
{
template: "motionlink_templates/blog_post_template.md",
outDir: "blog",
alsoUses: [],
uses: {
database: "blogPosts",
fetchBlocks: true,
filter: {
or: [
{
property: "Status",
select: {
equals: "Published",
},
},
],
},
map: (page, context) => {
function makeTwo(n) {
const str = `${n}`;
if (str.length < 2) return `0${str}`;
return str;
}
const date = new Date(page.data.created_time);
const dateAsString = `${date.getFullYear()}-${makeTwo(
date.getMonth() + 1
)}-${makeTwo(date.getDate())}`;
// Assuming the title has no formatting.
page._title = dateAsString + "-" + sanitize(page.data.id);
page.otherData.titleText = ObjectTransformers.transform_all(
page.data.properties.Title.title
);
page.otherData.content = context.genMarkdownForBlocks(page.blocks);
return page;
},
},
},
];
module.exports = rules;