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,7 +1,7 @@
import inquirer from 'inquirer';
import { loadConfig } from '../config.js';
import { initDirectusClient, searchItems, createItem } from '../directus/client.js';
import { removeUrlProtocol } from '../sanitize.js';
import inquirer from "inquirer";
import { loadConfig } from "../config.js";
import { initDirectusClient, searchItems, createItem } from "../directus/client.js";
import { removeUrlProtocol } from "../sanitize.js";
export const addLinkToShare = async () => {
const config = await loadConfig();
@ -10,34 +10,34 @@ export const addLinkToShare = async () => {
const { title, link, description, authorQuery } = await inquirer.prompt([
{
name: 'title',
message: '📝 Title for the link:',
validate: (input) => !!input || 'Title is required'
name: "title",
message: "📝 Title for the link:",
validate: (input) => !!input || "Title is required"
},
{
name: 'link',
message: '🔗 URL to share:',
validate: (input) => input.startsWith('http') || 'Must be a valid URL'
name: "link",
message: "🔗 URL to share:",
validate: (input) => input.startsWith("http") || "Must be a valid URL"
},
{
name: 'description',
message: '🗒 Description (optional):',
default: ''
name: "description",
message: "🗒 Description (optional):",
default: ""
},
{
name: 'authorQuery',
message: '👤 Search for an author:'
name: "authorQuery",
message: "👤 Search for an author:"
}
]);
const authorMatches = await searchItems('authors', authorQuery);
const authorMatches = await searchItems("authors", authorQuery);
let author;
if (!authorMatches.length) {
const { shouldCreate } = await inquirer.prompt({
type: 'confirm',
name: 'shouldCreate',
message: '❌ No authors found. Do you want to create a new one?',
type: "confirm",
name: "shouldCreate",
message: "❌ No authors found. Do you want to create a new one?",
default: true
});
@ -45,19 +45,19 @@ export const addLinkToShare = async () => {
const { name, url, mastodon, rss, json, newsletter, blogroll } = await inquirer.prompt([
{
name: 'name',
message: '👤 Author name:',
validate: (input) => !!input || 'Name is required'
name: "name",
message: "👤 Author name:",
validate: (input) => !!input || "Name is required"
},
{ name: 'url', message: '🔗 URL (optional):', default: '' },
{ name: 'mastodon', message: '🐘 Mastodon handle (optional):', default: '' },
{ name: 'rss', message: '📡 RSS feed (optional):', default: '' },
{ name: 'json', message: '🧾 JSON feed (optional):', default: '' },
{ name: 'newsletter', message: '📰 Newsletter URL (optional):', default: '' },
{ type: 'confirm', name: 'blogroll', message: '📌 Add to blogroll?', default: false }
{ name: "url", message: "🔗 URL (optional):", default: "" },
{ name: "mastodon", message: "🐘 Mastodon handle (optional):", default: "" },
{ name: "rss", message: "📡 RSS feed (optional):", default: "" },
{ name: "json", message: "🧾 JSON feed (optional):", default: "" },
{ name: "newsletter", message: "📰 Newsletter URL (optional):", default: "" },
{ type: "confirm", name: "blogroll", message: "📌 Add to blogroll?", default: false }
]);
const created = await createItem('authors', {
const created = await createItem("authors", {
name,
url,
mastodon,
@ -70,9 +70,9 @@ export const addLinkToShare = async () => {
author = created.data?.id || created.id;
} else {
const response = await inquirer.prompt({
type: 'list',
name: 'author',
message: 'Select an author:',
type: "list",
name: "author",
message: "Select an author:",
choices: authorMatches.map((a) => {
const cleanUrl = removeUrlProtocol(a.url);
const display = cleanUrl ? `${a.name} (${cleanUrl})` : a.name;
@ -91,41 +91,64 @@ export const addLinkToShare = 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}"`);
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:',
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
});
if (!again) break;
}
await createItem('links', {
await createItem("links", {
title,
link,
description,
@ -134,5 +157,5 @@ export const addLinkToShare = async () => {
date: new Date().toISOString()
});
console.log('✅ Link created successfully.');
console.log("✅ Link created successfully.");
};