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
133
);
134
134
135
135
// Build frontmatter mapping object
136
136
-
let frontmatterMapping: FrontmatterMapping | undefined = {};
136
136
+
const fieldMappings: Array<[keyof FrontmatterMapping, string, string]> = [
137
137
+
["title", frontmatterConfig.titleField, "title"],
138
138
+
["description", frontmatterConfig.descField, "description"],
139
139
+
["publishDate", frontmatterConfig.dateField, "publishDate"],
140
140
+
["coverImage", frontmatterConfig.coverField, "ogImage"],
141
141
+
["tags", frontmatterConfig.tagsField, "tags"],
142
142
+
];
137
143
138
138
-
if (frontmatterConfig.titleField !== "title") {
139
139
-
frontmatterMapping.title = frontmatterConfig.titleField;
140
140
-
}
141
141
-
if (frontmatterConfig.descField !== "description") {
142
142
-
frontmatterMapping.description = frontmatterConfig.descField;
143
143
-
}
144
144
-
if (frontmatterConfig.dateField !== "publishDate") {
145
145
-
frontmatterMapping.publishDate = frontmatterConfig.dateField;
146
146
-
}
147
147
-
if (frontmatterConfig.coverField !== "ogImage") {
148
148
-
frontmatterMapping.coverImage = frontmatterConfig.coverField;
149
149
-
}
150
150
-
if (frontmatterConfig.tagsField !== "tags") {
151
151
-
frontmatterMapping.tags = frontmatterConfig.tagsField;
152
152
-
}
144
144
+
const builtMapping = fieldMappings.reduce<FrontmatterMapping>(
145
145
+
(acc, [key, value, defaultValue]) => {
146
146
+
if (value !== defaultValue) {
147
147
+
acc[key] = value;
148
148
+
}
149
149
+
return acc;
150
150
+
},
151
151
+
{},
152
152
+
);
153
153
154
154
// Only keep frontmatterMapping if it has any custom fields
155
155
-
if (Object.keys(frontmatterMapping).length === 0) {
156
156
-
frontmatterMapping = undefined;
157
157
-
}
155
155
+
const frontmatterMapping =
156
156
+
Object.keys(builtMapping).length > 0 ? builtMapping : undefined;
158
157
159
158
// Publication setup
160
159
const publicationChoice = await select({