Skip to content

Commit 7152bb4

Browse files
supachai-jclaude
andcommitted
Make the book engaging: narrative voice + Mermaid diagrams + illustrations
- Rewrite part1/history.md as a story ("the 60-year quest to make machines remember"), six acts with scene-setting, protagonists, tension and resolution; drop-cap lead, 🧬 "DNA passed to OKF" callouts per era. - Mermaid diagrams (vendored mermaid.min.js + <pre class="mermaid"> via mermaid-init.js, no preprocessor): an evolution timeline, word2vec analogy, RAG flow, and a "six rivers into OKF" convergence; plus RAG-flow and knowledge-graph diagrams in foundations.md. Air-gap (vendored), render on web and in the PDF. - print-pdf.js waits for window.__okfMermaidDone so diagrams render in the PDF. - Figure/diagram/era-banner CSS. English mirror re-translated (diagram labels localized). Verified: links + fences OK in both books. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 24e9478 commit 7152bb4

13 files changed

Lines changed: 4390 additions & 227 deletions

File tree

book-en/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ preferred-dark-theme = "navy"
1111
git-repository-url = "https://github.com/supachai-j/open-knowledge-format-starter"
1212
edit-url-template = "https://github.com/supachai-j/open-knowledge-format-starter/edit/main/book-en/{path}"
1313
additional-css = ["css/custom.css"]
14-
additional-js = ["js/lang-switch.js"]
14+
additional-js = ["js/mermaid.min.js", "js/mermaid-init.js", "js/lang-switch.js"]
1515
no-section-label = false
1616

1717
[output.html.search]

book-en/css/custom.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@
9595
}
9696
.okf-embed-fallback .okf-url { font-family: ui-monospace, monospace; word-break: break-all; }
9797

98+
/* ── Figures, diagrams, illustrations ─────────────────────────── */
99+
pre.mermaid { background: transparent; border: 0; text-align: center; margin: 1.3rem 0; line-height: normal; }
100+
pre.mermaid svg { max-width: 100%; height: auto; }
101+
figure.okf-fig { margin: 1.4rem 0; text-align: center; }
102+
figure.okf-fig svg { max-width: 100%; height: auto; }
103+
figure.okf-fig figcaption { font-size: 0.85rem; color: var(--sidebar-fg, #6b7280); margin-top: 0.5rem; font-style: italic; }
104+
.okf-era {
105+
margin: 1.8rem 0 0.6rem; padding: 0.55rem 0.95rem; border-radius: 10px;
106+
background: linear-gradient(90deg, rgba(139,92,246,0.13), transparent);
107+
border-left: 4px solid #8b5cf6;
108+
}
109+
.okf-era .yr { font-weight: 800; color: #8b5cf6; font-size: 0.8rem; letter-spacing: 0.03em; }
110+
.okf-era .ti { font-weight: 700; font-size: 1.15rem; display: block; margin-top: 0.1rem; }
111+
.okf-lead { font-size: 1.05rem; line-height: 1.85; }
112+
.okf-lead .drop { float: left; font-size: 3rem; line-height: 0.8; font-weight: 800; color: #8b5cf6; padding: 0.3rem 0.5rem 0 0; }
113+
98114
/* ── Full-page A4 cover in the PDF ─────────────────────────────── */
99115
@media print {
100116
@page { size: A4; margin: 17mm 15mm; } /* room for the running header + page-number footer */

book-en/js/mermaid-init.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Render Mermaid diagrams written as <pre class="mermaid">…</pre> (no preprocessor needed).
2+
// Sets window.__okfMermaidDone so the PDF renderer can wait for diagrams to finish.
3+
(function () {
4+
window.__okfMermaidDone = false;
5+
async function run() {
6+
if (!window.mermaid) { window.__okfMermaidDone = true; return; }
7+
try {
8+
window.mermaid.initialize({
9+
startOnLoad: false,
10+
theme: 'neutral',
11+
securityLevel: 'loose',
12+
fontFamily: "'Noto Sans Thai','Loma',sans-serif",
13+
flowchart: { htmlLabels: true, curve: 'basis', useMaxWidth: true },
14+
themeVariables: { primaryColor: '#ede9fe', primaryBorderColor: '#8b5cf6', lineColor: '#8b5cf6' },
15+
});
16+
await window.mermaid.run({ querySelector: 'pre.mermaid' });
17+
} catch (e) { console.error('mermaid', e); }
18+
window.__okfMermaidDone = true;
19+
}
20+
if (document.readyState !== 'loading') run();
21+
else document.addEventListener('DOMContentLoaded', run);
22+
})();

book-en/js/mermaid.min.js

Lines changed: 2029 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book-en/src/part1/foundations.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ FRAME: Bacteroides
2424

2525
**Example** (RDF triple): `TimBernersLee — invented — WorldWideWeb` (subject–predicate–object)
2626

27-
**In OKF:** Markdown links between concepts serve a similar role to triples but are **untyped** — the type of relationship lives in prose (much lighter than OWL).
27+
**In OKF:** Markdown links between concepts serve a similar role to triples but are **untyped** — the type of relationship lives in the prose (much lighter than OWL).
2828

2929
## 3. Inverted Index
3030

@@ -33,8 +33,8 @@ FRAME: Bacteroides
3333
**Example:**
3434
| Term | Documents |
3535
|------|-----------|
36-
| cat | D1, D2 |
37-
| dog | D3 |
36+
| cat | D1, D2 |
37+
| dog | D3 |
3838

3939
Search "dog" → returns D3 immediately, without scanning every document.
4040

@@ -69,7 +69,14 @@ Search "dog" → returns D3 immediately, without scanning every document.
6969

7070
**What it is:** Retrieving relevant information and inserting it into the LLM's context at query time to ground the answer (reduce hallucination, enable citation).
7171

72-
**Example** (5 steps): `chunk → embed → store → retrieve top-k → generate`
72+
**Example** (5 steps):
73+
74+
<pre class="mermaid">
75+
flowchart LR
76+
D["Documents"] --> C["chunk"] --> E["embed"] --> S["vector store"]
77+
Q["Query"] --> R["retrieve top-k"]
78+
S --> R --> G["LLM generate<br/>grounded answer"]
79+
</pre>
7380

7481
**In OKF:** The wiki = Layer 1 (pre-synthesized; finding it in the wiki is sufficient); RAG = Layer 2 (mining raw documents when the wiki does not yet cover the topic).
7582

@@ -85,7 +92,14 @@ Search "dog" → returns D3 immediately, without scanning every document.
8592

8693
**What it is:** A graph of entities (nodes) + typed relationships (edges) — "things, not strings" — enabling entity-level disambiguation and reasoning.
8794

88-
**Example:** `[Customer A] —ordered→ [Order 123] —contains→ [Product X]`
95+
**Example:**
96+
97+
<pre class="mermaid">
98+
flowchart LR
99+
CU["Customer A"] -->|orders| O["Order 123"]
100+
O -->|contains| P["Product X"]
101+
CU -->|in segment| SEG["High-value"]
102+
</pre>
89103

90104
**In OKF:** The entire bundle forms a knowledge graph (concepts = nodes, links = edges) — viewable with `okf-viz.py`.
91105

0 commit comments

Comments
 (0)