fix context sentences in YAML to ensure vocab emphasis

This commit is contained in:
polv committed 2026-10-31 12:44:24 +07:00
1 parent 363a728fc3
commit 8e8e018445
19 files changed
+79 -56

No files matched your search

@@ -146,7 +146,7 @@ import {
import yaml from "yaml";
import SentenceAudio from "./SentenceAudio.vue";
import { supabase } from "../supabase.ts";
import { IVoc, Voc } from "../types.ts";
import { fmValueParser, IVoc, Voc } from "../types.ts";
import { LLMstream } from "../llm.ts";
import MarkdownIt from "markdown-it";
@@ -263,7 +263,7 @@ watch(sent_ko, () => {
const vocabulary: Record<string, IVoc[]> = {};
for (const [k, vs] of Object.entries(
frontmatter.value[fmKey] as Record<string, IVoc[]>,
fmValueParser.parse(frontmatter.value[fmKey]),
)) {
vocabulary[k] = [...(vocabulary[k] || []), ...vs];
+37 -14
View File
@@ -1,17 +1,40 @@
import * as z from "zod";
export const Voc = z.object({
ko: z.string(),
ko_text: z.string().optional(),
audio: z.string().optional(),
en: z.string(),
get usage() {
return z.array(Voc).optional();
},
notes: z.union([z.string(), z.array(z.string())]).optional(),
get examples() {
return z.array(Voc).optional();
},
});
// 1. Define the interface manually (do not use z.infer here)
export interface IVoc {
ko: string;
ko_text?: string;
audio?: string;
en: string;
usage?: IVoc[];
notes?: string | string[];
examples?: IVoc[];
}
export type IVoc = z.infer<typeof Voc>;
// 2. Annotate the schema with the manually defined interface
export const Voc: z.ZodType<IVoc> = z.lazy(() =>
z.object({
ko: z.string(),
ko_text: z.string().optional(),
audio: z.string().optional(),
en: z.string(),
usage: z.array(Voc).optional(),
notes: z.union([z.string(), z.array(z.string())]).optional(),
examples: z
.array(Voc)
.superRefine((val, ctx) => {
for (const x of val) {
if (!isEmp(x.ko)) {
ctx.addIssue(`${JSON.stringify(x)} must contain **emp** text`);
}
}
})
.optional(),
}),
);
export const fmValueParser = z.record(z.string(), z.array(Voc));
function isEmp(s: string) {
return /\*\*.+\*\*/.test(s);
}