<%* // Gemini API 키 설정 const apiKey = “AIzaSyD1I2n71xDMRlQ2RDrOOJlbV0iHLl4s1sA”; const prompt = `You are an expert in generating an appropriate topics properties that will be used in Obsidian Note. Your mission is to generate one or more topics suitable for given content.

Your generated output must be comma-separated values.

Example Output:

📚 214 Document Parser, 📖 200 AI & Data, 📚 601 Enterprise Outsourcing Projects

Here’s a list of possible substitutions for topics. You must use these topics listed below:

Topics:

[Note] Write your Final Answer in Korean. DO NOT narrate, just write the output without any markdown formatting of wrapping.

Generated topics must be related to the content. Otherwise, you will be penalized. `; %>

<%_* // frontmatter의 topics 속성을 업데이트하는 함수 // @param file: 대상 파일 객체 // @param newTopics: 새로운 토픽 문자열 (쉼표로 구분된 값)

const processTopics = async (file, newTopics) => {   await tp.app.fileManager.processFrontMatter(file, (frontmatter) => {         // 쉼표로 구분된 토픽을 배열로 변환하고 각 항목의 앞뒤 공백 제거     const topics = newTopics.split(’,‘).map(topic => topic.trim());

    // frontmatter의 topics 속성 업데이트     frontmatter.topics = topics.map(topic => ${topic});   }); }; _%>

<%* // 현재 노트의 내용을 가져옵니다 const content = tp.file.content;

// 토픽 생성을 위한 curl 명령 실행 const res = await fetch(https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${apiKey}, { method: “POST”, headers: { “Content-Type”: “application/json”, //“Authorization”: Bearer ${apiKey} // 이게 필요한 경우에만 사용하세요 }, body: JSON.stringify({ contents: [ { parts: [ { text: ${prompt}\n\nHere is the content of the note:\n${content} } ] } ] }) });

// 토픽을 생성하고 파일에 적용 const data = await res.json(); const topics = data.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || “토픽 생성 실패”; console.log(JSON.stringify(data, null, 2)); const file = tp.config.target_file; await processTopics(file, topics); %>