bloggie 0.0.0-stage → 0.4.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 (90) hide show
  1. package/AGENTS.md +32 -0
  2. package/LICENSE +202 -0
  3. package/README.md +159 -2
  4. package/astro.config.js +132 -0
  5. package/components/Cite.astro +12 -0
  6. package/components/Info.astro +23 -0
  7. package/components/LoadDemo.svelte +71 -0
  8. package/components/RoleKey.astro +12 -0
  9. package/components/slides/Mark.astro +23 -0
  10. package/components/slides/Notes.astro +5 -0
  11. package/components/slides/Slide.astro +97 -0
  12. package/e2e/browser.js +168 -0
  13. package/e2e/editor.js +710 -0
  14. package/e2e/figures.js +24 -0
  15. package/e2e/helpers.js +15 -0
  16. package/e2e/jump.js +331 -0
  17. package/e2e/live.js +247 -0
  18. package/e2e/run.js +416 -0
  19. package/e2e/toc.js +181 -0
  20. package/editor/client.js +1514 -0
  21. package/editor/css.js +49 -0
  22. package/editor/editor.css +697 -0
  23. package/editor/eyedropper.js +140 -0
  24. package/editor/integration.js +152 -0
  25. package/editor/panel.js +133 -0
  26. package/editor/patch.js +215 -0
  27. package/editor/source.js +668 -0
  28. package/editor/text.js +49 -0
  29. package/jump/annotate.js +99 -0
  30. package/jump/client.js +205 -0
  31. package/jump/integration.js +188 -0
  32. package/jump/vscode.js +75 -0
  33. package/layouts/Base.astro +24 -0
  34. package/layouts/Post.astro +181 -0
  35. package/layouts/Slides.astro +37 -0
  36. package/lib/blog-vite.js +4 -0
  37. package/lib/blog.js +12 -0
  38. package/lib/citations.js +234 -0
  39. package/lib/citations.test.js +30 -0
  40. package/lib/colors.js +21 -0
  41. package/lib/describe.js +16 -0
  42. package/lib/equations.js +67 -0
  43. package/lib/math.js +64 -0
  44. package/lib/post-tables.js +97 -0
  45. package/lib/roles.js +48 -0
  46. package/lib/shiki-mdx.js +56 -0
  47. package/lib/site-url.js +9 -0
  48. package/lib/slide-headings.js +259 -0
  49. package/lib/slides.js +256 -0
  50. package/lib/toc.js +172 -0
  51. package/lib/visibility.js +39 -0
  52. package/live/capture.js +15 -0
  53. package/live/client.js +158 -0
  54. package/live/integration.js +60 -0
  55. package/package.json +49 -4
  56. package/pages/index.astro +89 -0
  57. package/scripts/check-colors.js +135 -0
  58. package/scripts/check-kit.js +49 -0
  59. package/scripts/check-links.js +28 -0
  60. package/scripts/create.js +101 -0
  61. package/scripts/export/agent.js +189 -0
  62. package/scripts/export/common.js +75 -0
  63. package/scripts/export/dev.js +52 -0
  64. package/scripts/export/index.js +21 -0
  65. package/scripts/export/page.js +207 -0
  66. package/scripts/export-posts.js +21 -0
  67. package/scripts/publish.js +111 -0
  68. package/scripts/subtree.js +60 -0
  69. package/scripts/update.js +33 -0
  70. package/skills/bloggie-slides/SKILL.md +240 -0
  71. package/skills/bloggie-slides/check-slides.mjs +65 -0
  72. package/styles/site.css +1713 -0
  73. package/styles/slides.css +697 -0
  74. package/template/.github/workflows/deploy.yml +49 -0
  75. package/template/AGENTS.md +121 -0
  76. package/template/README.md +26 -0
  77. package/template/astro.config.mjs +2 -0
  78. package/template/gitignore +5 -0
  79. package/template/package.json +20 -0
  80. package/template/src/figures/attention-walk/AttentionWalk.svelte +210 -0
  81. package/template/src/figures/attention-walk/attention-walk.js +62 -0
  82. package/template/src/figures/attention-walk/describe.js +19 -0
  83. package/template/src/figures/attention-walk/e2e.js +22 -0
  84. package/template/src/figures/shared/CircleGraph.svelte +165 -0
  85. package/template/src/pages/posts/how-this-blog-works/index.mdx +224 -0
  86. package/template/src/pages/posts/how-this-blog-works/media/slide-editor.png +0 -0
  87. package/template/src/pages/posts/how-this-blog-works/slides.mdx +123 -0
  88. package/template/src/references.json +19 -0
  89. package/template/src/roles.js +12 -0
  90. package/template/src/site.js +14 -0
