tangled
alpha
login
or
join now
stevedylan.dev
/
sequoia
A CLI for publishing standard.site documents to ATProto
sequoia.pub
standard
site
lexicon
cli
publishing
29
fork
atom
overview
issues
4
pulls
1
pipelines
chore: refactored mapping
stevedylan.dev
1 week ago
d29624a3
00ae004c
+18
-19
1 changed file
expand all
collapse all
unified
split
packages
cli
src
commands
init.ts
+18
-19
packages/cli/src/commands/init.ts
···
133
);
134
135
// Build frontmatter mapping object
136
-
let frontmatterMapping: FrontmatterMapping | undefined = {};
0
0
0
0
0
0
137
138
-
if (frontmatterConfig.titleField !== "title") {
139
-
frontmatterMapping.title = frontmatterConfig.titleField;
140
-
}
141
-
if (frontmatterConfig.descField !== "description") {
142
-
frontmatterMapping.description = frontmatterConfig.descField;
143
-
}
144
-
if (frontmatterConfig.dateField !== "publishDate") {
145
-
frontmatterMapping.publishDate = frontmatterConfig.dateField;
146
-
}
147
-
if (frontmatterConfig.coverField !== "ogImage") {
148
-
frontmatterMapping.coverImage = frontmatterConfig.coverField;
149
-
}
150
-
if (frontmatterConfig.tagsField !== "tags") {
151
-
frontmatterMapping.tags = frontmatterConfig.tagsField;
152
-
}
153
154
// Only keep frontmatterMapping if it has any custom fields
155
-
if (Object.keys(frontmatterMapping).length === 0) {
156
-
frontmatterMapping = undefined;
157
-
}
158
159
// Publication setup
160
const publicationChoice = await select({
···
133
);
134
135
// Build frontmatter mapping object
136
+
const fieldMappings: Array<[keyof FrontmatterMapping, string, string]> = [
137
+
["title", frontmatterConfig.titleField, "title"],
138
+
["description", frontmatterConfig.descField, "description"],
139
+
["publishDate", frontmatterConfig.dateField, "publishDate"],
140
+
["coverImage", frontmatterConfig.coverField, "ogImage"],
141
+
["tags", frontmatterConfig.tagsField, "tags"],
142
+
];
143
144
+
const builtMapping = fieldMappings.reduce<FrontmatterMapping>(
145
+
(acc, [key, value, defaultValue]) => {
146
+
if (value !== defaultValue) {
147
+
acc[key] = value;
148
+
}
149
+
return acc;
150
+
},
151
+
{},
152
+
);
0
0
0
0
0
0
153
154
// Only keep frontmatterMapping if it has any custom fields
155
+
const frontmatterMapping =
156
+
Object.keys(builtMapping).length > 0 ? builtMapping : undefined;
0
157
158
// Publication setup
159
const publicationChoice = await select({