Update CSP to allow external fonts, scripts, and add corresponding test coverage
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
import {get} from "./api.js";
|
||||
|
||||
const grid = document.getElementById("personalityGrid");
|
||||
const icons = {spark:"✥", quill:"✒", code:"⌘", flask:"⚗", "book-open":"▤", logic:"∴"};
|
||||
const iconPaths = {
|
||||
spark: '<path d="M12 2.8 14.5 9.5 21.2 12l-6.7 2.5L12 21.2l-2.5-6.7L2.8 12l6.7-2.5L12 2.8Z"/><path d="m19 2 .8 2.2L22 5l-2.2.8L19 8l-.8-2.2L16 5l2.2-.8L19 2Z"/>',
|
||||
quill: '<path d="M20.8 3.2c-6.3-.4-11 2.3-13.2 7.1-1 2.1-.9 4.1-.5 5.7 1.6.4 3.6.5 5.7-.5 4.8-2.2 7.5-6.9 7.1-13.2Z"/><path d="M3 21c3.5-5.1 7.8-8.8 13-11.4M7.2 16.4l-3.4-.3M10.2 13.1l-.1-3.4"/>',
|
||||
code: '<path d="m8 7-5 5 5 5M16 7l5 5-5 5M14 4l-4 16"/>',
|
||||
flask: '<path d="M9 3h6M10 3v6l-5.8 9.5A2.3 2.3 0 0 0 6.2 22h11.6a2.3 2.3 0 0 0 2-3.5L14 9V3M7.5 16h9"/>',
|
||||
"book-open": '<path d="M12 7.2C9.8 5.4 6.5 5 3 5.8v13c3.5-.8 6.8-.4 9 1.4m0-13c2.2-1.8 5.5-2.2 9-1.4v13c-3.5-.8-6.8-.4-9 1.4m0-13v13"/>',
|
||||
logic: '<circle cx="6" cy="6" r="2"/><circle cx="18" cy="6" r="2"/><circle cx="12" cy="18" r="2"/><path d="M8 7.2 10.8 16M16 7.2 13.2 16M8 6h8"/>'
|
||||
};
|
||||
const result = await get("/personalities");
|
||||
if (result.error) {
|
||||
grid.textContent = result.error;
|
||||
} else {
|
||||
for (const item of result.personalities || []) {
|
||||
const card = document.createElement("article");
|
||||
card.className = "settings-panel personality-card";
|
||||
card.className = "personality-card";
|
||||
card.style.setProperty("--personality-accent", item.accentColor);
|
||||
const icon = document.createElement("div");
|
||||
const icon = document.createElement("span");
|
||||
icon.className = "personality-icon";
|
||||
icon.textContent = icons[item.icon] || "✦";
|
||||
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
svg.setAttribute("viewBox", "0 0 24 24");
|
||||
svg.setAttribute("fill", "none");
|
||||
svg.setAttribute("stroke", "currentColor");
|
||||
svg.setAttribute("stroke-width", "1.65");
|
||||
svg.setAttribute("stroke-linecap", "round");
|
||||
svg.setAttribute("stroke-linejoin", "round");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.innerHTML = iconPaths[item.icon] || iconPaths.spark;
|
||||
icon.append(svg);
|
||||
icon.title = item.name;
|
||||
icon.setAttribute("aria-hidden", "true");
|
||||
const specialization = document.createElement("p");
|
||||
@@ -20,9 +36,8 @@ if (result.error) {
|
||||
specialization.textContent = `${item.specialization}${item.isDefault ? " · Default" : ""}`;
|
||||
const name = document.createElement("h2");
|
||||
name.textContent = item.name;
|
||||
name.title = `Inspired by ${item.historicalInspiration}`;
|
||||
const description = document.createElement("p");
|
||||
description.className = "subtitle";
|
||||
description.className = "personality-description";
|
||||
description.textContent = item.description;
|
||||
const details = document.createElement("details");
|
||||
details.className = "personality-details";
|
||||
@@ -36,10 +51,13 @@ if (result.error) {
|
||||
details.append(summary, longDescription, inspiration);
|
||||
const action = document.createElement("a");
|
||||
action.className = "primary-action";
|
||||
action.textContent = "Start Chat";
|
||||
action.innerHTML = '<span>Start a chat</span><span aria-hidden="true">→</span>';
|
||||
action.setAttribute("aria-label", `Start a chat with ${item.name}, ${item.specialization}`);
|
||||
action.href = `/app/chats/new?personality=${encodeURIComponent(item.id)}`;
|
||||
card.append(icon, specialization, name, description, details, action);
|
||||
const identity = document.createElement("div");
|
||||
identity.className = "personality-identity";
|
||||
identity.append(specialization, name);
|
||||
card.append(icon, identity, description, details, action);
|
||||
grid.append(card);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user