feat(*.liquid): apply prettier to liquid templates

- offer to create tag when none is found while adding a link from cli
- fix tag display in search
This commit is contained in:
Cory Dransfeldt 2025-06-16 14:40:54 -07:00
parent 49e21d574e
commit efe701f939
No known key found for this signature in database
112 changed files with 1319 additions and 1134 deletions

View file

@ -1,16 +1,16 @@
import inquirer from 'inquirer';
import { loadConfig } from '../config.js';
import { initDirectusClient, createItem, searchItems } from '../directus/client.js';
import { promptForMultipleRelations } from '../directus/relationHelpers.js';
import inquirer from "inquirer";
import { loadConfig } from "../config.js";
import { initDirectusClient, createItem, searchItems } from "../directus/client.js";
import { promptForMultipleRelations } from "../directus/relationHelpers.js";
const ASSOCIATED_MEDIA_TYPES = ['artists', 'books', 'movies', 'shows', 'genres'];
const ASSOCIATED_MEDIA_TYPES = ["artists", "books", "movies", "shows", "genres"];
const BLOCK_COLLECTIONS = [
'youtube_player',
'github_banner',
'npm_banner',
'rss_banner',
'calendar_banner',
'forgejo_banner'
"youtube_player",
"github_banner",
"npm_banner",
"rss_banner",
"calendar_banner",
"forgejo_banner"
];
export const addPost = async () => {
@ -20,24 +20,24 @@ export const addPost = async () => {
const { title, description, content, featured } = await inquirer.prompt([
{
name: 'title',
message: '📝 Title:',
validate: (input) => !!input || 'Title is required'
name: "title",
message: "📝 Title:",
validate: (input) => !!input || "Title is required"
},
{
name: 'description',
message: '🗒 Description:',
default: ''
name: "description",
message: "🗒 Description:",
default: ""
},
{
name: 'content',
message: '📄 Content:',
default: ''
name: "content",
message: "📄 Content:",
default: ""
},
{
type: 'confirm',
name: 'featured',
message: '⭐ Featured?',
type: "confirm",
name: "featured",
message: "⭐ Featured?",
default: false
}
]);
@ -46,14 +46,14 @@ export const addPost = async () => {
while (true) {
const { query } = await inquirer.prompt({
name: 'query',
message: '🏷 Search for tags (or leave blank to finish):'
name: "query",
message: "🏷 Search for tags (or leave blank to finish):"
});
const trimmedQuery = query.trim();
if (!trimmedQuery) break;
const tags = await searchItems('tags', trimmedQuery);
const tags = await searchItems("tags", trimmedQuery);
if (!tags.length) {
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
@ -62,18 +62,18 @@ export const addPost = async () => {
}
const { selected } = await inquirer.prompt({
type: 'checkbox',
name: 'selected',
message: '✔ Select tags to add:',
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?',
type: "confirm",
name: "again",
message: "Search and select more tags?",
default: false
});
@ -82,25 +82,25 @@ export const addPost = async () => {
const selectedBlocks = [];
const { includeBlocks } = await inquirer.prompt({
type: 'confirm',
name: 'includeBlocks',
message: ' Add blocks?',
type: "confirm",
name: "includeBlocks",
message: " Add blocks?",
default: false
});
if (includeBlocks) {
while (true) {
const { collection } = await inquirer.prompt({
type: 'list',
name: 'collection',
message: '🧱 Choose a block collection (or Cancel to finish):',
choices: [...BLOCK_COLLECTIONS, new inquirer.Separator(), 'Cancel']
type: "list",
name: "collection",
message: "🧱 Choose a block collection (or Cancel to finish):",
choices: [...BLOCK_COLLECTIONS, new inquirer.Separator(), "Cancel"]
});
if (collection === 'Cancel') break;
if (collection === "Cancel") break;
const { query } = await inquirer.prompt({
name: 'query',
name: "query",
message: `🔍 Search ${collection}:`
});
const results = await searchItems(collection, query);
@ -112,8 +112,8 @@ export const addPost = async () => {
}
const { itemId } = await inquirer.prompt({
type: 'list',
name: 'itemId',
type: "list",
name: "itemId",
message: `Select an item from ${collection}:`,
choices: results.map((item) => ({
name: item.title || item.name || item.id,
@ -124,9 +124,9 @@ export const addPost = async () => {
selectedBlocks.push({ collection, item: itemId });
const { again } = await inquirer.prompt({
type: 'confirm',
name: 'again',
message: ' Add another block?',
type: "confirm",
name: "again",
message: " Add another block?",
default: false
});
@ -136,16 +136,16 @@ export const addPost = async () => {
const associatedMediaPayload = {};
const { includeMedia } = await inquirer.prompt({
type: 'confirm',
name: 'includeMedia',
message: ' Add associated media?',
type: "confirm",
name: "includeMedia",
message: " Add associated media?",
default: false
});
if (includeMedia) {
for (const mediaType of ASSOCIATED_MEDIA_TYPES) {
const { query } = await inquirer.prompt({
name: 'query',
name: "query",
message: `🔎 Search for ${mediaType} to associate (or leave blank to skip):`
});
@ -160,8 +160,8 @@ export const addPost = async () => {
}
const { selected } = await inquirer.prompt({
type: 'checkbox',
name: 'selected',
type: "checkbox",
name: "selected",
message: `✔ Select ${mediaType} to associate:`,
choices: matches.map((m) => ({
name: m.name_string || m.title || m.name || m.label || m.id,
@ -176,7 +176,7 @@ export const addPost = async () => {
}
}
const media = await promptForMultipleRelations('media', 'Associated media');
const media = await promptForMultipleRelations("media", "Associated media");
const payload = {
title,
description,
@ -188,7 +188,7 @@ export const addPost = async () => {
...associatedMediaPayload
};
await createItem('posts', payload);
await createItem("posts", payload);
console.log('✅ Post created successfully.');
console.log("✅ Post created successfully.");
};