Skip to content

Commit b626a9b

Browse files
claudejsshin2022
authored andcommitted
Show web book progress in the hub and stamp the passport for it
The web book keeps finished chapters in cil-book-read and the last one in cil-book-last on the same origin. The hub now reads them: the book's entry shows how many chapters are done and leads with a continue button, and the passport gets a web book reader stamp once a chapter is finished. /#passport opens the passport so the book can link to it.
1 parent 213ffdd commit b626a9b

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ python3 scripts/builder_cards.py
8181

8282
## 활동 여권과 실험실
8383

84-
스탬프 정의는 `assets/js/passport.js`의 `STAMPS`에 있습니다. `kind: "auto"`는 허브가 알아서 찍고(`window.hubStamp("post")`), `kind: "self"`는 행사 후기, 강의 후기, 레포 댓글처럼 허브 밖에서 하는 일이라 방문자가 ‘했어요’를 눌러 찍습니다. 이미 받은 스탬프는 다시 주지 않고, 기록은 `localStorage`에만 남습니다. 교란 실험실(`lab.html`, `assets/js/lab.js`)의 데이터는 페이지에서 만드는 가상 사용자입니다.
84+
스탬프 정의는 `assets/js/passport.js`의 `STAMPS`에 있습니다. `kind: "auto"`는 허브가 알아서 찍고(`window.hubStamp("post")`), `kind: "self"`는 행사 후기, 강의 후기, 레포 댓글처럼 허브 밖에서 하는 일이라 방문자가 ‘했어요’를 눌러 찍습니다. 이미 받은 스탬프는 다시 주지 않고, 기록은 `localStorage`에만 남습니다. 웹북 독자 스탬프는 같은 도메인의 웹북이 남기는 `cil-book-read`(읽은 장)를 보고 찍고, 역 정보 창의 '내 진도'와 '이어 읽기'는 `cil-book-read`, `cil-book-last`를 읽습니다. `/#passport`로 들어오면 여권이 바로 열립니다. 교란 실험실(`lab.html`, `assets/js/lab.js`)의 데이터는 페이지에서 만드는 가상 사용자입니다.
8585

