From 7b6369fa0ff2ce04a54623c11100bddb389a6c49 Mon Sep 17 00:00:00 2001 From: Marios Antonoudiou Date: Fri, 13 Jun 2025 22:47:05 +0300 Subject: [PATCH] Introduce highlights option --- pages/index.vue | 18 ++++++++++++++++++ server/api/preferences.put.ts | 3 +++ server/database/schema.ts | 2 ++ server/utils/create-content.ts | 18 ++++++++---------- shared/constants.ts | 8 ++++++++ utils/model.ts | 3 +++ 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index cb9693d..b7319c9 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -14,6 +14,7 @@ interface FormData { language: string; units: string; tone: string[]; + highlights: string[]; } const preferences = useState("preferences", () => ({ @@ -21,6 +22,7 @@ const preferences = useState("preferences", () => ({ language: "English", units: "Metric", tone: [], + highlights: [], })); const { data, status } = useFetch("/api/preferences", { @@ -149,6 +151,22 @@ const saveOp = watchPausable( /> + + + + + + diff --git a/server/api/preferences.put.ts b/server/api/preferences.put.ts index 6708f1f..f4b9d53 100644 --- a/server/api/preferences.put.ts +++ b/server/api/preferences.put.ts @@ -1,5 +1,6 @@ import * as z from "zod"; import { + availableHighlights, availableLanguages, availableTones, availableUnits, @@ -10,6 +11,7 @@ const bodySchema = z.strictObject({ language: z.enum(availableLanguages), units: z.enum(availableUnits), tone: z.array(z.enum(availableTones)), + highlights: z.array(z.enum(availableHighlights)), }); export default defineEventHandler(async (event) => { @@ -26,6 +28,7 @@ export default defineEventHandler(async (event) => { language: body.language, units: body.units, tone: body.tone, + highlights: body.highlights, }, }) .where(eq(tables.preferences.userId, session.user.id)) diff --git a/server/database/schema.ts b/server/database/schema.ts index 0e36e4f..f0d5a5e 100644 --- a/server/database/schema.ts +++ b/server/database/schema.ts @@ -34,12 +34,14 @@ export const preferences = pgTable("preferences", { language: string; units: "Imperial" | "Metric"; tone?: string[]; + highlights?: string[]; }>() .$defaultFn(() => ({ enabled: true, language: "English", units: "Metric", tone: [], + highlights: [], })), }); diff --git a/server/utils/create-content.ts b/server/utils/create-content.ts index 7a1179a..c66159e 100644 --- a/server/utils/create-content.ts +++ b/server/utils/create-content.ts @@ -1,7 +1,7 @@ import { chain, draw, get, isEmpty, omit, pick, tryit } from "radash"; import { safeDestr } from "destr"; import { User } from "./drizzle"; -import { availableTones } from "~/shared/constants"; +import { availableHighlights, availableTones } from "~/shared/constants"; const promo = "Written by https://ghostwriter.rocks 👻"; @@ -120,21 +120,19 @@ export const createActivityContent = async ({ ? (draw(availableTones) as string) : draw(user.preferences.data!.tone!); - const length = draw([ - "short", - "short", - "short", - "medium", - "a-little-more-than-medium", - ]); + const highlight = isEmpty(user.preferences.data?.highlights) + ? (draw(availableHighlights) as string) + : draw(user.preferences.data!.highlights!); + + const length = draw(["short", "medium", "a-little-more-than-medium"]); const prompt = ` 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. - 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. - 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} Unit system: ${user?.preferences.data.units} diff --git a/shared/constants.ts b/shared/constants.ts index e881171..a96530c 100644 --- a/shared/constants.ts +++ b/shared/constants.ts @@ -22,3 +22,11 @@ export const availableLanguages = [ ] as const; export const availableUnits = ["Imperial", "Metric"] as const; + +export const availableHighlights = [ + "Athletic", + "Area Exploration", + "Social", + "Mood", + "Conditions", +] as const; diff --git a/utils/model.ts b/utils/model.ts index 23e7b55..9d4cac4 100644 --- a/utils/model.ts +++ b/utils/model.ts @@ -2,6 +2,7 @@ import { availableLanguages, availableTones, availableUnits, + availableHighlights, } from "~/shared/constants"; export const languages = ref(availableLanguages); @@ -9,3 +10,5 @@ export const languages = ref(availableLanguages); export const tones = ref(availableTones); export const units = ref(availableUnits); + +export const highlights = ref(availableHighlights);