Enhance interview functionality and settings; add YAML dependency
- Introduced profile selection modal for creating notes from interview profiles. - Added settings for interview configuration path, auto-starting interviews, and intercepting unresolved link clicks. - Updated package files to include YAML dependency for configuration handling. - Enhanced CSS for profile selection and interview wizard UI elements.
This commit is contained in:
1 parent
d577283af6
commit
bab84549e2
19 files changed
+2840
-5
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import type { InterviewProfile } from "./types";
|
||||
|
||||
export interface FrontmatterOptions {
|
||||
id: string;
|
||||
title: string;
|
||||
noteType: string;
|
||||
interviewProfile: string;
|
||||
defaults?: Record<string, unknown>;
|
||||
frontmatterWhitelist: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write frontmatter YAML from options.
|
||||
* Only includes defaults fields that are in frontmatterWhitelist.
|
||||
*/
|
||||
export function writeFrontmatter(opts: FrontmatterOptions): string {
|
||||
const { id, title, noteType, interviewProfile, defaults, frontmatterWhitelist } = opts;
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push("---");
|
||||
|
||||
// Required fields
|
||||
lines.push(`id: ${escapeYamlValue(id)}`);
|
||||
lines.push(`title: ${escapeYamlValue(title)}`);
|
||||
lines.push(`type: ${escapeYamlValue(noteType)}`);
|
||||
lines.push(`interview_profile: ${escapeYamlValue(interviewProfile)}`);
|
||||
|
||||
// Whitelisted defaults
|
||||
if (defaults) {
|
||||
for (const [key, value] of Object.entries(defaults)) {
|
||||
if (frontmatterWhitelist.includes(key)) {
|
||||
lines.push(`${key}: ${escapeYamlValue(value)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lines.push("---");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape YAML value for frontmatter.
|
||||
* Handles strings, numbers, booleans, null.
|
||||
*/
|
||||
function escapeYamlValue(value: unknown): string {
|
||||
if (value === null || value === undefined) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (typeof value === "boolean") {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
||||
if (typeof value === "number") {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
// If string contains special characters, quote it
|
||||
if (
|
||||
value.includes(":") ||
|
||||
value.includes("#") ||
|
||||
value.includes("|") ||
|
||||
value.includes(">") ||
|
||||
value.includes("<") ||
|
||||
value.includes("&") ||
|
||||
value.includes("*") ||
|
||||
value.includes("!") ||
|
||||
value.includes("%") ||
|
||||
value.includes("@") ||
|
||||
value.includes("`") ||
|
||||
value.includes('"') ||
|
||||
value.includes("'") ||
|
||||
value.includes("\n") ||
|
||||
value.trim() !== value ||
|
||||
value.startsWith("[") ||
|
||||
value.startsWith("{")
|
||||
) {
|
||||
// Escape quotes and use double quotes
|
||||
const escaped = value.replace(/"/g, '\\"');
|
||||
return `"${escaped}"`;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// For objects/arrays, serialize as JSON string (quoted)
|
||||
try {
|
||||
const json = JSON.stringify(value);
|
||||
return `"${json.replace(/"/g, '\\"')}"`;
|
||||
} catch {
|
||||
return '""';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user