package/AGENTS.md ADDED
@@ -0,0 +1,32 @@
1
+ # Bloggie, the engine
2
+
3
+ This folder is Bloggie: the layouts, components, slide kit and editor, styles, checks and e2e runner that a blog builds
4
+ with. In a blog it is the npm package `bloggie` (`node_modules/bloggie/`), or, in a blog made with `--git`, the
5
+ `bloggie/` folder, kept as a git subtree of https://github.com/bhoov/bloggie; the blog's own `AGENTS.md` covers posts
6
+ and figures. `template/` is the starter blog that `scripts/create.js` copies (`npx bloggie`), and the demo site
7
+ (`.github/workflows/demo.yml`). `create/` is the npm package `create-bloggie`, which runs `scripts/create.js`.
8
+
9
+ - An engine file imports only engine files, the blog's site data (`src/site.js`, `src/references.json`,
10
+ `src/roles.js`) and npm packages, never a post or a figure; `scripts/check-kit.js` fails the build otherwise.
11
+ - The engine finds the blog by the folder it runs in (`lib/blog.js`), never by a relative path out of the engine:
12
+ an Astro component imports the site data as `@/site.js`; code that Node runs imports it from `lib/blog.js`.
13
+ - Build every feature as a general one, with no post's names or data in it, and say in a comment what it is for.
14
+ - A change here reaches every blog that updates. Keep a blog's files (`src/`, its `astro.config.mjs`, `package.json`)
15
+ working as they are: add before you remove, and say in the commit what a blog must change, if anything.
16
+ - The engine's dependencies are in this folder's `package.json`, under `dependencies`: npm does not install the
17
+ `devDependencies` of a package that a blog depends on. A blog lists `bloggie` as a dependency, or, with `--git`, this
18
+ folder as an npm workspace (npm links it as `node_modules/bloggie`, so a blog's scripts and imports work in both).
19
+ - A release goes to npm: raise the last number of `version` in `package.json`, 0.4.0 to 0.4.1 (the middle number goes
20
+ up once others contribute), and the template's `bloggie` dependency with it; then `npm publish` here. Publish
21
+ `create/` (`create-bloggie`) only when its `index.js` changes.
22
+ - From a blog, `npm run bloggie:push -- -m "…" --yes` (`scripts/publish.js`) publishes `bloggie/` as one new commit on
23
+ top of the engine's main and opens a pull request: to a branch of the engine's repository if you may push there,
24
+ else of your fork (`gh` makes it; without `gh`, `--remote <fork>`). `--main` pushes to main. None of the blog's
25
+ commits or messages go. Write that message for the public.
26
+ - Git: this repository's history is public and holds only engine commits. Commit here directly in a clone of it, or
27
+ publish from a blog with `scripts/publish.js` (one commit per publish, its message written for the public). Never
28
+ `git subtree push` a blog's history here, never force-push main, and keep main buildable: the demo deploys from it.
29
+ A blog takes new commits with `npm run bloggie:update` (`scripts/update.js`). It and `publish.js --main` merge with
30
+ `scripts/subtree.js`, which changes only `bloggie/` and needs only it committed, not `git subtree merge`.
31
+ - Check a change in a blog: `npm run build` and `npm run e2e` there. For the starter blog, make one with
32
+ `node scripts/create.js <folder> --copy-engine` and run the same.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- # Temporary Holding Version
1
+ # Bloggie
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Write one story with your AI agent.
4
+ > Publish it as an interactive blog post that ports to slides when you need them.
5
+
6
+ **Live demo:** the example post, https://bhoov.com/bloggie/posts/how-this-blog-works/, and its deck, https://bhoov.com/bloggie/posts/how-this-blog-works/slides/.
7
+
8
+ Bloggie turns one plain-text story into an interactive blog post.
9
+ When you are ready, an AI agent makes a talk deck from it that runs the same live figures.
10
+ Every post downloads as a single HTML file that works offline.
11
+
12
+ - **One story, two forms.**
13
+ A post, plus an optional slide deck beside it that reuses its figures and tables.
14
+ - **Built to write with an agent.**
15
+ Everything is plain text, one folder per post.
16
+ `AGENTS.md` and the build's checks tell an AI agent how to draft, build figures and check its own work.
17
+ - **You are in control.**
18
+ The agent's slides may not be the slides you want.
19
+ Edit them with the mouse in the dev server, and each change is written back to the deck's text file.
20
+ - **Interactive figures.**
21
+ Everything is HTML, CSS and JavaScript.
22
+ Readers play the demos in the post and on the slides.
23
+ - **Works offline.**
24
+ Each post downloads as one HTML file with working figures, and as a text version for AI readers.
25
+ - **Easy to host.**
26
+ A static site, with a workflow that deploys it to GitHub Pages.
27
+
28
+ ## Start
29
+
30
+ ```sh
31
+ npx bloggie my-blog # start a new blog in my-blog/ and install its packages
32
+ # npx bloggie my-blog --title "My blog" --author "Ada Lovelace"
33
+ # OR add metadata later to `src/site.js`
34
+ cd my-blog && npm run dev # http://localhost:4321/
35
+ ```
36
+
37
+ The new blog is your own git repository; Bloggie, the engine, is an npm package, and `npm run bloggie:update` installs its latest version.
38
+ To contribute to Bloggie's engine, you can instead have bloggie as a git subtree inside your blog using `npx bloggie my-blog --git`, saved to your blog's `bloggie/` folder. See [Contributing](#contributing).
39
+
40
+ Use Node 22 or later.
41
+ See the example post, "How this blog works", for features.
42
+ You can copy that post's folder, `src/pages/posts/how-this-blog-works/`, to `src/pages/posts/<slug>/` to start a post.
43
+
44
+ ## Commands and keys
45
+
46
+ | Command | What it does |
47
+ | --- | --- |
48
+ | `npm run dev` | Preview at http://localhost:4321/ while you write |
49
+ | `npm run build` | Check links and citations, then build `dist/` and each post's downloads |
50
+
51
+ When developing with `npm run dev`, pressing `e` on a deck opens the slide editor that saves without page reloads, and downloads are prepared on click.
52
+ Cmd+Shift+click (Ctrl+Shift+click) on any text, formula or figure of a post or deck opens its source in VS Code at that line, also when the dev server runs on a machine that VS Code reaches over SSH.
53
+
54
+ On a post, press `s` to open its deck, or `t` to fold or open the table of contents.
55
+ On a deck:
56
+
57
+ | Key | What it does |
58
+ | --- | --- |
59
+ | `→` `←` `space` | next, previous slide |
60
+ | `home` `end` | first, last slide |
61
+ | `f` | full screen |
62
+ | `n` | speaker notes |
63
+ | `p` | speaker view, in a second window |
64
+ | `esc` | back to the post |
65
+ | `e` | the slide editor (under `npm run dev`); its keys follow Figma's |
66
+
67
+ ## A post is a story you can play with
68
+
69
+ A post mixes prose, equations, results and live demos.
70
+ A figure is a demo the reader drives in the page; it waits for Play, so the page stays still until the reader asks.
71
+
72
+ <img src=".github/readme/fig-walk.png" width="560" alt="The example post's figure: a walker on a graph of eight nodes, with play controls above and its belief over the nodes beside it.">
73
+
74
+ Equations are typeset when the site builds, numbered and linked as in Quarto, with braces that name their terms and a legend that names their symbols.
75
+
76
+ <img src=".github/readme/equation.png" width="560" alt="The self-attention equation from the example post, with braces under the attention weights and the values, and a legend of its symbols.">
77
+
78
+ Citations are managed for you.
79
+ Add a source once to `src/references.json` and cite it by its key; the post numbers each citation in order of first use, shows the source on hover, and lists every source at the end.
80
+
81
+ ## One story as blog and slides
82
+
83
+ A post can have a slide deck, a talk version in a `slides.mdx` file beside it, which runs the same live figures.
84
+ Once you are happy with the story of your post, ask an AI agent to generate the deck for you.
85
+ The `bloggie-slides` skill ships with the blog, so the agent makes one idea per slide with text large enough for the back of the room, and checks every slide in a browser.
86
+ Then fine-tune it with the mouse in the slide editor.
87
+ Each change goes into `slides.mdx`, so your edits and an agent's mix freely.
88
+ When the post changes, ask the agent to "update the deck for the changes to the post"; it keeps your layout.
89
+
90
+ <img src="template/src/pages/posts/how-this-blog-works/media/slide-editor.png" width="720" alt="The slide editor on the example deck: a toolbar of font, size, color and alignment buttons above the slide, and a column of slide thumbnails on the left.">
91
+
92
+ ## Everything is a plain text file
93
+
94
+ A post is one folder, and every file in it is text you can open in any editor:
95
+
96
+ ```
97
+ src/pages/posts/<slug>/
98
+ index.mdx the post: Markdown, math and figure tags
99
+ slides.mdx its deck (optional)
100
+ data/ media/ the numbers and pictures it shows
101
+ ```
102
+
103
+ The blog's home page is an index that lists every post, newest first.
104
+ You can ask an agent to write a post or its slides, or edit it yourself in Markdown and HTML.
105
+
106
+ ## One style, written down for your agent
107
+
108
+ `AGENTS.md` is the blog's style guide and the manual for any coding agent (Claude Code and Codex both read it).
109
+ Add your own rules, and every agent follows them in every post and deck.
110
+ You write the argument; the agent builds and checks what it needs.
111
+ For example:
112
+
113
+ > Draft a post in `src/pages/posts/<slug>/` from these notes: …
114
+ >
115
+ > Build a figure for the post that shows …
116
+ >
117
+ > Read the post as a first-time reader in a browser, use every control, and list what is unclear.
118
+ >
119
+ > Make slides for the post with the bloggie-slides skill.
120
+
121
+ A note written as `((…))` anywhere in a file asks the agent to address it and remove it (`AGENTS.md` has the rule).
122
+
123
+ ## Download for offline distribution
124
+
125
+ The <img src=".github/readme/download.svg" height="14" alt="download"> in each post's byline downloads the post as one HTML file, with its styles, figures and deck inside.
126
+ It opens from disk with no internet, so you can present from a laptop offline or send the post by email.
127
+ The menu beside it also offers the post as text for an AI agent.
128
+
129
+ ## Publish
130
+
131
+ Push to `main`, and GitHub Actions builds the site and publishes it to GitHub Pages.
132
+ Once, in the repository's Settings → Pages, set the source to GitHub Actions.
133
+
134
+ ## Contributing
135
+
136
+ The easiest way to contribute is to start your blog with `npx bloggie my-blog --git`.
137
+ The blogging engine is then placed into your blog's `bloggie/` folder, a git subtree of this repository, and you work on your blog as usual.
138
+ When you have an idea that would improve the engine for every blog, make the change in `bloggie/`, commit it, and run:
139
+
140
+ ```sh
141
+ npm run bloggie:update # merge this repository's latest main first
142
+ npm run bloggie:push -- -m "What changed" --body "Why" # list the files that would change; nothing is sent
143
+ npm run bloggie:push -- -m "What changed" --body "Why" --yes # send it and open a pull request
144
+ ```
145
+
146
+ With the GitHub CLI (`gh`) logged in, the last command makes your fork if needed, pushes the change to a branch of it and opens a pull request here.
147
+ Without `gh`, fork this repository, add `--remote <your fork's URL>`, and open the pull request from the link it prints.
148
+ Only the content of `bloggie/` goes, as one commit on top of this repository's main; none of your blog's commits or messages do.
149
+ Once the pull request is merged, `npm run bloggie:update` brings it into your blog.
150
+
151
+ In a blog that uses Bloggie as an npm package, make the change in a clone of this repository instead (`gh repo fork bhoov/bloggie --clone`), and open the pull request from there.
152
+
153
+ This repository is the engine; `template/` is the starter blog that `npx bloggie` copies and the demo site shows.
154
+ To check a change to the starter blog, make one with `node scripts/create.js ../demo --copy-engine` and run `npm run build` there.
155
+ `AGENTS.md` has the engine's rules.
156
+
157
+ ## License
158
+
159
+ Apache 2.0.
160
+ See [LICENSE](LICENSE).
@@ -0,0 +1,132 @@
1
+ // Bloggie's build configuration. A blog's astro.config.mjs is one line, `export { default } from 'bloggie/astro.config.js'`,
2
+ // and this file, in the engine (node_modules/bloggie/, or the blog's bloggie/ folder), holds the rest. Posts and slides are MDX pages under the
3
+ // blog's src/pages; figures are Svelte components under its src/figures. Math is typeset at build time by KaTeX;
4
+ // lib/equations.js numbers labelled equations and resolves [](#eq-id) references.
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
+ import { existsSync } from 'node:fs'
7
+ import { relative } from 'node:path'
8
+ import { defineConfig } from 'astro/config'
9
+ import mdx from '@astrojs/mdx'
10
+ import svelte from '@astrojs/svelte'
11
+ import { unified } from '@astrojs/markdown-remark'
12
+ import remarkMath from 'remark-math'
13
+ import rehypeKatex from 'rehype-katex'
14
+ import remarkEquations from './lib/equations.js'
15
+ import { root } from './lib/blog.js'
16
+ import { katexMacros, remarkRoles } from './lib/roles.js'
17
+ import remarkPostTables from './lib/post-tables.js'
18
+ import remarkSlideHeadings, { rehypeSlideBoxes } from './lib/slide-headings.js'
19
+ import postDownloads from './scripts/export/dev.js'
20
+ import slideEditor from './editor/integration.js'
21
+ import liveUpdate from './live/integration.js'
22
+ import jumpToSource from './jump/integration.js'
23
+ import { rehypeSourcePositions, withMathPositions } from './jump/annotate.js'
24
+ import tsx from 'shiki/langs/tsx.mjs'
25
+ import latex from 'shiki/langs/latex.mjs'
26
+ import markdownLang from 'shiki/langs/markdown.mjs'
27
+ import { mdxGrammar } from './lib/shiki-mdx.js'
28
+
29
+ // Dev only. Astro links each server-rendered Svelte component's CSS module, and the browser may ask for it before the
30
+ // client has compiled the component (a client:visible island that has not hydrated). vite-plugin-svelte then finds no
31
+ // compiled CSS, and Vite serves the raw .svelte file as CSS: the first rule is lost and the rest lose their scoping, so
32
+ // one figure's styles leak onto the whole page (a Load demo cover over the title, figures out of shape). Compile the
33
+ // component first, and serve its CSS.
34
+ function svelteCssInDev() {
35
+ let server
36
+ return {
37
+ name: 'svelte-css-in-dev',
38
+ apply: 'serve',
39
+ configureServer(s) { server = s },
40
+ async load(id) {
41
+ if (!/[?&]svelte&type=style&lang\.css$/.test(id)) return
42
+ const filename = id.replace(/\?.*$/, '')
43
+ if (this.getModuleInfo(filename)?.meta?.svelte?.css) return // compiled here: vite-plugin-svelte serves it
44
+ // The server's compile of the component made the page's class names, so its CSS is the one that matches them.
45
+ // transformRequest compiles it again if the file changed since, and otherwise returns the compile it has.
46
+ const ssr = server?.environments?.ssr
47
+ if (!ssr) return
48
+ await ssr.transformRequest(`/${relative(server.config.root, filename)}`).catch(() => {})
49
+ const css = ssr.moduleGraph.getModuleById(filename)?.meta?.svelte?.css
50
+ if (!css) return
51
+ this.addWatchFile(filename)
52
+ return { code: css.code, map: css.map, moduleType: 'css' }
53
+ },
54
+ }
55
+ }
56
+
57
+ // Under Vite (pages, figures, the browser), lib/blog.js is lib/blog-vite.js: the same site data, through `@/`.
58
+ function blogInVite() {
59
+ const node = fileURLToPath(new URL('./lib/blog.js', import.meta.url))
60
+ const vite = fileURLToPath(new URL('./lib/blog-vite.js', import.meta.url))
61
+ return {
62
+ name: 'bloggie-blog',
63
+ enforce: 'pre',
64
+ async resolveId(source, importer, options) {
65
+ if (!source.endsWith('blog.js')) return null
66
+ const resolved = await this.resolve(source, importer, { ...options, skipSelf: true })
67
+ return resolved?.id === node ? vite : null
68
+ },
69
+ }
70
+ }
71
+
72
+ // The blog is the folder Astro runs in (lib/blog.js); `@/` is its src/.
73
+ const blog = pathToFileURL(root + '/')
74
+ const engine = new URL('./', import.meta.url)
75
+
76
+ // The home page (pages/index.astro): every post, newest first. A blog with its own src/pages/index.astro uses that.
77
+ function homePage() {
78
+ return {
79
+ name: 'bloggie-home-page',
80
+ hooks: {
81
+ 'astro:config:setup': ({ injectRoute }) => {
82
+ if (existsSync(new URL('src/pages/index.astro', blog))) return
83
+ injectRoute({ pattern: '/', entrypoint: fileURLToPath(new URL('pages/index.astro', engine)) })
84
+ },
85
+ },
86
+ }
87
+ }
88
+
89
+ export default defineConfig({
90
+ root: fileURLToPath(blog),
91
+ // GitHub Pages serves a project site under /<repo>/; the deploy workflow sets BASE_PATH.
92
+ base: process.env.BASE_PATH || '/',
93
+ // postDownloads: the download links under `npm run dev`; liveUpdate: a save of a post draws its change in the
94
+ // open page, without a reload (live/); slideEditor: edit a deck with the mouse and keyboard under
95
+ // `npm run dev`, written to its slides.mdx (editor/). liveUpdate goes before slideEditor (live/integration.js).
96
+ // jumpToSource: under `npm run dev`, Cmd+Shift+click opens the source of what is clicked in VS Code (jump/).
97
+ // hmr: false: a change to a figure's .svelte or .js reloads the page, so every figure starts over,
98
+ // instead of a hot swap that keeps the figure's state and leaves its old animation loops running.
99
+ // optimize: MDX compiles the static parts of a page to HTML strings; the page is the same, and the
100
+ // dev server compiles a deck again after a slide editor edit in about half the time. A <style> or
101
+ // <script> stays an element (a Box's inner rules are a <style>): in an HTML string, Astro drops its text.
102
+ integrations: [mdx({ optimize: { ignoreElementNames: ['style', 'script'] } }), svelte({ compilerOptions: { hmr: false } }), postDownloads(), liveUpdate(), slideEditor(), jumpToSource(), homePage()],
103
+ devToolbar: { enabled: false }, // no Astro toolbar over the page under `npm run dev`
104
+ // `@/` is src/, so posts import `@/figures/attention-walk/AttentionWalk.svelte` instead of ../../../ paths; `@bloggie/` is
105
+ // bloggie/, the engine (`@bloggie/components/Cite.astro`, a post's `layout: '@bloggie/layouts/Post.astro'`).
106
+ vite: {
107
+ plugins: [svelteCssInDev(), blogInVite()],
108
+ resolve: { alias: { '@': fileURLToPath(new URL('src', blog)), '@bloggie': fileURLToPath(engine).replace(/\/$/, '') } },
109
+ build: { assetsInlineLimit: 0 }, // keep imported files (e.g. a figure's JSON parameters) as real, linkable files
110
+ // Pre-bundle the figures' dependencies at dev-server start. Found later, at a figure's first
111
+ // import, they make Vite re-optimize and answer the open page with "504 Outdated Optimize Dep".
112
+ // The engine as an npm package (node_modules/bloggie/) is source, not a dependency to pre-bundle or leave to Node:
113
+ // Vite compiles its .astro and .svelte files, applies `@/` in them, and keeps one copy of each module.
114
+ optimizeDeps: { include: ['d3', 'katex'], exclude: ['bloggie'] },
115
+ ssr: { noExternal: ['bloggie'] },
116
+ // The dev server watches the whole project: not the Python environment, or what a post's runs write.
117
+ server: { watch: { ignored: ['**/.venv/**', '**/__pycache__/**', '**/_experiments/runs/**', '**/_experiments/logs/**'] } },
118
+ },
119
+ markdown: {
120
+ // `mdx` code blocks: imports and component tags as TSX, math as LaTeX (lib/shiki-mdx.js).
121
+ shikiConfig: { langs: [...tsx, ...latex, ...markdownLang, mdxGrammar] },
122
+ processor: unified({
123
+ remarkPlugins: [remarkMath, remarkPostTables, remarkEquations, remarkRoles, remarkSlideHeadings], // roles: the post's color key; slide-headings: # / ## shorthand in slides.mdx
124
+ rehypePlugins: [[withMathPositions(rehypeKatex), {
125
+ // \state{v} and the other role macros (lib/roles.js) color a symbol with \htmlClass; nothing else is trusted.
126
+ macros: katexMacros,
127
+ trust: (context) => context.command === '\\htmlClass',
128
+ strict: (code) => (code === 'htmlExtension' ? 'ignore' : 'warn'),
129
+ }], rehypeSlideBoxes, rehypeSourcePositions], // slide-boxes: a <Box style> in slides.mdx styles the element it holds; source-positions: dev only, last (jump/annotate.js)
130
+ }),
131
+ },
132
+ })
@@ -0,0 +1,12 @@
1
+ ---
2
+ // <Cite key="vaswani2017">[Transformer]</Cite> links to a source in src/references.json; on the page,
3
+ // bloggie/lib/citations.js numbers it in order of first use, [1], shows the source on hover, and lists it
4
+ // under References at the end of the post. Text in brackets is replaced by the number; other words stay,
5
+ // with the number after them (<Cite key="brouard2020">Brouard et al.</Cite> learn ...). Several sources:
6
+ // key="smith2020,lee2021" renders [1, 2] (the link goes to the first). An unknown key fails the build.
7
+ import catalog from '@/references.json'
8
+
9
+ const keys = Astro.props.key.split(',').map((key) => key.trim())
10
+ for (const key of keys) if (!catalog[key]) throw new Error(`<Cite>: unknown reference key "${key}"`)
11
+ ---
12
+ <a data-cite={keys.join(',')} href={catalog[keys[0]].url}><slot /></a>
@@ -0,0 +1,23 @@
1
+ ---
2
+ // <Info label="Solved">the mean over 3 seeds</Info> puts an (i) button after a short label, such as a table's column
3
+ // label, and its note in a popover. <Info term="learned early exit">…</Info> makes the words themselves the button,
4
+ // underlined with dots. The note shows while the pointer rests on the button; a press opens it until a press
5
+ // outside or Esc, which is how it opens on a touch screen. The note is Markdown, math and links included. It needs
6
+ // no script, so it works in the downloaded page too; the agent download writes it in parentheses after the label or
7
+ // term (bloggie/scripts/export/agent.js). The id comes from the note, numbered when a page repeats one, so that every build
8
+ // gives the same page.
9
+ import { createHash } from 'node:crypto'
10
+
11
+ const { label = '', term } = Astro.props
12
+ const note = await Astro.slots.render('default')
13
+ const base = `info-${createHash('sha1').update(label + (term ?? '') + note).digest('hex').slice(0, 8)}`
14
+ // Astro.request is the same object for every component of one page, so this counts repeats within the page.
15
+ const seen = (globalThis.__infoIds ??= new WeakMap())
16
+ if (!seen.has(Astro.request)) seen.set(Astro.request, new Map())
17
+ const count = (seen.get(Astro.request).get(base) ?? 0) + 1
18
+ seen.get(Astro.request).set(base, count)
19
+ const id = count === 1 ? base : `${base}-${count}`
20
+ ---
21
+ <span class="info">{term
22
+ ? <button type="button" class="info-term" popovertarget={id} style={`anchor-name: --${id}`}>{term}</button>
23
+ : <button type="button" class="info-button" popovertarget={id} aria-label={label ? `About ${label}` : 'More'} style={`anchor-name: --${id}`}></button>}<span id={id} class="info-note" popover="auto" style={`position-anchor: --${id}`} set:html={note} /></span>
@@ -0,0 +1,71 @@
1
+ <!--
2
+ The cover of a demo that needs seconds of work or large data before it can run. Until the reader presses its one
3
+ large "Load demo" button, the demo's first frame shows blurred under it, and the demo's controls are inert.
4
+ The figure keeps its caption outside, so the reader can read what the demo is before loading it.
5
+
6
+ <LoadDemo {loaded} onload={load} disabled={!mounted} note="About 15 s of computing, in the background">
7
+ …the figure's controls and panels…
8
+ </LoadDemo>
9
+ -->
10
+ <script>
11
+ let { loaded, onload, disabled = false, note = '', children } = $props()
12
+ const noteId = $props.id()
13
+ </script>
14
+
15
+ <div class="load-demo">
16
+ <div class="load-demo-content" inert={!loaded}>{@render children()}</div>
17
+ {#if !loaded}
18
+ <div class="load-demo-cover">
19
+ <button type="button" class="load-demo-button" onclick={onload} {disabled} aria-label="load demo" aria-describedby={note ? noteId : undefined}>Load demo</button>
20
+ {#if note}<p class="load-demo-note" id={noteId}>{note}</p>{/if}
21
+ </div>
22
+ {/if}
23
+ </div>
24
+
25
+ <style>
26
+ .load-demo {
27
+ position: relative;
28
+ }
29
+ .load-demo-cover {
30
+ position: absolute;
31
+ inset: -0.35rem;
32
+ z-index: 2;
33
+ display: flex;
34
+ flex-direction: column;
35
+ align-items: center;
36
+ justify-content: center;
37
+ gap: 0.6rem;
38
+ border-radius: 4px;
39
+ background: color-mix(in srgb, var(--surface-1) 60%, transparent);
40
+ /* Unprefixed only: the build adds -webkit- for Safari, and given both it keeps only that one, which Chrome ignores. */
41
+ backdrop-filter: blur(8px);
42
+ }
43
+ .load-demo-button {
44
+ font: 650 1.25rem/1 var(--sans);
45
+ color: #fff;
46
+ background: var(--series-1);
47
+ border: 0;
48
+ border-radius: 8px;
49
+ padding: 0.9rem 2rem;
50
+ cursor: pointer;
51
+ box-shadow: 0 2px 10px color-mix(in srgb, var(--text-primary) 18%, transparent);
52
+ transition: background 0.15s, box-shadow 0.15s;
53
+ }
54
+ .load-demo-button:hover:not(:disabled) {
55
+ background: color-mix(in srgb, var(--series-1) 85%, #000);
56
+ }
57
+ .load-demo-button:focus-visible {
58
+ outline: none;
59
+ box-shadow: 0 0 0 4px color-mix(in srgb, var(--series-1) 35%, transparent);
60
+ }
61
+ .load-demo-button:disabled {
62
+ opacity: 0.6;
63
+ cursor: default;
64
+ }
65
+ .load-demo-note {
66
+ margin: 0;
67
+ font: 0.85rem/1.35 var(--sans);
68
+ color: var(--text-secondary);
69
+ text-align: center;
70
+ }
71
+ </style>
@@ -0,0 +1,12 @@
1
+ ---
2
+ // <RoleKey />: every symbol role of this blog (src/roles.js) as a list, each with its example symbol in its color, its
3
+ // label and its meaning. A post that explains its colors shows the blog's own roles with it, so the text stays true when
4
+ // the roles change. The byline's key (Post.astro) lists only the roles a post uses.
5
+ import katex from 'katex'
6
+ import { katexMacros, roles } from '../lib/roles.js'
7
+
8
+ const math = (tex) => katex.renderToString(tex, { macros: katexMacros, trust: (context) => context.command === '\\htmlClass', strict: 'ignore' })
9
+ ---
10
+ <ul class="role-list">
11
+ {roles.map((role) => <li><Fragment set:html={math(`\\${role.name}{${role.example}}`)} /> <b>{role.label}</b>: {role.meaning}.</li>)}
12
+ </ul>