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,11 +1,11 @@
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import { createDirectus, staticToken, rest } from '@directus/sdk';
import path from "path";
import { fileURLToPath } from "url";
import dotenv from "dotenv";
import { createDirectus, staticToken, rest } from "@directus/sdk";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: path.resolve(__dirname, '..', '..', '..', '.env') });
dotenv.config({ path: path.resolve(__dirname, "..", "..", "..", ".env") });
let directus;
let API_URL;
@ -15,13 +15,13 @@ export const initDirectusClient = (config) => {
const token = process.env.DIRECTUS_API_TOKEN;
if (!API_URL || !token) throw new Error('Missing Directus API URL or token.');
if (!API_URL || !token) throw new Error("Missing Directus API URL or token.");
directus = createDirectus(API_URL).with(staticToken(process.env.DIRECTUS_API_TOKEN)).with(rest());
};
export const getDirectusClient = () => {
if (!directus) throw new Error('Directus client not initialized.');
if (!directus) throw new Error("Directus client not initialized.");
return directus;
};
@ -31,7 +31,7 @@ const request = async (method, endpoint, body = null) => {
const res = await fetch(`${API_URL}/items/${endpoint}`, {
method,
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
Authorization: `Bearer ${API_TOKEN}`
},
body: body ? JSON.stringify(body) : null
@ -46,13 +46,13 @@ const request = async (method, endpoint, body = null) => {
return await res.json();
};
export const searchItems = async (collection, query = '', filters = {}) => {
export const searchItems = async (collection, query = "", filters = {}) => {
const API_TOKEN = process.env.DIRECTUS_API_TOKEN;
const params = new URLSearchParams();
if (query) params.append('search', query);
if (query) params.append("search", query);
params.append('limit', '50');
params.append("limit", "50");
for (const [field, value] of Object.entries(filters)) {
params.append(`filter[${field}][_eq]`, value);
@ -60,9 +60,9 @@ export const searchItems = async (collection, query = '', filters = {}) => {
try {
const res = await fetch(`${API_URL}/items/${collection}?${params.toString()}`, {
method: 'GET',
method: "GET",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
Authorization: `Bearer ${API_TOKEN}`
}
});
@ -77,6 +77,6 @@ export const searchItems = async (collection, query = '', filters = {}) => {
};
export const updateItem = async (collection, id, values) =>
await request('PATCH', `${collection}/${id}`, values);
await request("PATCH", `${collection}/${id}`, values);
export const createItem = async (collection, values) => await request('POST', collection, values);
export const createItem = async (collection, values) => await request("POST", collection, values);

View file

@ -1,12 +1,12 @@
import inquirer from 'inquirer';
import { searchItems } from '../directus/client.js';
import inquirer from "inquirer";
import { searchItems } from "../directus/client.js";
export const promptForMultipleRelations = async (collection, label = collection) => {
const selectedIds = new Set();
while (true) {
const { query } = await inquirer.prompt({
name: 'query',
name: "query",
message: `🔍 Search ${label} (or leave blank to finish):`
});
const trimmed = query.trim();
@ -22,8 +22,8 @@ export const promptForMultipleRelations = async (collection, label = collection)
}
const { selected } = await inquirer.prompt({
type: 'checkbox',
name: 'selected',
type: "checkbox",
name: "selected",
message: `✔ Select ${label} to add:`,
choices: results.map((item) => ({
name: item.name || item.title || item.id,
@ -34,8 +34,8 @@ export const promptForMultipleRelations = async (collection, label = collection)
selected.forEach((id) => selectedIds.add(id));
const { again } = await inquirer.prompt({
type: 'confirm',
name: 'again',
type: "confirm",
name: "again",
message: `Search and add more ${label}?`,
default: false
});