Migrate tags to single file
This commit is contained in:
parent
bb1e533a00
commit
4f42774e83
14 changed files with 326 additions and 335 deletions
|
|
@ -30,43 +30,36 @@ const draftOnlyTagsSet = new Set<string>();
|
|||
uncategorizedTagsSet.forEach((tag) => draftOnlyTagsSet.delete(tag));
|
||||
|
||||
const uniqueSlugs = new Set<string>();
|
||||
const categorizedTags = tagCategories
|
||||
.sort((a, b) => {
|
||||
if (a.data.index === b.data.index) {
|
||||
throw new Error(`Found tag categories with same index value ${a.data.index} ("${a.id}", "${b.id}")`);
|
||||
}
|
||||
return a.data.index - b.data.index;
|
||||
})
|
||||
.map((category) => {
|
||||
const tagList = category.data.tags.map<Tag>(({ name, description }) => {
|
||||
description =
|
||||
description &&
|
||||
markdownToPlaintext(typeof description === "object" ? description[DEFAULT_LANG] : description).replaceAll(
|
||||
/\n+/g,
|
||||
" ",
|
||||
);
|
||||
const tag = typeof name === "string" ? name : name.en;
|
||||
return { id: slug(tag), name: tag, description };
|
||||
});
|
||||
tagList.forEach(({ id, name }) => {
|
||||
if (uniqueSlugs.has(id)) {
|
||||
throw new Error(`Duplicated tag "${name}" found in multiple tag-categories entries`);
|
||||
}
|
||||
uniqueSlugs.add(id);
|
||||
});
|
||||
return {
|
||||
name: category.data.name,
|
||||
id: slug(category.data.name),
|
||||
tags: tagList.filter(({ name }) => {
|
||||
if (draftOnlyTagsSet.has(name)) {
|
||||
// console.log(`Omitting draft-only tag "${name}"`);
|
||||
return false;
|
||||
}
|
||||
uncategorizedTagsSet.delete(name);
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
const categorizedTags = tagCategories.map((category) => {
|
||||
const tagList = category.data.tags.map<Tag>(({ name, description }) => {
|
||||
description =
|
||||
description &&
|
||||
markdownToPlaintext(typeof description === "object" ? description[DEFAULT_LANG] : description).replaceAll(
|
||||
/\n+/g,
|
||||
" ",
|
||||
);
|
||||
const tag = typeof name === "string" ? name : name.en;
|
||||
return { id: slug(tag), name: tag, description };
|
||||
});
|
||||
tagList.forEach(({ id, name }) => {
|
||||
if (uniqueSlugs.has(id)) {
|
||||
throw new Error(`Duplicated tag "${name}" found in multiple tag-categories entries`);
|
||||
}
|
||||
uniqueSlugs.add(id);
|
||||
});
|
||||
return {
|
||||
name: category.data.category,
|
||||
id: category.id,
|
||||
tags: tagList.filter(({ name }) => {
|
||||
if (draftOnlyTagsSet.has(name)) {
|
||||
// console.log(`Omitting draft-only tag "${name}"`);
|
||||
return false;
|
||||
}
|
||||
uncategorizedTagsSet.delete(name);
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
if (uncategorizedTagsSet.size > 0) {
|
||||
const tagList = [...uncategorizedTagsSet];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue