ligarb 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/mermaid_check.mjs +5 -1
- data/assets/style.css +16 -0
- data/docs/help.md +47 -0
- data/lib/ligarb/builder.rb +23 -2
- data/lib/ligarb/chapter.rb +1 -1
- data/lib/ligarb/config.rb +6 -2
- data/lib/ligarb/template.rb +6 -1
- data/lib/ligarb/version.rb +1 -1
- data/templates/book.html.erb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4da7029fb2f9963b33dc85186479a6b76f279613837c8de76fba3b44f82431c8
|
|
4
|
+
data.tar.gz: '0648d1ad4d05539e4675a835c5970635cd08c560f75de5968cfc9f946371c40c'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b500296a3a1f1d6b0065b40ccdbf3b043ebc8ee6ce8f3278979d2e82f736fc16a2774894f9bce84c757238c09d6f640f2c35524cf924b09b47f20c3bf9eae362
|
|
7
|
+
data.tar.gz: 599ec6de780340aa4c61c7dd7e539363890297102b7a800384089327dbb0dc9cbff2a4e0f1ee808be0b26b37357445d3762a2f8441a932254dd01b05aea816f6
|
data/assets/mermaid_check.mjs
CHANGED
|
@@ -47,7 +47,11 @@ function makeStub(name, overrides = {}) {
|
|
|
47
47
|
globalThis.window = globalThis;
|
|
48
48
|
// nodeType 9 = DOCUMENT_NODE; DOMPurify checks it to decide it has a real DOM.
|
|
49
49
|
globalThis.document = makeStub("document", { nodeType: 9 });
|
|
50
|
-
|
|
50
|
+
// Node >= 21 ships a built-in read-only `navigator` global; assigning to it
|
|
51
|
+
// throws a TypeError. Only define our stub when the runtime lacks one.
|
|
52
|
+
if (!("navigator" in globalThis)) {
|
|
53
|
+
globalThis.navigator = { userAgent: "node" };
|
|
54
|
+
}
|
|
51
55
|
globalThis.addEventListener = noop;
|
|
52
56
|
globalThis.location = { href: "http://localhost/", protocol: "http:" };
|
|
53
57
|
globalThis.Element = function Element() {};
|
data/assets/style.css
CHANGED
|
@@ -77,6 +77,22 @@ body {
|
|
|
77
77
|
opacity: 1;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
.ai-md-hint {
|
|
81
|
+
margin: 0 0 1.5rem;
|
|
82
|
+
font-size: 0.8rem;
|
|
83
|
+
color: var(--color-text-muted);
|
|
84
|
+
opacity: 0.8;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.ai-md-hint a {
|
|
88
|
+
color: inherit;
|
|
89
|
+
text-decoration: underline;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@media print {
|
|
93
|
+
.ai-md-hint { display: none; }
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
.book-title {
|
|
81
97
|
font-size: 1.1rem;
|
|
82
98
|
font-weight: 700;
|
data/docs/help.md
CHANGED
|
@@ -83,6 +83,23 @@ The output directory contains index.html plus js/ and css/ subdirectories
|
|
|
83
83
|
for auto-downloaded libraries (highlight.js, mermaid, KaTeX, etc.).
|
|
84
84
|
Open index.html directly in a browser — no web server needed.
|
|
85
85
|
|
|
86
|
+
The build also emits a Markdown full-text version of the book next to
|
|
87
|
+
index.html, intended for AI/LLM readers (HTML is noisy and costly to read;
|
|
88
|
+
clean Markdown is cheaper and more faithful). For a single-language build it
|
|
89
|
+
is `index.md`; for a multi-language (hub) build it is `index.<lang>.md` per
|
|
90
|
+
language. Each is the concatenated chapter sources in reading order. The HTML
|
|
91
|
+
points to it two ways: a small visible note at the top of the content ("For
|
|
92
|
+
AI/LLM readers: a clean Markdown full-text version of this book is at …") and
|
|
93
|
+
a `<link rel="alternate" type="text/markdown">` in the head. Both use a
|
|
94
|
+
relative href (the bare filename), so they resolve against whatever URL the
|
|
95
|
+
page is actually served from — local preview, staging, or production — rather
|
|
96
|
+
than hard-coding `site_url` (the absolute canonical URL still lives in
|
|
97
|
+
`og:url` / `<link rel="canonical">`). A fetcher resolves it against the page's
|
|
98
|
+
own URL, so a model that fetched the page finds the bundle next to it. No tool
|
|
99
|
+
is guaranteed to honor these automatically —
|
|
100
|
+
the visible note is what actually reaches a model that fetched the page,
|
|
101
|
+
since the in-page text is included in what the fetcher hands to the model.
|
|
102
|
+
|
|
86
103
|
When `github_review.enabled` is true and `repository` is set (see
|
|
87
104
|
Configuration below), the build also injects a static "Report as issue"
|
|
88
105
|
feedback UI: readers select text, pick a type and add a comment, and a
|
|
@@ -182,6 +199,7 @@ The configuration file is a YAML file with the following fields:
|
|
|
182
199
|
| `output_dir` | optional | `"build"` | Output directory relative to book.yml. |
|
|
183
200
|
| `chapter_numbers` | optional | `true` | Show chapter/section numbers (e.g. "1.", "1.1", "1.1.1"). |
|
|
184
201
|
| `style` | optional | — | Path to a custom CSS file relative to book.yml. Loaded after the default styles, so it can override any rule. |
|
|
202
|
+
| `head` | optional | — | Raw HTML injected verbatim at the end of `<head>`. Use it for analytics beacons, search-console verification, custom meta tags, etc. Not sanitized (trusted-author model, like `style`). In a multi-language hub build it is shared across languages (set it once on the hub). See "Custom head HTML (analytics)". |
|
|
185
203
|
| `repository` | optional | — | GitHub repository URL (e.g. "https://github.com/user/repo"). When set, each chapter shows a "View on GitHub" link pointing to `{repository}/blob/HEAD/{path-from-git-root}`. |
|
|
186
204
|
| `ai_generated` | optional | `false` | Mark the book as AI-generated content. When true: adds an "AI Generated" badge in the sidebar header, adds a default disclaimer footer to each chapter, and adds noindex/noai meta tags. The footer text can be overridden with the `footer` field. |
|
|
187
205
|
| `footer` | optional | — | Custom text displayed at the bottom of each chapter. Overrides the default ai_generated disclaimer if both are set. |
|
|
@@ -800,6 +818,35 @@ Example custom.css:
|
|
|
800
818
|
}
|
|
801
819
|
```
|
|
802
820
|
|
|
821
|
+
### Custom head HTML (analytics)
|
|
822
|
+
|
|
823
|
+
GitHub Pages and most static hosts do not report page views (a repository's
|
|
824
|
+
"Insights → Traffic" counts repo visits, not the rendered site). To measure
|
|
825
|
+
traffic, add a small client-side beacon. The `head` field injects raw HTML
|
|
826
|
+
verbatim at the end of `<head>`:
|
|
827
|
+
|
|
828
|
+
```yaml
|
|
829
|
+
head: |
|
|
830
|
+
<script data-goatcounter="https://MYCODE.goatcounter.com/count"
|
|
831
|
+
async src="//gc.zgo.at/count.js"></script>
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
The HTML is embedded as-is (no sanitization — trusted-author model, like
|
|
835
|
+
`style`), so treat it as part of the trusted source. It is not limited to
|
|
836
|
+
analytics: search-console verification tags, a custom `og:image`, or extra
|
|
837
|
+
meta tags work too.
|
|
838
|
+
|
|
839
|
+
[GoatCounter](https://www.goatcounter.com/) is a good fit for a personal site
|
|
840
|
+
— free for non-commercial use, one script tag, no cookies (so no consent
|
|
841
|
+
banner), and a per-page breakdown. [Cloudflare Web Analytics] and Google
|
|
842
|
+
Analytics work the same way; just paste their snippet.
|
|
843
|
+
|
|
844
|
+
[Cloudflare Web Analytics]: https://www.cloudflare.com/web-analytics/
|
|
845
|
+
|
|
846
|
+
In a multi-language hub build, set `head` once on the hub config — it is
|
|
847
|
+
inherited by every language, and the output is a single HTML page, so the
|
|
848
|
+
snippet appears once.
|
|
849
|
+
|
|
803
850
|
### Dark Mode
|
|
804
851
|
|
|
805
852
|
The generated HTML includes a dark mode toggle button (moon icon) in the
|
data/lib/ligarb/builder.rb
CHANGED
|
@@ -41,13 +41,18 @@ module Ligarb
|
|
|
41
41
|
|
|
42
42
|
bibliography = resolve_citations!(all_chapters)
|
|
43
43
|
|
|
44
|
+
FileUtils.mkdir_p(@config.output_path)
|
|
45
|
+
|
|
46
|
+
md_name = "index.md"
|
|
47
|
+
write_markdown_bundle(all_chapters, File.join(@config.output_path, md_name))
|
|
48
|
+
|
|
44
49
|
html = Template.new.render(config: @config, chapters: all_chapters,
|
|
45
50
|
structure: structure, assets: assets,
|
|
46
51
|
index_entries: index_entries,
|
|
47
52
|
bibliography: bibliography,
|
|
48
|
-
github_review: github_review_data(@config)
|
|
53
|
+
github_review: github_review_data(@config),
|
|
54
|
+
ai_md: md_name)
|
|
49
55
|
|
|
50
|
-
FileUtils.mkdir_p(@config.output_path)
|
|
51
56
|
output_file = File.join(@config.output_path, "index.html")
|
|
52
57
|
File.write(output_file, html)
|
|
53
58
|
|
|
@@ -76,6 +81,14 @@ module Ligarb
|
|
|
76
81
|
all_lang_chapters.concat(lang_data[:chapters])
|
|
77
82
|
end
|
|
78
83
|
|
|
84
|
+
FileUtils.mkdir_p(output_path)
|
|
85
|
+
|
|
86
|
+
langs.each do |ld|
|
|
87
|
+
md_name = "index.#{ld[:lang]}.md"
|
|
88
|
+
write_markdown_bundle(ld[:chapters], File.join(output_path, md_name))
|
|
89
|
+
ld[:ai_md] = md_name
|
|
90
|
+
end
|
|
91
|
+
|
|
79
92
|
assets = AssetManager.new(output_path)
|
|
80
93
|
assets.detect(all_lang_chapters)
|
|
81
94
|
assets.provision!
|
|
@@ -428,6 +441,14 @@ module Ligarb
|
|
|
428
441
|
text.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
429
442
|
end
|
|
430
443
|
|
|
444
|
+
# Emit a clean Markdown full-text version of the book alongside index.html.
|
|
445
|
+
# AI/LLM readers (and the in-page hint) point here for low-noise content.
|
|
446
|
+
# The bundle is the concatenated chapter sources in flat reading order.
|
|
447
|
+
def write_markdown_bundle(chapters, path)
|
|
448
|
+
body = chapters.map { |ch| ch.source.strip }.reject(&:empty?).join("\n\n")
|
|
449
|
+
File.write(path, body.empty? ? body : "#{body}\n")
|
|
450
|
+
end
|
|
451
|
+
|
|
431
452
|
def copy_images
|
|
432
453
|
images_dir = File.join(@config.base_dir, "images")
|
|
433
454
|
return unless Dir.exist?(images_dir)
|
data/lib/ligarb/chapter.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Ligarb
|
|
|
8
8
|
class CrossReferenceError < StandardError; end
|
|
9
9
|
|
|
10
10
|
attr_reader :title, :slug, :html, :headings, :number, :appendix_letter, :index_entries, :cite_entries,
|
|
11
|
-
:path, :mermaid_blocks
|
|
11
|
+
:path, :mermaid_blocks, :source
|
|
12
12
|
attr_accessor :part_title, :cover, :relative_path
|
|
13
13
|
|
|
14
14
|
Heading = Struct.new(:level, :text, :id, :display_text, keyword_init: true)
|
data/lib/ligarb/config.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Ligarb
|
|
|
11
11
|
# config file that was directly passed to `ligarb build`.
|
|
12
12
|
INHERITABLE_KEYS = %w[author language chapter_numbers style
|
|
13
13
|
repository ai_generated footer bibliography
|
|
14
|
-
github_review site_url].freeze
|
|
14
|
+
github_review site_url head].freeze
|
|
15
15
|
# `description` is intentionally not inheritable: it is usually
|
|
16
16
|
# language-specific, so each translation should set its own.
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@ module Ligarb
|
|
|
28
28
|
attr_reader :title, :author, :language, :output_dir, :base_dir,
|
|
29
29
|
:chapter_numbers, :structure, :style, :repository,
|
|
30
30
|
:ai_generated, :footer, :bibliography, :sources,
|
|
31
|
-
:translations, :github_review, :description, :site_url
|
|
31
|
+
:translations, :github_review, :description, :site_url, :head
|
|
32
32
|
|
|
33
33
|
def initialize(path, parent_data: nil)
|
|
34
34
|
@base_dir = File.dirname(File.expand_path(path))
|
|
@@ -74,6 +74,7 @@ module Ligarb
|
|
|
74
74
|
@footer = data.fetch("footer", nil)
|
|
75
75
|
@bibliography = data.fetch("bibliography", nil)
|
|
76
76
|
@github_review = data.fetch("github_review", nil)
|
|
77
|
+
@head = data.fetch("head", nil)
|
|
77
78
|
@sources = parse_sources(data.fetch("sources", []))
|
|
78
79
|
@structure = parse_structure(data["chapters"])
|
|
79
80
|
@translations = []
|
|
@@ -233,6 +234,9 @@ module Ligarb
|
|
|
233
234
|
|
|
234
235
|
def load_translations_hub(data)
|
|
235
236
|
@title = data.fetch("title", "")
|
|
237
|
+
# The hub writes its combined build here; serve needs output_path to work
|
|
238
|
+
# even though hub init returns before the normal output_dir assignment.
|
|
239
|
+
@output_dir = data.fetch("output_dir", "build")
|
|
236
240
|
@translations = []
|
|
237
241
|
|
|
238
242
|
trans = data["translations"]
|
data/lib/ligarb/template.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Ligarb
|
|
|
13
13
|
@css_path = File.join(ASSETS_DIR, "style.css")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def render(config:, chapters:, structure:, assets:, index_entries: [], bibliography: [], github_review: nil)
|
|
16
|
+
def render(config:, chapters:, structure:, assets:, index_entries: [], bibliography: [], github_review: nil, ai_md: nil)
|
|
17
17
|
css = File.read(@css_path)
|
|
18
18
|
template = File.read(@template_path)
|
|
19
19
|
|
|
@@ -42,6 +42,8 @@ module Ligarb
|
|
|
42
42
|
b.local_variable_set(:og_description, og_description(config, chapters))
|
|
43
43
|
b.local_variable_set(:og_locale, og_locale(config.language))
|
|
44
44
|
b.local_variable_set(:og_url, og_url(config))
|
|
45
|
+
b.local_variable_set(:ai_md, ai_md)
|
|
46
|
+
b.local_variable_set(:head_html, config.head)
|
|
45
47
|
|
|
46
48
|
ERB.new(template, trim_mode: "-").result(b)
|
|
47
49
|
end
|
|
@@ -74,6 +76,7 @@ module Ligarb
|
|
|
74
76
|
footer: cfg.effective_footer,
|
|
75
77
|
index_tree: build_index_tree(ld[:index_entries], ld[:chapters]),
|
|
76
78
|
bibliography: ld[:bibliography],
|
|
79
|
+
ai_md: ld[:ai_md],
|
|
77
80
|
}
|
|
78
81
|
end
|
|
79
82
|
|
|
@@ -99,6 +102,8 @@ module Ligarb
|
|
|
99
102
|
b.local_variable_set(:og_description, og_description(first_config, first[:chapters]))
|
|
100
103
|
b.local_variable_set(:og_locale, og_locale(first_config.language))
|
|
101
104
|
b.local_variable_set(:og_url, og_url(first_config))
|
|
105
|
+
b.local_variable_set(:ai_md, nil)
|
|
106
|
+
b.local_variable_set(:head_html, first_config.head)
|
|
102
107
|
|
|
103
108
|
ERB.new(template, trim_mode: "-").result(b)
|
|
104
109
|
end
|
data/lib/ligarb/version.rb
CHANGED
data/templates/book.html.erb
CHANGED
|
@@ -17,6 +17,15 @@
|
|
|
17
17
|
<meta property="og:description" content="<%= h(og_description) %>">
|
|
18
18
|
<%- end -%>
|
|
19
19
|
<meta name="twitter:card" content="summary">
|
|
20
|
+
<%- if multilang -%>
|
|
21
|
+
<%- langs.each do |ld| -%>
|
|
22
|
+
<%- if ld[:ai_md] -%>
|
|
23
|
+
<link rel="alternate" type="text/markdown" hreflang="<%= h(ld[:language]) %>" href="<%= h(ld[:ai_md]) %>" title="<%= h(ld[:title]) %> (Markdown)">
|
|
24
|
+
<%- end -%>
|
|
25
|
+
<%- end -%>
|
|
26
|
+
<%- elsif ai_md -%>
|
|
27
|
+
<link rel="alternate" type="text/markdown" href="<%= h(ai_md) %>" title="Markdown version">
|
|
28
|
+
<%- end -%>
|
|
20
29
|
<%- if author && !author.to_s.empty? -%>
|
|
21
30
|
<meta property="book:author" content="<%= h(author) %>">
|
|
22
31
|
<%- end -%>
|
|
@@ -43,6 +52,9 @@
|
|
|
43
52
|
<%- if assets.need?(:katex) -%>
|
|
44
53
|
<link rel="stylesheet" href="css/katex.min.css">
|
|
45
54
|
<%- end -%>
|
|
55
|
+
<%- if head_html && !head_html.to_s.empty? -%>
|
|
56
|
+
<%= head_html %>
|
|
57
|
+
<%- end -%>
|
|
46
58
|
</head>
|
|
47
59
|
<body>
|
|
48
60
|
|
|
@@ -272,6 +284,15 @@
|
|
|
272
284
|
<button class="sidebar-toggle" id="sidebar-toggle" aria-label="Toggle sidebar">☰</button>
|
|
273
285
|
|
|
274
286
|
<main class="content" id="content">
|
|
287
|
+
<%- if multilang -%>
|
|
288
|
+
<%- langs.each do |ld| -%>
|
|
289
|
+
<%- if ld[:ai_md] -%>
|
|
290
|
+
<p class="ai-md-hint lang-content" data-lang="<%= ld[:lang] %>">For AI/LLM readers: a clean Markdown full-text version of this book is at <a href="<%= h(ld[:ai_md]) %>"><%= h(ld[:ai_md]) %></a>.</p>
|
|
291
|
+
<%- end -%>
|
|
292
|
+
<%- end -%>
|
|
293
|
+
<%- elsif ai_md -%>
|
|
294
|
+
<p class="ai-md-hint">For AI/LLM readers: a clean Markdown full-text version of this book is at <a href="<%= h(ai_md) %>"><%= h(ai_md) %></a>.</p>
|
|
295
|
+
<%- end -%>
|
|
275
296
|
<%- if multilang -%>
|
|
276
297
|
<%- langs.each do |ld| -%>
|
|
277
298
|
<%- ld[:chapters].select(&:cover?).each do |chapter| -%>
|