datalog-theme 0.8.0 → 0.9.1

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.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +84 -0
  3. data/CITATION.cff +2 -2
  4. data/README.md +4 -2
  5. data/_data/i18n/en.yml +321 -0
  6. data/_data/i18n/es.yml +321 -0
  7. data/_data/i18n/pt.yml +321 -0
  8. data/_data/js_manifest.json +16 -0
  9. data/_includes/components/academic-dashboard.html +4 -4
  10. data/_includes/components/author-bio.html +21 -11
  11. data/_includes/components/author-list.html +32 -0
  12. data/_includes/components/breadcrumbs.html +6 -4
  13. data/_includes/components/citation-tools.html +18 -58
  14. data/_includes/components/comments-thread.html +90 -0
  15. data/_includes/components/contact-form.html +120 -0
  16. data/_includes/components/correction-report.html +82 -0
  17. data/_includes/components/enhanced-toc.html +6 -7
  18. data/_includes/components/hero.html +1 -1
  19. data/_includes/components/license-link.html +13 -0
  20. data/_includes/components/license-notice.html +28 -0
  21. data/_includes/components/moderation-inbox.html +139 -0
  22. data/_includes/components/post-hero.html +2 -2
  23. data/_includes/components/reactions.html +49 -0
  24. data/_includes/components/reading-list.html +34 -0
  25. data/_includes/components/reading-mode-toggle.html +67 -0
  26. data/_includes/components/reading-state-bookmark.html +27 -0
  27. data/_includes/components/reading-state-panel.html +62 -0
  28. data/_includes/components/reading-state-resume.html +17 -0
  29. data/_includes/components/reproducibility.html +61 -0
  30. data/_includes/components/responsive-image.html +3 -3
  31. data/_includes/components/revision-history.html +39 -0
  32. data/_includes/components/revision-notice.html +35 -0
  33. data/_includes/components/series-nav.html +64 -0
  34. data/_includes/components/subscribe-form.html +88 -0
  35. data/_includes/components/subscription-manage.html +69 -0
  36. data/_includes/components/visualization-card.html +1 -1
  37. data/_includes/components/webmentions.html +48 -0
  38. data/_includes/csp-meta.html +21 -1
  39. data/_includes/footer/nav-column.html +1 -1
  40. data/_includes/footer.html +5 -2
  41. data/_includes/head.html +64 -52
  42. data/_includes/header/navigation.html +2 -2
  43. data/_includes/header.html +1 -1
  44. data/_includes/layouts/default/article.html +6 -8
  45. data/_includes/meta/dynamic-services-config.html +14 -0
  46. data/_includes/meta/math-config.html +12 -5
  47. data/_includes/meta/person-json.html +27 -0
  48. data/_includes/meta/publisher.html +45 -0
  49. data/_includes/meta/schema.html +84 -48
  50. data/_includes/meta/scholarly.html +122 -0
  51. data/_includes/meta/scripts-loader.html +2 -0
  52. data/_includes/meta/webmention-discovery.html +14 -0
  53. data/_includes/post/related-posts.html +1 -1
  54. data/_includes/scripts.html +57 -0
  55. data/_layouts/dataset.html +5 -4
  56. data/_layouts/default.html +1 -1
  57. data/_layouts/home.html +2 -2
  58. data/_layouts/notebook.html +1 -1
  59. data/_layouts/package.html +8 -7
  60. data/_layouts/page.html +15 -0
  61. data/_layouts/portfolio.html +1 -1
  62. data/_layouts/post.html +94 -25
  63. data/_layouts/project.html +5 -5
  64. data/_layouts/research.html +27 -75
  65. data/_plugins/authors.rb +151 -0
  66. data/_plugins/citation_exports.rb +93 -0
  67. data/_plugins/config_validator.rb +223 -20
  68. data/_plugins/critical_css_check.rb +42 -0
  69. data/_plugins/i18n.rb +6 -4
  70. data/_plugins/image_optimizer.rb +240 -186
  71. data/_plugins/licenses.rb +147 -0
  72. data/_plugins/math_preprocessor.rb +55 -11
  73. data/_plugins/references.rb +260 -0
  74. data/_plugins/reproducibility.rb +167 -0
  75. data/_plugins/responsive_content.rb +40 -0
  76. data/_plugins/revisions.rb +102 -0
  77. data/_plugins/scholarly.rb +55 -0
  78. data/_plugins/series.rb +104 -0
  79. data/_plugins/statements.rb +87 -0
  80. data/_sass/_base.scss +13 -1
  81. data/_sass/_comments-thread.scss +159 -0
  82. data/_sass/_layout.scss +402 -1
  83. data/_sass/_mathematical.scss +38 -1
  84. data/_sass/_moderation.scss +222 -0
  85. data/_sass/_post-components.scss +4 -2
  86. data/_sass/_print.scss +299 -0
  87. data/_sass/_reactions.scss +89 -0
  88. data/_sass/_reading-state.scss +290 -0
  89. data/_sass/_service-forms.scss +204 -0
  90. data/_sass/_subscriptions.scss +140 -0
  91. data/_sass/_syntax-highlighting.scss +3 -3
  92. data/_sass/_theme.scss +11 -0
  93. data/_sass/_typography.scss +116 -0
  94. data/_sass/_utilities.scss +5 -0
  95. data/_sass/_variables.scss +6 -0
  96. data/_sass/_webmentions.scss +125 -0
  97. data/assets/js/dist/academic.js +1 -1
  98. data/assets/js/dist/analytics-dashboard.js +1 -1
  99. data/assets/js/dist/chunks/chunk-PATLC23F.js +1 -0
  100. data/assets/js/dist/chunks/chunk-VZ5WKQVA.js +1 -0
  101. data/assets/js/dist/chunks/chunk-WIRUK3OZ.js +1 -0
  102. data/assets/js/dist/comments.js +2 -0
  103. data/assets/js/dist/contact.js +1 -0
  104. data/assets/js/dist/core.js +1 -1
  105. data/assets/js/dist/corrections.js +1 -0
  106. data/assets/js/dist/loader.js +1 -1
  107. data/assets/js/dist/math.js +1 -1
  108. data/assets/js/dist/moderation.js +1 -0
  109. data/assets/js/dist/notebook.js +1 -1
  110. data/assets/js/dist/reactions.js +1 -0
  111. data/assets/js/dist/reading-state.js +1 -0
  112. data/assets/js/dist/search.js +1 -1
  113. data/assets/js/dist/sources.json +52 -0
  114. data/assets/js/dist/subscriptions.js +1 -0
  115. data/assets/js/dist/visualizations.js +2 -2
  116. data/assets/js/dist/webmentions.js +1 -0
  117. data/assets/js/loader.js +34 -0
  118. data/datalog-theme.gemspec +1 -2
  119. data/lib/datalog/cli.rb +9 -1
  120. data/lib/datalog/critical_css.rb +168 -0
  121. data/lib/datalog/plugins/comments.rb +33 -3
  122. data/lib/datalog/theme/installed_files.rb +113 -0
  123. data/lib/datalog/theme/repository_checkout.rb +6 -2
  124. data/lib/datalog/theme/version.rb +5 -1
  125. data/lib/datalog-theme.rb +1 -0
  126. metadata +60 -23
  127. data/assets/js/dist/chunks/chunk-225H5YXE.js +0 -1
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module Datalog
6
+ # The computational artifacts behind an article, for the "Reproduce this
7
+ # analysis" panel (_includes/components/reproducibility.html):
8
+ #
9
+ # reproducibility:
10
+ # code:
11
+ # url: https://github.com/example/project
12
+ # ref: 4f2c1ab # the commit, tag or branch the article used
13
+ # data:
14
+ # doi: 10.5281/zenodo.1234567 # or url:
15
+ # version: v2
16
+ # environment:
17
+ # file: requirements.txt # in the code repository at the ref, a site path or a URL
18
+ # container: ghcr.io/example/project:1.4.0
19
+ # archive: https://doi.org/10.5281/zenodo.7654321
20
+ # notebook:
21
+ # url: /notebooks/example/
22
+ # results:
23
+ # url: https://github.com/example/project/releases/tag/results-v1
24
+ # version: results-v1
25
+ #
26
+ # Every artifact is optional, and each may be a bare URL. The panel shows
27
+ # what is given and claims nothing more: a link is a link, a ref is a ref.
28
+ # A URL that is not http(s), a site path or a DOI stops the build.
29
+ module Reproducibility
30
+ module_function
31
+
32
+ KINDS = %w[code data notebook environment results].freeze
33
+ # Where a ref and a file in the repository can be linked.
34
+ HOSTS = {
35
+ "github.com" => { tree: "/tree/%s", blob: "/blob/%s/%s" },
36
+ "gitlab.com" => { tree: "/-/tree/%s", blob: "/-/blob/%s/%s" }
37
+ }.freeze
38
+ URL = %r{\Ahttps?://[^\s"'<>]+\z}i
39
+ PATH = %r{\A/[^\s"'<>]*\z}
40
+
41
+ # The artifacts, in KINDS order, or nil when the page gives none.
42
+ def resolve(page, site)
43
+ value = Authors.value(page, "reproducibility")
44
+ return unless value.is_a?(Hash)
45
+
46
+ given = value.transform_keys(&:to_s)
47
+ baseurl = Authors.value(site, "baseurl").to_s
48
+ artifacts = KINDS.filter_map { |kind| artifact(kind, given[kind], given, page, baseurl) }
49
+ { "artifacts" => artifacts } unless artifacts.empty?
50
+ end
51
+
52
+ def artifact(kind, value, all, page, baseurl)
53
+ return if value.nil? || value == false || (value.is_a?(String) && value.strip.empty?)
54
+
55
+ given = value.is_a?(Hash) ? Authors.present(value) : { "url" => value.to_s }
56
+ url = link(given["url"] || doi_url(given["doi"]), page, "#{kind}.url", baseurl)
57
+ artifact = { "kind" => kind, "url" => url, "external" => external?(url), "version" => given["version"]&.to_s,
58
+ "label" => given["label"] || display(url), "doi" => bare_doi(given["doi"]) }
59
+ artifact.merge!(code(given, url)) if kind == "code"
60
+ artifact.merge!(environment(given, all, page, baseurl)) if kind == "environment"
61
+ artifact = artifact.compact
62
+ artifact if artifact.values_at("url", "file", "container", "archive").any?
63
+ end
64
+
65
+ def code(given, url)
66
+ ref = given["ref"].to_s.strip
67
+ return {} if ref.empty?
68
+
69
+ { "ref" => ref, "ref_url" => host_url(url, :tree, ref) }
70
+ end
71
+
72
+ # The environment file lives in the code repository at the article's ref
73
+ # unless it is a site path or a URL of its own.
74
+ def environment(given, all, page, baseurl)
75
+ file = given["file"].to_s.strip
76
+ archive = link(given["archive"], page, "environment.archive", baseurl)
77
+ {
78
+ "file" => (file unless file.empty?),
79
+ "file_url" => (file_url(file, all["code"], page, baseurl) unless file.empty?),
80
+ "container" => given["container"]&.to_s,
81
+ "archive" => archive, "archive_label" => display(archive)
82
+ }
83
+ end
84
+
85
+ def file_url(file, code, page, baseurl)
86
+ own = file.match?(URL) || file.match?(PATH) || file.match?(/\Adoi:/i)
87
+ return link(file, page, "environment.file", baseurl) if own
88
+
89
+ code = code.is_a?(Hash) ? Authors.present(code) : { "url" => code.to_s }
90
+ code_url = link(code["url"], page, "code.url", baseurl)
91
+ ref = code["ref"].to_s.strip
92
+ host_url(code_url, :blob, ref.empty? ? "HEAD" : ref, file)
93
+ end
94
+
95
+ # A page of a known host under the repository URL, such as a tree or a blob.
96
+ def host_url(url, kind, *parts)
97
+ return unless url
98
+
99
+ uri = URI.parse(url)
100
+ host = uri.host.to_s.downcase.sub(/\Awww\./, "")
101
+ pattern = HOSTS.dig(host, kind)
102
+ return unless pattern
103
+
104
+ root = if host == "github.com"
105
+ uri.path.split("/").reject(&:empty?).first(2).join("/")
106
+ else
107
+ uri.path.sub(%r{/-/.*}, "").delete_prefix("/")
108
+ end
109
+ root = root.chomp("/").delete_suffix(".git")
110
+ # A ref is one route argument; a file retains its directory separators.
111
+ encoded = parts.each_with_index.map do |part, index|
112
+ index.zero? ? URI.encode_www_form_component(part).gsub("+", "%20") : encode_path(part)
113
+ end
114
+ "#{uri.scheme}://#{host}/#{root}#{format(pattern, *encoded)}"
115
+ rescue URI::InvalidURIError
116
+ nil
117
+ end
118
+
119
+ # An http(s) URL as given, a site path with the baseurl, or a DOI as its
120
+ # URL; anything else, such as a javascript: URL or an address without its
121
+ # scheme, stops the build.
122
+ def link(value, page, field, baseurl)
123
+ text = value.to_s.strip
124
+ return if text.empty?
125
+ return doi_url(text) if text.match?(/\Adoi:/i)
126
+ return text if text.match?(URL)
127
+ return "#{baseurl}#{text}" if text.match?(PATH)
128
+
129
+ raise Jekyll::Errors::FatalException,
130
+ "#{Authors.value(page, 'path')} reproducibility.#{field} is #{text.inspect}, which is not an http(s) " \
131
+ "URL, a site path starting with / or a doi:; give the whole address, such as https://github.com/example/project"
132
+ end
133
+
134
+ def bare_doi(doi)
135
+ text = doi.to_s.strip.sub(%r{\Ahttps?://(dx\.)?doi\.org/}i, "").sub(/\Adoi:\s*/i, "")
136
+ text unless text.empty?
137
+ end
138
+
139
+ def doi_url(doi)
140
+ bare = bare_doi(doi)
141
+ "https://doi.org/#{encode_path(bare)}" if bare
142
+ end
143
+
144
+ def encode_path(value)
145
+ value.to_s.split("/", -1).map { |part| URI.encode_www_form_component(part).gsub("+", "%20") }.join("/")
146
+ end
147
+
148
+ # What a link reads: the address without its scheme, or the site path.
149
+ def display(url)
150
+ return url unless external?(url)
151
+
152
+ url.sub(%r{\Ahttps?://(www\.)?}i, "").chomp("/")
153
+ end
154
+
155
+ def external?(url)
156
+ url.to_s.match?(URL)
157
+ end
158
+ end
159
+
160
+ module ReproducibilityFilters
161
+ def page_reproducibility(page)
162
+ Reproducibility.resolve(page, @context["site"])
163
+ end
164
+ end
165
+ end
166
+
167
+ Liquid::Template.register_filter(Datalog::ReproducibilityFilters)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+
5
+ module Datalog
6
+ # A table keeps its native semantics and desktop width while its enclosing
7
+ # region can scroll with either touch or the keyboard on a narrow screen.
8
+ module ResponsiveContent
9
+ module_function
10
+
11
+ def process(document)
12
+ return unless document.output_ext == ".html" && document.content.to_s.include?("<table")
13
+
14
+ html = Nokogiri::HTML5.fragment(document.content)
15
+ tables = html.css("table").to_a
16
+ tables.reject! do |table|
17
+ table["class"].to_s.split.include?("rouge-table") || table.ancestors(".content-table").any?
18
+ end
19
+ return if tables.empty?
20
+
21
+ locale = I18n.locale_code(document.site, document.data["lang"])
22
+ label = I18n.lookup(document.site, locale, "references.table") || "Table"
23
+ tables.each_with_index do |table, index|
24
+ wrapper = Nokogiri::XML::Node.new("div", html)
25
+ wrapper["class"] = "content-table"
26
+ wrapper["role"] = "region"
27
+ wrapper["tabindex"] = "0"
28
+ caption = table.at_css("caption")&.text.to_s.strip
29
+ wrapper["aria-label"] = caption.empty? ? "#{label} #{index + 1}" : caption
30
+ table.add_previous_sibling(wrapper)
31
+ wrapper.add_child(table)
32
+ end
33
+ document.content = html.to_html
34
+ end
35
+ end
36
+ end
37
+
38
+ Jekyll::Hooks.register %i[pages documents], :post_convert do |document|
39
+ Datalog::ResponsiveContent.process(document)
40
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "time"
5
+
6
+ module Datalog
7
+ # The revision history of an article, for a post that is corrected or
8
+ # rewritten while keeping its URL:
9
+ #
10
+ # revisions:
11
+ # - date: 2026-09-16
12
+ # type: correction
13
+ # summary: Replaced the sample-size rules with model diagnostics.
14
+ # details_url: https://github.com/example/repo/pull/425
15
+ # - date: 2024-03-12
16
+ # type: update
17
+ # summary: Updated the code examples for the current SciPy.
18
+ #
19
+ # Before the site renders, each page's list is checked, its dates are
20
+ # parsed and its entries sorted newest first, so the includes read one
21
+ # shape. A correction or an update is substantive: the newest one becomes
22
+ # `revision_notice`, which the post layout announces under the metadata.
23
+ # A review or an editorial change appears in the history only.
24
+ #
25
+ # Every revision but a review changed the article, so the newest one sets
26
+ # `last_modified_at` when it is later than the date the page gives, and
27
+ # the JSON-LD, the microdata, the feed and the sitemap all carry it.
28
+ module Revisions
29
+ module_function
30
+
31
+ TYPES = %w[correction update review editorial].freeze
32
+ SUBSTANTIVE = %w[correction update].freeze
33
+ DEFAULT_TYPE = "update"
34
+
35
+ def normalize!(document)
36
+ data = document.data
37
+ data["last_modified_at"] ||= to_time(data["updated"]) if data["updated"]
38
+ return unless data.key?("revisions")
39
+
40
+ revisions = entries(data["revisions"], document)
41
+ data["revisions"] = revisions
42
+ notice = revisions.find { |revision| revision["substantive"] }
43
+ data["revision_notice"] = notice unless data["revision_notice"] == false
44
+
45
+ changed = revisions.find { |revision| revision["type"] != "review" }
46
+ modified = to_time(data["last_modified_at"] || data["updated"])
47
+ data["last_modified_at"] = changed["date"] if changed && (modified.nil? || changed["date"] > modified)
48
+ end
49
+
50
+ # Newest first; revisions on one day keep their order.
51
+ def entries(list, document)
52
+ unless list.is_a?(Array)
53
+ stop(document, "has revisions that is not a list; each revision is a map with a date, a summary and, " \
54
+ "if wanted, a type and a details_url")
55
+ end
56
+
57
+ revisions = list.each_with_index.map { |entry, index| revision(entry, index + 1, document) }
58
+ revisions.each_with_index.sort_by { |revision, index| [-revision["date"].to_i, index] }.map(&:first)
59
+ end
60
+
61
+ def revision(entry, number, document)
62
+ stop(document, "revision #{number} is not a map with a date and a summary") unless entry.is_a?(Hash)
63
+
64
+ entry = entry.transform_keys(&:to_s)
65
+ type = (entry["type"] || DEFAULT_TYPE).to_s.strip.downcase
66
+ unless TYPES.include?(type)
67
+ stop(document, "revision #{number} has the type #{entry['type'].inspect}; it takes #{TYPES.join(', ')}")
68
+ end
69
+ summary = entry["summary"].to_s.strip
70
+ stop(document, "revision #{number} needs a summary saying what changed") if summary.empty?
71
+ date = to_time(entry["date"])
72
+ unless date
73
+ stop(document, "revision #{number} has the date #{entry['date'].inspect}, which is not a date such as " \
74
+ "2026-09-16")
75
+ end
76
+
77
+ details = entry["details_url"].to_s.strip
78
+ { "date" => date, "type" => type, "summary" => summary, "details_url" => (details unless details.empty?),
79
+ "substantive" => SUBSTANTIVE.include?(type) }.compact
80
+ end
81
+
82
+ def stop(document, problem)
83
+ raise Jekyll::Errors::FatalException, "#{document.relative_path} #{problem}"
84
+ end
85
+
86
+ # A Date, a Time or a string naming a day, such as "2026-09-16".
87
+ def to_time(value)
88
+ case value
89
+ when Time then value
90
+ when Date then value.to_time
91
+ when String
92
+ parts = Date._parse(value)
93
+ Time.parse(value) if parts[:year] && parts[:mon] && parts[:mday]
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ Jekyll::Hooks.register :site, :post_read do |site|
100
+ site.documents.each { |document| Datalog::Revisions.normalize!(document) }
101
+ site.pages.each { |page| Datalog::Revisions.normalize!(page) }
102
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datalog
4
+ # Which pages get scholarly discovery metadata (_includes/meta/scholarly.html):
5
+ # the Highwire meta tags Google Scholar and reference managers read, and
6
+ # their Dublin Core equivalents. Not every post is a paper, so the tags are
7
+ # opt-in:
8
+ #
9
+ # scholarly: true # front matter: this page is a research article
10
+ # scholarly: false # front matter: this one is not, whatever the site says
11
+ #
12
+ # scholarly: true # _config.yml: every post and research article
13
+ # scholarly: [notebooks] # _config.yml: these collections or layouts as well
14
+ #
15
+ # A page with the research layout, or in a research collection, is
16
+ # scholarly unless it says otherwise.
17
+ module Scholarly
18
+ module_function
19
+
20
+ ALWAYS = %w[research].freeze
21
+ POSTS = %w[posts post].freeze
22
+
23
+ def scholarly?(page, site)
24
+ own = Authors.value(page, "scholarly")
25
+ return own == true unless own.nil?
26
+
27
+ kinds = kinds(Authors.value(site, "scholarly"))
28
+ [Authors.value(page, "layout"), Authors.value(page, "collection")].any? { |kind| kinds.include?(kind.to_s) }
29
+ end
30
+
31
+ # The layouts and collections the site's setting covers, besides research.
32
+ def kinds(setting)
33
+ case setting
34
+ when true then ALWAYS + POSTS
35
+ when Array then ALWAYS + setting.map(&:to_s)
36
+ when String then ALWAYS + setting.split(/[\s,]+/)
37
+ else ALWAYS
38
+ end
39
+ end
40
+ end
41
+
42
+ module ScholarlyFilters
43
+ # JSON embedded in a script must not contain an HTML closing tag.
44
+ def jsonify_script(value)
45
+ jsonify(value).gsub("<", '\\u003c').gsub("\u2028", '\\u2028').gsub("\u2029", '\\u2029')
46
+ end
47
+
48
+ # A Liquid filter's name cannot end with "?".
49
+ def scholarly(page) # rubocop:disable Naming/PredicateMethod
50
+ Scholarly.scholarly?(page, @context["site"])
51
+ end
52
+ end
53
+ end
54
+
55
+ Liquid::Template.register_filter(Datalog::ScholarlyFilters)
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datalog
4
+ # Article series: multi-part writing a reader follows in order, whatever
5
+ # was published in between.
6
+ #
7
+ # series: # front matter, as a map
8
+ # id: missing-data
9
+ # title: Missing Data and Statistical Inference
10
+ # order: 3
11
+ #
12
+ # series: missing-data # or flat
13
+ # series_title: Missing Data and Statistical Inference
14
+ # series_order: 3
15
+ #
16
+ # missing-data: # _data/series.yml, so the title lives once
17
+ # title: Missing Data and Statistical Inference
18
+ # description: Four parts, from the missing-data mechanisms to sensitivity analysis.
19
+ #
20
+ # Before the site renders, every part is checked (an order that is missing,
21
+ # not a whole number or taken by another part stops the build), the parts
22
+ # are put in order, and each page's `series` becomes one shape: id, title,
23
+ # description, order, position, count, parts (title, url, order, position,
24
+ # current), previous and next. _includes/components/series-nav.html reads it.
25
+ module Series
26
+ module_function
27
+
28
+ def normalize!(site)
29
+ documents = site.documents + site.pages
30
+ registry = site.data["series"].is_a?(Hash) ? site.data["series"] : {}
31
+ documents.filter_map { |document| part(document) }.group_by { |part| part[:id] }.each do |id, parts|
32
+ check_orders!(id, parts)
33
+ meta = registry[id].is_a?(Hash) ? registry[id] : {}
34
+ resolve!(id, parts.sort_by { |part| part[:order] }, meta)
35
+ end
36
+ end
37
+
38
+ # The document's part of a series, as {doc, id, order, title}, or nil.
39
+ def part(document)
40
+ data = document.data
41
+ value = data["series"]
42
+ return if value.nil? || value == false || (value.is_a?(String) && value.strip.empty?)
43
+
44
+ given = case value
45
+ when Hash then value.transform_keys(&:to_s)
46
+ when String, Symbol then { "id" => value.to_s }
47
+ else stop(document, "has a series that is neither a name nor a map with an id and an order")
48
+ end
49
+ id = given["id"].to_s.strip
50
+ stop(document, "has a series without an id, such as series: missing-data") if id.empty?
51
+
52
+ order = given["order"] || data["series_order"]
53
+ unless whole_number?(order)
54
+ stop(document, "is part of the series \"#{id}\" without an order; give the part a whole number from 1, " \
55
+ "such as order: 2")
56
+ end
57
+
58
+ { doc: document, id: id, order: order.to_i, title: given["title"] || data["series_title"] }
59
+ end
60
+
61
+ def whole_number?(value)
62
+ (value.is_a?(Integer) && value >= 1) || (value.is_a?(String) && value.match?(/\A[1-9]\d*\z/))
63
+ end
64
+
65
+ def check_orders!(id, parts)
66
+ parts.group_by { |part| part[:order] }.each_value do |same|
67
+ next if same.size == 1
68
+
69
+ paths = same.map { |part| part[:doc].relative_path }.sort.join(" and ")
70
+ raise Jekyll::Errors::FatalException,
71
+ "#{paths} are both part #{same.first[:order]} of the series \"#{id}\"; each part needs its own order"
72
+ end
73
+ end
74
+
75
+ # Writes each part's `series` from the ordered parts and the data file's entry.
76
+ def resolve!(id, ordered, meta)
77
+ title = meta["title"] || ordered.filter_map { |part| part[:title] }.first || titleize(id)
78
+ summaries = ordered.each_with_index.map do |part, index|
79
+ { "title" => part[:doc].data["title"], "url" => part[:doc].url, "order" => part[:order],
80
+ "position" => index + 1 }
81
+ end
82
+ ordered.each_with_index do |part, index|
83
+ part[:doc].data["series"] = {
84
+ "id" => id, "title" => title, "description" => meta["description"],
85
+ "order" => part[:order], "position" => index + 1, "count" => ordered.size,
86
+ "parts" => summaries.map { |summary| summary.merge("current" => summary["url"] == part[:doc].url) },
87
+ "previous" => (summaries[index - 1] if index.positive?), "next" => summaries[index + 1]
88
+ }.compact
89
+ end
90
+ end
91
+
92
+ def titleize(id)
93
+ id.tr("-_", " ").split.map(&:capitalize).join(" ")
94
+ end
95
+
96
+ def stop(document, problem)
97
+ raise Jekyll::Errors::FatalException, "#{document.relative_path} #{problem}"
98
+ end
99
+ end
100
+ end
101
+
102
+ Jekyll::Hooks.register :site, :post_read do |site|
103
+ Datalog::Series.normalize!(site)
104
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+
5
+ module Datalog
6
+ # Theorems, lemmas and the other statements of mathematical writing, and
7
+ # proofs. Articles marked them with a blockquote and a bold "Theorem 1.",
8
+ # typed by hand:
9
+ #
10
+ # {% theorem id="thm-consistency" title="Consistency" %}
11
+ # Let $\hat\theta_n$ be ...
12
+ # {% endtheorem %}
13
+ #
14
+ # {% proof for="thm-consistency" %}
15
+ # ...
16
+ # {% endproof %}
17
+ #
18
+ # Statements are numbered with figures and tables (_plugins/references.rb):
19
+ # each kind counts on its own, {% ref thm-consistency %} reads "Theorem 1",
20
+ # and a duplicate id stops the build. `label="A"` names a statement
21
+ # "Theorem A" instead of numbering it. A proof is not numbered; with `for`
22
+ # its heading reads "Proof of Theorem 1".
23
+ class StatementTag < Liquid::Block
24
+ def initialize(tag_name, markup, options)
25
+ super
26
+ @kind = tag_name
27
+ @markup = markup
28
+ end
29
+
30
+ def render(context)
31
+ attributes = References.attributes(@markup, context, @kind)
32
+ id = References.validate_id(attributes["id"], @kind)
33
+ custom = attributes["label"]
34
+ References.validate_label(custom, @kind)
35
+ body = References.markdown(context, super)
36
+
37
+ number = custom ? %( data-ref-number="#{CGI.escapeHTML(custom)}") : ""
38
+ title = attributes["title"].to_s.strip
39
+ title = title.empty? ? "" : %( <span class="datalog-statement__title">(#{CGI.escapeHTML(title)})</span>)
40
+ %(<div class="datalog-statement datalog-statement--#{@kind}" role="group" aria-labelledby="#{id}-heading" ) +
41
+ %(id="#{id}" data-ref-target="#{id}" data-ref-kind="#{@kind}"#{number}>) +
42
+ %(<p class="datalog-statement__heading" id="#{id}-heading">) +
43
+ %(<span class="datalog-ref-label" data-ref-for="#{id}" data-ref-end=""></span>#{title}.</p>) +
44
+ %(<div class="datalog-statement__body">#{body.strip}</div></div>\n)
45
+ end
46
+ end
47
+
48
+ class ProofTag < Liquid::Block
49
+ def initialize(tag_name, markup, options)
50
+ super
51
+ @markup = markup
52
+ end
53
+
54
+ def render(context)
55
+ attributes = References.attributes(@markup, context, "proof")
56
+ target = attributes["for"]
57
+ body = References.markdown(context, super)
58
+ heading_id = "proof-#{target ? References.validate_id(target, 'proof') : Statements.next_proof(context)}"
59
+ heading = if target
60
+ link = %(<a class="datalog-ref" href="##{target}" data-ref="#{target}">#{target}</a>)
61
+ I18n.translate(context, "references.proof_of", "target" => link)
62
+ else
63
+ CGI.escapeHTML(I18n.translate(context, "references.proof"))
64
+ end
65
+ end_mark = %(<p class="datalog-proof__end"><span aria-hidden="true">∎</span></p>)
66
+ end_mark = "" if attributes["qed"] == "false"
67
+
68
+ %(<div class="datalog-proof" role="group" aria-labelledby="#{heading_id}">) +
69
+ %(<p class="datalog-proof__heading" id="#{heading_id}">#{heading}.</p>) +
70
+ %(<div class="datalog-proof__body">#{body.strip}</div>#{end_mark}</div>\n)
71
+ end
72
+ end
73
+
74
+ module Statements
75
+ module_function
76
+
77
+ KINDS = %w[theorem lemma proposition corollary definition assumption example remark].freeze
78
+
79
+ # Proofs without a statement are numbered in the page for their heading ids only.
80
+ def next_proof(context)
81
+ context.registers[:datalog_proofs] = context.registers[:datalog_proofs].to_i + 1
82
+ end
83
+ end
84
+ end
85
+
86
+ Datalog::Statements::KINDS.each { |kind| Liquid::Template.register_tag(kind, Datalog::StatementTag) }
87
+ Liquid::Template.register_tag("proof", Datalog::ProofTag)
data/_sass/_base.scss CHANGED
@@ -12,7 +12,14 @@
12
12
 
13
13
  html {
14
14
  font-size: $font-size-root;
15
- scroll-behavior: smooth;
15
+ }
16
+
17
+ // Anchor links, and the theme's scripts, which pass no scroll behavior, follow
18
+ // this rule, so a reader who asks for reduced motion jumps to the target.
19
+ @media (prefers-reduced-motion: no-preference) {
20
+ html {
21
+ scroll-behavior: smooth;
22
+ }
16
23
  }
17
24
 
18
25
  body {
@@ -40,6 +47,11 @@ iframe {
40
47
  max-width: 100%;
41
48
  }
42
49
 
50
+ img,
51
+ video {
52
+ height: auto;
53
+ }
54
+
43
55
  a {
44
56
  color: $color-accent-primary;
45
57
  text-decoration-thickness: 0.12em;