8686
## 이벤트 측정
8787

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
- **오늘의 한 문제:** 첫 화면 아래에 매일 한 문제가 바뀝니다. 사흘 연속으로 풀면 스탬프를 받습니다.
4343
- **교란 실험실:** 가상 사용자 800명으로 교란이 단순 비교를 얼마나 속이는지 슬라이더로 직접 움직여 봅니다. [실험실 열기](https://causalinferencelab.github.io/lab.html)
4444
- **연재:** 팀원이 쓰는 글을 모읍니다. 매주 월요일 ‘이번 주 포스트’가 바뀌고, 글쓴이를 작가 카드로 소개합니다.
45-
- **활동 여권:** 자료 읽기 같은 배우기 스탬프와 함께, 행사 사진 후기, 강의·책 후기, 레포 댓글, 러너 참여, 첫 기여, Builder 되기 스탬프를 모읍니다. 기록은 내 브라우저에만 남습니다.
45+
- **활동 여권:** 자료 읽기, 웹북 한 장 완독 같은 배우기 스탬프와 함께, 행사 사진 후기, 강의·책 후기, 레포 댓글, 러너 참여, 첫 기여, Builder 되기 스탬프를 모읍니다. 기록은 내 브라우저에만 남습니다.
4646
- **3문항으로 시작점 찾기:** 경험, 하는 일, 원하는 것을 고르면 볼 순서와 첫 자료를 추천합니다. [바로 해 보기](https://causalinferencelab.github.io/?quiz=1)
4747
- **상관일까, 인과일까?:** 데이터 상황 10개를 보고 상관인지 인과인지 고르는 2분짜리 게임입니다. 답마다 관련 웹북 장으로 이어집니다. [게임 하기](https://causalinferencelab.github.io/game.html)
4848
- **완주 카드:** 한 단계의 자료를 모두 학습 완료로 표시하면, 공유할 수 있는 완주 카드 이미지를 만들 수 있습니다.

‎assets/js/hub.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,22 @@
12731273
/* ---------- station dialog ---------- */
12741274
const dialog = () => $("#station-dialog");
12751275

1276+
/* Reading progress from the web book (same origin): finished chapters and the last one opened. */
1277+
function webbookProgress() {
1278+
try {
1279+
const read = JSON.parse(localStorage.getItem("cil-book-read") || "{}");
1280+
const last = JSON.parse(localStorage.getItem("cil-book-last") || "null");
1281+
const done = read && typeof read === "object" ? Object.keys(read).length : 0;
1282+
const ok = last && /^[A-Za-z0-9-]+$/.test(last.slug || "");
1283+
const total = ok && Number(last.total) > 0 ? Number(last.total) : 30;
1284+
return done || ok ? { done: Math.min(done, total), total, last: ok ? { slug: last.slug, label: String(last.label || "") } : null } : null;
1285+
} catch (e) { return null; }
1286+
}
1287+
12761288
function openStation(id, source, silent) {
12771289
const r = state.repos.get(id);
12781290
if (!r) return;
1291+
const book = r.repo === "Causal-Inference-with-Python" && r.site ? webbookProgress() : null;
12791292
state.openRepo = r;
12801293
if (!silent) { track("open_repo", { repo: r.repo, level: r.level || "", source: source || "hub" }); if (source !== "deeplink") stamp("first_open"); }
12811294
if (!silent && r.kind !== "paid") {
@@ -1294,11 +1307,14 @@
12941307
builders ? `<dt>Builder</dt><dd>${builders}</dd>` : "",
12951308
r.cohorts && r.cohorts.length ? `<dt>기수</dt><dd>${r.cohorts.join("·")}기</dd>` : "",
12961309
statusText[r.status] ? `<dt>상태</dt><dd title="${esc(statusText[r.status].split(": ")[1] || "")}">${esc(statusText[r.status].split(": ")[0])}</dd>` : "",
1310+
book ? `<dt>내 진도</dt><dd>${book.total}편 중 ${book.done}편 읽음</dd>` : "",
12971311
r.kind ? "" : `<dt>스타</dt><dd>${fmt(r.stars || 0)}</dd>`,
12981312
r.pushed ? `<dt>마지막 커밋</dt><dd>${dot(r.pushed.slice(0, 10))}</dd>` : ""
12991313
].join("");
13001314
const links = r.kind
13011315
? r.links.map((l, i) => `<a class="btn${i ? " ghost" : ""}" href="${esc(l.url)}" target="_blank" rel="noopener">${esc(l.label)}</a>`).join("")
1316+
: book && book.last
1317+
? `<a class="btn" href="${esc(r.site.replace(/\/?$/, "/") + book.last.slug + ".html")}">이어 읽기${book.last.label ? ` · ${esc(book.last.label)}` : ""}</a><a class="btn ghost" href="${esc(repoUrl(r))}" target="_blank" rel="noopener">GitHub에서 보기</a>`
13021318
: r.site && r.siteLabel
13031319
? `<a class="btn" href="${esc(r.site)}" target="_blank" rel="noopener">${esc(r.siteLabel)}</a><a class="btn ghost" href="${esc(repoUrl(r))}" target="_blank" rel="noopener">GitHub에서 보기</a>`
13041320
: `<a class="btn" href="${esc(repoUrl(r))}" target="_blank" rel="noopener">GitHub에서 보기</a>${r.site ? `<a class="btn ghost" href="${esc(r.site)}" target="_blank" rel="noopener">사이트 열기</a>` : ""}`;

‎assets/js/passport.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const STAMPS = [
1212
{ id: "first_open", group: "learn", kind: "auto", mark: "첫", name: "첫 걸음", how: "커리큘럼에서 자료 하나를 열어 보세요.", href: "/#curriculum" },
1313
{ id: "post", group: "learn", kind: "auto", mark: "글", name: "연재 독자", how: "연재 글을 하나 읽어 보세요.", href: "/#posts" },
14+
{ id: "webbook", group: "learn", kind: "auto", mark: "책", name: "웹북 독자", how: "웹북 『Python으로 하는 인과추론』에서 한 장을 끝까지 읽어 보세요.", href: "/Causal-Inference-with-Python/" },
1415
{ id: "builder", group: "learn", kind: "auto", mark: "B", name: "Builder 탐방", how: "Builder 세 명의 이력이나 페이지를 열어 보세요.", href: "/#contrib" },
1516
{ id: "comment", group: "together", kind: "self", mark: "말", name: "레포에 한마디", how: "관심 있는 레포에 질문이나 응원을 남겨 보세요.", go: `${REPO}/discussions`, goLabel: "토론 게시판" },
1617
{ id: "event_photo", group: "together", kind: "self", mark: "찰", name: "행사 사진 후기", how: "Data Forum 같은 팀 행사 사진과 한 줄 후기를 올려 보세요.", go: `${REPO}/discussions/new/choose`, goLabel: "후기 올리기" },
@@ -121,10 +122,25 @@
121122
if (toastEl && dlg && toastEl.parentNode !== dlg) dlg.appendChild(toastEl);
122123
}
123124
});
125+
/* #passport (the web book links here) opens the passport */
126+
function openFromHash() {
127+
if (location.hash !== "#passport") return;
128+
history.replaceState(history.state, "", location.pathname + location.search);
129+
passportDialog("link");
130+
const dlg = document.getElementById("passport-dialog");
131+
if (toastEl && dlg && toastEl.parentNode && toastEl.parentNode !== dlg) dlg.appendChild(toastEl);
132+
}
133+
window.addEventListener("hashchange", openFromHash);
124134
document.addEventListener("DOMContentLoaded", () => {
125135
paintCounts();
126136
/* a Builder page view counts toward the Builder stamp */
127137
const m = location.pathname.match(/^\/builders\/([^/]+)\.html$/);
128138
if (m) window.hubSeen("builders", m[1], 3, "builder");
139+
/* the web book (same origin) keeps finished chapters in cil-book-read: one is enough for the stamp */
140+
try {
141+
const read = JSON.parse(localStorage.getItem("cil-book-read") || "{}");
142+
if (read && typeof read === "object" && Object.keys(read).length) window.hubStamp("webbook");
143+
} catch (e) { /* storage unavailable */ }
144+
openFromHash();
129145
});
130146
})();

‎assets/js/track.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
const HUB_PATHS = /^\/(?:$|index\.html$|article\.html$|404\.html$|game\.html$|lab\.html$|assets\/|data\/|articles\/|builders\/|badges\/)/;
5353
const WEBBOOK = "Causal-Inference-with-Python";
5454
const SPOTS = [
55-
["#featured", "featured"], [".partner", "partner"], ["#station-dialog", "station"], ["#daily", "daily"],
55+
["#featured", "featured"], [".partner", "partner"], ["#station-dialog", "station"], ["#daily", "daily"], ["#posts", "posts"], ["#passport-dialog", "passport"],
5656
["#shelf, #week, .spot", "curriculum"], [".gm", "game"], [".lab", "lab"], [".bp", "builder_page"],
5757
[".reader, .prose", "article"], [".site-footer", "footer"], [".banner", "banner"]
5858
];

0 commit comments

Comments
 (0)