Introduce highlights option

This commit is contained in:
2025-06-13 22:47:05 +03:00
parent 6911cfaaa4
commit 7b6369fa0f
6 changed files with 42 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ interface FormData {
language: string; language: string;
units: string; units: string;
tone: string[]; tone: string[];
highlights: string[];
} }
const preferences = useState<FormData>("preferences", () => ({ const preferences = useState<FormData>("preferences", () => ({
@@ -21,6 +22,7 @@ const preferences = useState<FormData>("preferences", () => ({
language: "English", language: "English",
units: "Metric", units: "Metric",
tone: [], tone: [],
highlights: [],
})); }));
const { data, status } = useFetch("/api/preferences", { const { data, status } = useFetch("/api/preferences", {
@@ -149,6 +151,22 @@ const saveOp = watchPausable(
/> />
</template> </template>
</CardField> </CardField>
<CardField>
<template #title> Highlight </template>
<template #description>
Choose what Ghostwriter should focus on.
</template>
<template #value>
<USelect
multiple
class="min-w-28 max-w-64"
:items="highlights"
v-model="preferences.highlights"
placeholder="None specified (Use all)"
/>
</template>
</CardField>
</div> </div>
</UCard> </UCard>
</UContainer> </UContainer>

View File

@@ -1,5 +1,6 @@
import * as z from "zod"; import * as z from "zod";
import { import {
availableHighlights,
availableLanguages, availableLanguages,
availableTones, availableTones,
availableUnits, availableUnits,
@@ -10,6 +11,7 @@ const bodySchema = z.strictObject({
language: z.enum(availableLanguages), language: z.enum(availableLanguages),
units: z.enum(availableUnits), units: z.enum(availableUnits),
tone: z.array(z.enum(availableTones)), tone: z.array(z.enum(availableTones)),
highlights: z.array(z.enum(availableHighlights)),
}); });
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
@@ -26,6 +28,7 @@ export default defineEventHandler(async (event) => {
language: body.language, language: body.language,
units: body.units, units: body.units,
tone: body.tone, tone: body.tone,
highlights: body.highlights,
}, },
}) })
.where(eq(tables.preferences.userId, session.user.id)) .where(eq(tables.preferences.userId, session.user.id))

View File

@@ -34,12 +34,14 @@ export const preferences = pgTable("preferences", {
language: string; language: string;
units: "Imperial" | "Metric"; units: "Imperial" | "Metric";
tone?: string[]; tone?: string[];
highlights?: string[];
}>() }>()
.$defaultFn(() => ({ .$defaultFn(() => ({
enabled: true, enabled: true,
language: "English", language: "English",
units: "Metric", units: "Metric",
tone: [], tone: [],
highlights: [],
})), })),
}); });

View File

@@ -1,7 +1,7 @@
import { chain, draw, get, isEmpty, omit, pick, tryit } from "radash"; import { chain, draw, get, isEmpty, omit, pick, tryit } from "radash";
import { safeDestr } from "destr"; import { safeDestr } from "destr";
import { User } from "./drizzle"; import { User } from "./drizzle";
import { availableTones } from "~/shared/constants"; import { availableHighlights, availableTones } from "~/shared/constants";
const promo = "Written by https://ghostwriter.rocks 👻"; const promo = "Written by https://ghostwriter.rocks 👻";
@@ -120,21 +120,19 @@ export const createActivityContent = async ({
? (draw(availableTones) as string) ? (draw(availableTones) as string)
: draw(user.preferences.data!.tone!); : draw(user.preferences.data!.tone!);
const length = draw([ const highlight = isEmpty(user.preferences.data?.highlights)
"short", ? (draw(availableHighlights) as string)
"short", : draw(user.preferences.data!.highlights!);
"short",
"medium", const length = draw(["short", "medium", "a-little-more-than-medium"]);
"a-little-more-than-medium",
]);
const prompt = ` const prompt = `
Generate a short title and a ${length}-lengthed description for my strava activity. Use my preferred language and unit system. Generate a short title and a ${length}-lengthed description for my strava activity. Use my preferred language and unit system.
Try to not exaggerate as I am using Strava often and I want my activites to be unique and easy to read. Don't say things like nothing too fancy or wild. Try to not exaggerate as I am using Strava often and I want my activites to be unique and easy to read. Don't say things like nothing too fancy or wild.
Use a little bit of ${tone} tone to make things less boring. Highlight any PR only if available, do not mention them if no PRs. Use a little bit of ${tone} tone to make things less boring. Highlight ${highlight} properties if available.
Maybe comment if any interesting fact in comparison to previous activities. Maybe comment if any interesting fact in comparison to previous activities.
Add #${tone} at the end of the description. Depending the length of the description, maybe add more hashtags. Add #${tone} and #${highlight} at the end of the description. Depending the length of the description, maybe add more hashtags.
Language: ${user?.preferences.data.language} Language: ${user?.preferences.data.language}
Unit system: ${user?.preferences.data.units} Unit system: ${user?.preferences.data.units}

View File

@@ -22,3 +22,11 @@ export const availableLanguages = [
] as const; ] as const;
export const availableUnits = ["Imperial", "Metric"] as const; export const availableUnits = ["Imperial", "Metric"] as const;
export const availableHighlights = [
"Athletic",
"Area Exploration",
"Social",
"Mood",
"Conditions",
] as const;

View File

@@ -2,6 +2,7 @@ import {
availableLanguages, availableLanguages,
availableTones, availableTones,
availableUnits, availableUnits,
availableHighlights,
} from "~/shared/constants"; } from "~/shared/constants";
export const languages = ref(availableLanguages); export const languages = ref(availableLanguages);
@@ -9,3 +10,5 @@ export const languages = ref(availableLanguages);
export const tones = ref(availableTones); export const tones = ref(availableTones);
export const units = ref(availableUnits); export const units = ref(availableUnits);
export const highlights = ref(availableHighlights);