Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions assets/css/hub.css
Original file line number Diff line number Diff line change
Expand Up @@ -2609,3 +2609,28 @@ body.has-helper .site-footer { padding-bottom: calc(96px + env(safe-area-inset-b
.hp-say-x:hover { background: var(--surface-2); color: var(--ink); }
@media (prefers-reduced-motion: no-preference) { .hp-say:not([hidden]) { animation: hp-in .3s ease-out both; } }
.hp-msg.typing-now .hp-links, .hp-msg.typing-now .hp-ai { visibility: hidden; }

/* a warmer helper: the mascot's own colour, its face beside what it says, softer bubbles for the reader */
.hp { --mint: #2f9e76; --mint-ink: #1b6e50; --mint-soft: color-mix(in srgb, #3dbb8c 13%, var(--surface)); }
.hp-panel { border-radius: 22px; }
.hp-head { background: linear-gradient(180deg, var(--mint-soft), var(--surface)); border-bottom-color: color-mix(in srgb, #3dbb8c 22%, var(--rule)); }
.hp-head h2 { display: grid; gap: 1px; font-size: 16px; }
.hp-head h2 span { font-size: 12px; font-weight: 600; color: var(--muted); }
.hp-msg.bot { position: relative; margin-left: 38px; background: var(--mint-soft); border-radius: 16px 16px 16px 6px; max-width: calc(100% - 38px); }
.hp-msg.bot::before { content: ""; position: absolute; left: -40px; bottom: -2px; width: 34px; height: 29px; background: url("../img/mascot.webp") center / contain no-repeat; }
.hp-msg.me { background: var(--surface-2); color: var(--ink); border-radius: 16px 16px 6px 16px; }
.hp-links li { border: 1px solid color-mix(in srgb, #3dbb8c 18%, var(--rule)); }
.hp-links a:hover { color: var(--mint-ink); }
.hp-sug button { border-radius: 999px; padding: 7px 12px; border-color: color-mix(in srgb, #3dbb8c 30%, var(--rule)); }
.hp-sug button:hover { border-color: var(--mint); color: var(--mint-ink); }
.hp-send { background: var(--mint); }
.hp-form textarea:focus { border-color: var(--mint); }
.hp-claude { color: var(--mint-ink); }
.hp-say { border-color: color-mix(in srgb, #3dbb8c 30%, var(--rule)); }
.hp-say::after { border-color: color-mix(in srgb, #3dbb8c 30%, var(--rule)); }
.hp-say.bye { width: auto; padding-right: 14px; }
.hp-say.bye .hp-say-x { display: none; }
.hp-say-acts button { border-color: color-mix(in srgb, #3dbb8c 30%, var(--rule)); background: var(--mint-soft); }
.hp-say-acts button:hover { border-color: var(--mint); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hp { --mint: #4fd1a1; --mint-ink: #7fe3bf; } }
:root[data-theme="dark"] .hp { --mint: #4fd1a1; --mint-ink: #7fe3bf; }
58 changes: 39 additions & 19 deletions assets/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
/* what the mascot says on its own: once per visit each, and never again after the reader closes a bubble */
const LINES = {
hub: [
{ id: "hello", text: "안녕하세요! 인과추론이나 A/B 테스트, 어디서부터 볼지 같이 찾아 드릴게요.", acts: [["처음이에요", "인과추론이 처음인데 뭐부터 봐요?"], ["용어가 궁금해요", ""]] },
{ id: "topics", when: "#topics", text: "모르는 주제나 용어가 있으면 저한테 바로 물어봐도 돼요.", acts: [["SRM이 뭐예요?", "SRM이 뭐예요?"], ["이중차분법이 뭐예요?", "이중차분법이 뭐예요?"]] }
{ id: "hello", text: "안녕하세요, 반가워요! 어디서부터 볼지 막막하면 저를 불러 주세요. 같이 골라 봐요.", acts: [["처음 왔어요", "처음인데 뭐부터 볼까요?"], ["궁금한 말이 있어요", ""]] },
{ id: "topics", when: "#topics", text: "여기가 제 자리예요. 낯선 말이 보이면 저한테 툭 던져 주세요.", acts: [["SRM이 뭐예요?", "SRM이 뭐예요?"], ["이중차분법이 뭐예요?", "이중차분법이 뭐예요?"]] }
],
library: [
{ id: "hello", text: "찾는 주제가 있나요? 이름을 몰라도 상황을 적어 주면 찾아 드릴게요.", acts: [["쿠폰 효과를 재고 싶어요", "쿠폰 효과를 재고 싶어요"], ["A/B 테스트는 처음이에요", "A/B 테스트는 처음이에요"]] }
{ id: "hello", text: "어서 와요! 이름이 기억 안 나도 괜찮아요. 하고 싶은 걸 그냥 말해 주세요.", acts: [["쿠폰 효과를 재고 싶어요", "쿠폰 효과를 재고 싶어요"], ["A/B 테스트는 처음이에요", "A/B 테스트는 처음이에요"]] }
],
article: [
{ id: "read", when: "half", text: "읽다가 모르는 말이 있었나요? 적어 주면 설명할 자료를 찾아 드릴게요.", acts: [["물어보기", ""]] }
{ id: "read", when: "half", text: "여기까지 읽느라 고생했어요. 걸리는 말 있었어요? 같이 찾아봐요.", acts: [["하나 있어요", ""]] }
]
};
const page = /library\.html$/.test(location.pathname) ? "library" : /article\.html$/.test(location.pathname) ? "article" : "hub";
const SUGGEST = {
hub: ["인과추론이 처음인데 뭐부터 봐요?", "A/B 테스트 결과를 믿어도 되는지 어떻게 확인해요?", "이중차분법이 뭐예요?"],
hub: ["처음인데 뭐부터 볼까요?", "A/B 테스트 결과, 믿어도 될까요?", "이중차분법이 뭐예요?"],
library: ["A/B 테스트는 처음이에요", "SRM이 뭐예요?", "쿠폰 효과를 재고 싶어요"],
article: ["이 글에 나온 용어를 설명해 주세요", "이 주제를 더 공부하려면?", "실험군과 대조군 차이가 뭐예요?"]
article: ["이 글에 나온 말이 궁금해요", "이 주제 더 공부하고 싶어요", "실험군이랑 대조군이 뭐가 달라요?"]
};
const SRC = {
"Causal-Inference-with-Python": "웹북", "causal-studio": "Causal Studio", "causal-inference-lecture": "실무자 특강",
Expand Down Expand Up @@ -98,14 +98,22 @@
return /[136780lmnLMN]$/.test(base) ? "은" : "는";
}

/* a different first word now and then, picked by the question so the same question gets the same reply */
const lead = (q, ko, en) => {
const n = [...String(q)].reduce((a, c) => a + c.charCodeAt(0), 0) % 3;
if (n === 0) return `아, ${ko}요! 영어로는 “${en}”라고 써요.`;
if (n === 1) return `좋은 질문이에요! ${ko}${topicMark(ko)} 영어로 “${en}”라고 써요.`;
return `그거 저도 처음에 헷갈렸어요. ${ko}${topicMark(ko)} 영어로 “${en}”라고 써요.`;
};

function answer(q) {
const links = [];
let text = "", matched = "none";
const term = findTerm(q), topic0 = findTopic(q);
if (isStart(q)) {
const t = topicById(isExp(q) || (topic0 && topic0.shelf === "exp") ? "ab-basics" : "why-causal");
if (t) {
text = `처음이라면 ‘${t.name}’부터 보세요. 아래 두 개면 감을 잡을 수 있어요.`;
text = t.id === "ab-basics" ? "A/B 테스트가 처음이면 이 두 개부터 같이 봐요. 실험 하나가 어떻게 굴러가는지 금방 감이 와요." : "처음이면 상관과 인과가 왜 다른지부터 봐요. 짧은 영상 하나랑 웹북 1장이면 충분해요.";
t.items.slice(0, 2).forEach((x) => links.push({ title: x.title, url: x.url, note: `${KIND[x.kind] || ""} · ${SRC[x.repo] || ""}` }));
links.push({ title: `${t.name} 자료 모두 보기`, url: `library.html#${t.id}`, note: "자료실" });
matched = `start:${t.id}`;
Expand All @@ -115,7 +123,7 @@
/* the chapter to read: one the topic also lists, else the first the glossary gives */
const inTopic = t0 ? t0.items.map((x) => x.url) : [];
const ch = (term.chapters || []).find((c) => inTopic.includes(`${BOOK}${c.slug}.html`)) || (term.chapters || [])[0];
text = `‘${term.ko}’${topicMark(term.ko)} 영어로 ${term.en}입니다.${ch ? ` 웹북 ${ch.num} ‘${ch.title}’에서 자세히 다뤄요.` : ""}`;
text = `${lead(q, term.ko, term.en)}${ch ? ` 웹북 ${ch.num} ‘${ch.title}’에 차근차근 나와요.` : " 제가 아는 자료 중엔 아래가 제일 좋아요."}`;
if (ch) links.push({ title: `웹북 ${ch.num}: ${ch.title}`, url: `${BOOK}${ch.slug}.html`, note: "글 · 웹북" });
const t = t0;
if (t) {
Expand All @@ -127,12 +135,12 @@
}
matched = `term:${term.id}`;
} else if (topic0) {
text = `‘${topic0.name}’ 주제에 맞는 자료가 있어요. ${topic0.about.split(". ")[0].replace(/\.$/, "")}.`;
text = `그거라면 ‘${topic0.name}’ 쪽 자료가 딱이에요. 먼저 볼 만한 걸 골라 왔어요.`;
topic0.items.slice(0, 2).forEach((x) => links.push({ title: x.title, url: x.url, note: `${KIND[x.kind] || ""} · ${SRC[x.repo] || ""}` }));
links.push({ title: `${topic0.name} 자료 모두 보기`, url: `library.html#${topic0.id}`, note: "자료실" });
matched = `topic:${topic0.id}`;
} else {
text = "자료실에서 딱 맞는 자료를 찾지 못했어요. 아래 버튼으로 AI에게 이어서 물어보세요. 질문을 바꿔 다시 적어도 좋아요.";
text = "음, 제 자료실엔 딱 맞는 게 아직 없네요. 미안해요! 다르게 물어봐 주거나, 아래에서 Claude한테 같이 물어봐요.";
}
return { text, links: links.slice(0, 3), matched };
}
Expand Down Expand Up @@ -235,14 +243,16 @@
if (!q) return;
say(esc(q), "me");
input.value = ""; grow();
const wait = say('<span class="hp-dots" aria-label="찾는 중"><i></i><i></i><i></i></span>', "bot");
const wait = say('<span class="hp-dots" aria-label="찾아보는 중이에요"><i></i><i></i><i></i></span>', "bot");
typing(true);
await Promise.all([load(), new Promise((r) => setTimeout(r, reduced() ? 0 : 450))]);
typing(false);
const a = answer(q);
const p = prompt(q, a.links);
/* only the newest reply offers to carry on with Claude; older ones stay quiet */
log.querySelectorAll(".hp-ai").forEach((el) => el.remove());
wait.innerHTML = `<p class="hp-said"></p>${a.links.length ? `<ul class="hp-links">${a.links.map((l) => `<li><a href="${esc(l.url)}"${/^https?:/.test(l.url) && !l.url.startsWith(SITE) ? ' target="_blank" rel="noopener"' : ""} data-event="helper_click" data-event-params='${esc(JSON.stringify({ matched: a.matched, page }))}'>${esc(l.title)}</a><span>${esc(l.note)}</span></li>`).join("")}</ul>` : ""}
<p class="hp-ai"><a class="hp-claude" href="https://claude.ai/new?q=${encodeURIComponent(p)}" target="_blank" rel="noopener" data-event="helper_handoff" data-event-params='${esc(JSON.stringify({ target: "claude", matched: a.matched, page }))}'>Claude에게 이어서 묻기<span aria-hidden="true"> ↗</span></a><button type="button" class="hp-copy" data-copy="${esc(p)}" data-label="프롬프트 복사">프롬프트 복사</button></p>`;
<p class="hp-ai"><a class="hp-claude" href="https://claude.ai/new?q=${encodeURIComponent(p)}" target="_blank" rel="noopener" data-event="helper_handoff" data-event-params='${esc(JSON.stringify({ target: "claude", matched: a.matched, page }))}'>Claude랑 더 이야기하기<span aria-hidden="true"> ↗</span></a><button type="button" class="hp-copy" data-copy="${esc(p)}" data-label="질문 복사하기">질문 복사하기</button></p>`;
wait.querySelector(".hp-copy").addEventListener("click", () => track("helper_handoff", { target: "copy", matched: a.matched, page }));
/* the links wait until the mascot has finished typing its line */
wait.classList.add("typing-now");
Expand All @@ -262,17 +272,27 @@
load();
if (!log.children.length) {
const first = say(`<p class="hp-said"></p><p class="hp-sug" hidden>${SUGGEST[page].map((s) => `<button type="button" data-ask="${esc(s)}">${esc(s)}</button>`).join("")}</p>`, "bot");
typeOut(first.querySelector(".hp-said"), page === "article" ? "글을 읽다가 모르는 말이 나오면 적어 주세요." : "무엇을 공부하고 싶나요? 주제나 모르는 용어를 적으면 자료실에서 맞는 자료를 찾아 드릴게요.")
typeOut(first.querySelector(".hp-said"), page === "article" ? "반가워요! 글에서 걸리는 말이 있으면 편하게 적어 주세요. 같이 찾아볼게요." : "반가워요! 공부하고 싶은 거나 낯선 말을 편하게 적어 주세요. 제가 아는 자료 중에 딱 맞는 걸 골라 올게요.")
.then(() => { first.querySelector(".hp-sug").hidden = false; log.scrollTop = log.scrollHeight; });
}
setTimeout(() => input.focus(), 30);
track("helper_open", { page });
}
let waved = false;
function close() {
if (panel.hidden) return;
panel.hidden = true;
opener.setAttribute("aria-expanded", "false");
root.classList.remove("open");
/* a small goodbye, once per page and only if the reader has not asked for quiet */
if (!waved && !quiet() && log.querySelector(".hp-msg.me")) {
waved = true;
sayEl.hidden = false; sayEl.classList.add("bye");
sayEl.querySelector(".hp-say-acts").innerHTML = "";
typeOut(sayEl.querySelector(".hp-say-t"), "언제든 또 불러 주세요!");
clearTimeout(sayTimer);
sayTimer = setTimeout(() => { sayEl.classList.remove("bye"); hush(false); }, 2800);
}
opener.focus();
}

Expand All @@ -281,19 +301,19 @@
root.className = "hp";
root.innerHTML = `
<section class="hp-panel" id="hp-panel" role="dialog" aria-modal="false" aria-labelledby="hp-title" hidden>
<header class="hp-head"><img src="assets/img/mascot.webp" alt="" width="40" height="34"><h2 id="hp-title">자료실 도우미</h2>
<button type="button" class="hp-x" aria-label="도우미 닫기"><svg viewBox="0 0 16 16" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" d="M3.5 3.5l9 9m0-9l-9 9"/></svg></button></header>
<header class="hp-head"><img src="assets/img/mascot.webp" alt="" width="40" height="34"><h2 id="hp-title">같이 찾아봐요<span>인과추론팀 자료실 지킴이</span></h2>
<button type="button" class="hp-x" aria-label="닫기"><svg viewBox="0 0 16 16" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" d="M3.5 3.5l9 9m0-9l-9 9"/></svg></button></header>
<ol class="hp-log" aria-live="polite"></ol>
<form class="hp-form"><label class="sr-only" for="hp-q">도우미에게 묻기</label>
<textarea id="hp-q" rows="1" maxlength="300" placeholder="예: 쿠폰 효과를 어떻게 재요?" enterkeyhint="send"></textarea>
<form class="hp-form"><label class="sr-only" for="hp-q">자료실 지킴이에게 물어보기</label>
<textarea id="hp-q" rows="1" maxlength="300" placeholder="편하게 적어 주세요" enterkeyhint="send"></textarea>
<button type="submit" class="hp-send" aria-label="보내기"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 10h12M10 4l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg></button></form>
<p class="hp-note">답은 자료실 안에서 찾습니다. 적은 내용은 저장하지 않아요.</p>
<p class="hp-note">적어 준 말은 어디에도 저장하지 않아요.</p>
</section>
<div class="hp-say" role="status" hidden>
<button type="button" class="hp-say-x" aria-label="말풍선 닫기, 이번 방문 동안 다시 말 걸지 않기"><svg viewBox="0 0 16 16" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" d="M4 4l8 8m0-8l-8 8"/></svg></button>
<p class="hp-say-t"></p><p class="hp-say-acts"></p>
</div>
<button type="button" class="hp-open" aria-controls="hp-panel" aria-expanded="false" aria-label="자료실 도우미에게 묻기"><span class="hp-mascot" aria-hidden="true"><img src="assets/img/mascot-blank.webp" alt="" width="84" height="72">${SCREEN}</span></button>`;
<button type="button" class="hp-open" aria-controls="hp-panel" aria-expanded="false" aria-label="자료실 지킴이에게 물어보기"><span class="hp-mascot" aria-hidden="true"><img src="assets/img/mascot-blank.webp" alt="" width="84" height="72">${SCREEN}</span></button>`;
document.body.appendChild(root);
document.body.classList.add("has-helper");
panel = root.querySelector(".hp-panel"); log = root.querySelector(".hp-log"); input = root.querySelector("#hp-q"); opener = root.querySelector(".hp-open");
Expand Down
2 changes: 1 addition & 1 deletion data/featured.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"title": "ccwr",
"desc": "Target trial emulation을 위한 R 패키지",
"repo": "ccwr",
"url": "https://github.com/CausalInferenceLab/ccwr"
"url": "https://causalinferencelab.github.io/ccwr/"
}
]
2 changes: 1 addition & 1 deletion data/topics.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@
"kind": "code",
"repo": "ccwr",
"title": "ccwr: Clone-Censor-Weight R 패키지",
"url": "https://github.com/CausalInferenceLab/ccwr"
"url": "https://causalinferencelab.github.io/ccwr/"
},
{
"kind": "read",
Expand Down