chore(cli): dry up link + post tag prompt
This commit is contained in:
parent
efe701f939
commit
555ba74bf6
8 changed files with 75 additions and 104 deletions
|
@ -2,6 +2,7 @@ import inquirer from "inquirer";
|
|||
import { loadConfig } from "../config.js";
|
||||
import { initDirectusClient, searchItems, createItem } from "../directus/client.js";
|
||||
import { removeUrlProtocol } from "../sanitize.js";
|
||||
import { promptForTags } from "../directus/tagHelpers.js";
|
||||
|
||||
export const addLinkToShare = async () => {
|
||||
const config = await loadConfig();
|
||||
|
@ -87,66 +88,7 @@ export const addLinkToShare = async () => {
|
|||
author = response.author;
|
||||
}
|
||||
|
||||
let tagIds = [];
|
||||
|
||||
while (true) {
|
||||
const { query } = await inquirer.prompt({
|
||||
name: "query",
|
||||
message: "🏷 Search for tags (or leave blank to finish):"
|
||||
});
|
||||
|
||||
const trimmedQuery = query.trim();
|
||||
if (!trimmedQuery) break;
|
||||
|
||||
const tags = await searchItems("tags", trimmedQuery);
|
||||
|
||||
if (!tags.length) {
|
||||
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
|
||||
|
||||
const { shouldCreateTag } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "shouldCreateTag",
|
||||
message: `Do you want to create a new tag named "${trimmedQuery}"?`,
|
||||
default: true
|
||||
});
|
||||
|
||||
if (shouldCreateTag) {
|
||||
const createdTag = await createItem("tags", { name: trimmedQuery });
|
||||
const newTagId = createdTag.data?.id || createdTag.id;
|
||||
|
||||
tagIds.push(newTagId);
|
||||
}
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const { selected } = await inquirer.prompt({
|
||||
type: "checkbox",
|
||||
name: "selected",
|
||||
message: "✔ Select tags to add:",
|
||||
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
|
||||
});
|
||||
|
||||
tagIds.push(...selected);
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
}
|
||||
const tagIds = await promptForTags();
|
||||
|
||||
await createItem("links", {
|
||||
title,
|
||||
|
|
|
@ -2,6 +2,7 @@ import inquirer from "inquirer";
|
|||
import { loadConfig } from "../config.js";
|
||||
import { initDirectusClient, createItem, searchItems } from "../directus/client.js";
|
||||
import { promptForMultipleRelations } from "../directus/relationHelpers.js";
|
||||
import { promptForTags } from "../directus/tagHelpers.js";
|
||||
|
||||
const ASSOCIATED_MEDIA_TYPES = ["artists", "books", "movies", "shows", "genres"];
|
||||
const BLOCK_COLLECTIONS = [
|
||||
|
@ -42,44 +43,7 @@ export const addPost = async () => {
|
|||
}
|
||||
]);
|
||||
|
||||
let tagIds = [];
|
||||
|
||||
while (true) {
|
||||
const { query } = await inquirer.prompt({
|
||||
name: "query",
|
||||
message: "🏷 Search for tags (or leave blank to finish):"
|
||||
});
|
||||
const trimmedQuery = query.trim();
|
||||
|
||||
if (!trimmedQuery) break;
|
||||
|
||||
const tags = await searchItems("tags", trimmedQuery);
|
||||
|
||||
if (!tags.length) {
|
||||
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const { selected } = await inquirer.prompt({
|
||||
type: "checkbox",
|
||||
name: "selected",
|
||||
message: "✔ Select tags to add:",
|
||||
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
|
||||
});
|
||||
|
||||
tagIds.push(...selected);
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
}
|
||||
|
||||
const tagIds = await promptForTags();
|
||||
const selectedBlocks = [];
|
||||
const { includeBlocks } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue