bloggie 0.4.3 → 0.4.5

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.
package/lib/pages.js ADDED
@@ -0,0 +1,29 @@
1
+ // Where a page sits among the posts, for the features that depend on it: the deck link, the downloads and the share
2
+ // link (layouts/Post.astro, scripts/export-posts.js, scripts/export/).
3
+ //
4
+ // A post is src/pages/posts/<slug>/index.mdx, at /posts/<slug>/; the home page lists it. Every other page under
5
+ // src/pages/posts/ is a subpage, which the home page does not list:
6
+ // a file beside a post's index.mdx posts/<slug>/<name>.mdx -> /posts/<slug>/<name>/
7
+ // a folder inside a post posts/<slug>/<name>/index.mdx -> /posts/<slug>/<name>/
8
+ // A page's path is its URL under posts/, without slashes at either end: '<slug>' for a post, '<slug>/<name>' (or
9
+ // deeper) for a subpage.
10
+
11
+ // The page's path from its URL path (`base` is the site's base path, import.meta.env.BASE_URL); null outside posts/.
12
+ export function pagePath(pathname, base = '/') {
13
+ const prefix = `${base.replace(/\/?$/, '/')}posts/`
14
+ if (!pathname.startsWith(prefix)) return null
15
+ return pathname.slice(prefix.length).replace(/\/+$/, '') || null
16
+ }
17
+
18
+ export const isSubpage = (path) => path.includes('/')
19
+
20
+ // A page offers the two downloads unless its front matter says otherwise (`downloads: false` on a post,
21
+ // `downloads: true` on a subpage). Subpages default to none: each download costs build time (see
22
+ // scripts/export-posts.js), and a subpage is usually reached from its post.
23
+ export const offersDownloads = (frontmatter, path) => frontmatter.downloads ?? !isSubpage(path)
24
+
25
+ // The downloads' file names, beside the page: named after the last part of its path.
26
+ export function downloadNames(path) {
27
+ const name = path.split('/').at(-1)
28
+ return { page: `${name}.html`, agent: `${name}-agent.html` }
29
+ }
package/lib/slides.js CHANGED
@@ -37,6 +37,8 @@ export function initDeck(deck) {
37
37
  const count = document.querySelector('.deck-count')
38
38
  const progress = document.querySelector('.deck-progress > div')
39
39
  const notesPanel = document.querySelector('.deck-notes')
40
+ // The YouTube player's command to pause, through its iframe API (components/YouTube.astro).
41
+ const YOUTUBE_PAUSE = JSON.stringify({ event: 'command', func: 'pauseVideo', args: [] })
40
42
  let index = 0
41
43
  let step = 0
42
44
 
@@ -57,6 +59,9 @@ export function initDeck(deck) {
57
59
  slide.inert = k !== index
58
60
  // A video keeps playing only on its own slide.
59
61
  if (k !== index) slide.querySelectorAll('video').forEach((v) => v.pause())
62
+ if (k !== index) slide.querySelectorAll('iframe.youtube').forEach((f) => f.contentWindow?.postMessage(YOUTUBE_PAUSE, '*'))
63
+ // An embedded page (components/Embed.astro) loads one slide early, so it is ready when its slide comes.
64
+ if (k === index || k === index + 1) slide.querySelectorAll('iframe.embed[data-src]').forEach((f) => { f.src = f.dataset.src; f.removeAttribute('data-src') })
60
65
  })
61
66
  steps.forEach((els, k) => els.forEach((el) => el.classList.toggle('shown', k < step)))
62
67
  count.textContent = `${index + 1} / ${slides.length}`
@@ -94,6 +99,11 @@ export function initDeck(deck) {
94
99
  // A focused control keeps the keys it uses. Text fields, sliders, selects and videos use the
95
100
  // arrows, Space, Home and End; a button, a <summary>, a checkbox or a clickable node uses only
96
101
  // Space and Enter, so the arrows still move the deck after a figure's button is clicked.
102
+ // A click in a YouTube player (components/YouTube.astro) moves the keyboard focus into its frame, where the deck's
103
+ // keys never arrive. Take the focus back, so that → still moves the deck; the video keeps playing.
104
+ addEventListener('blur', () => setTimeout(() => {
105
+ if (document.activeElement?.matches('.deck iframe.youtube')) document.activeElement.blur()
106
+ }))
97
107
  const ALL_KEYS = 'input:not([type="checkbox"], [type="radio"], [type="button"]), select, textarea, [role="slider"], [contenteditable], video'
98
108
  const PRESS_KEYS = 'button, summary, a[href], input[type="checkbox"], input[type="radio"], [role="button"]'
99
109
  const ownsKey = (target, key) => target instanceof Element &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bloggie",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Write one story with your AI agent. Publish it as an interactive blog post that ports to slides when you need them.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/pages/index.astro CHANGED
@@ -2,61 +2,88 @@
2
2
  // The home page: every post under the blog's src/pages/posts/<slug>/index.mdx, newest first. The engine adds it as
3
3
  // the route / (astro.config.js), unless the blog has a src/pages/index.astro of its own. A folder whose
4
4
  // name starts with "_" is not a page (Astro skips it), so it is not listed either.
5
- // A post with no tags is part of the main story. Front matter `tags: [wip]` or `tags: [archived]` sets a post apart:
6
- // the reader shows or hides each tag with a checkbox above the list, and a post shows when none of its tags is off.
7
- // Front matter `edited:` is the date of the post's last edit. When the reader checks "Last edited", the list shows it
8
- // after the publication date (for a post edited after the day it was published) and orders the posts by it, most
9
- // recently edited first; a post with no `edited:` counts as last edited on its publication date.
5
+ //
6
+ // Tags. Front matter `tags: [wip]` or `tags: [archived]` marks a post; a post with no tags is part of the main story.
7
+ // One tag is computed, not written: `slides`, for a post with a deck (slides.mdx beside it, unless its front matter
8
+ // sets `slides: false`, as for its byline in layouts/Post.astro). Such a post has the slides icon to the left of its
9
+ // title, a link to the deck.
10
+ //
11
+ // Above the list, a chip per tag in use filters the list, one at a time: "All" shows every post but those with a
12
+ // hidden tag (archived), a tag's chip shows only the posts with that tag (and none with a hidden tag, unless the chip
13
+ // is that tag), and a click on the chosen chip goes back to All. A menu sorts the list: newest first, recently
14
+ // updated first (front matter `edited:`, else the publication date), or oldest first. A post edited after the day it
15
+ // was published shows "updated <date>". The chip and the sort are in the URL (?tag=slides&sort=updated), so a view can
16
+ // be linked to, and Back comes back to it.
17
+ import { existsSync } from 'node:fs'
18
+ import { join } from 'node:path'
10
19
  import Base from '../layouts/Base.astro'
11
20
  import { parseFrontmatter } from '@astrojs/markdown-remark'
12
21
  import { site, longDate, isoDate } from '@/site.js'
13
22
 
14
- // Each tag's name, its mark after a post's title (an icon, else the name), and whether it starts hidden.
15
- // A tag not listed here is shown, with its own word as its name.
23
+ const SLIDES_ICON = '<svg class="slides-icon" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M1 2.5h14M2.5 2.5v8h11v-8M8 10.5V13M8 13l-2.5 2.5M8 13l2.5 2.5M5 8.5l2-2 1.5 1.5L11 5" /></svg>'
24
+
25
+ // Each tag's name, its mark after a post's title (an icon, else the name; `svg` is drawn in the chip only), and
26
+ // whether it is left out of All. A tag not listed here is shown, with its own word as its name.
16
27
  const TAGS = {
28
+ slides: { name: 'Slides', svg: SLIDES_ICON, computed: true },
17
29
  wip: { name: 'Work in progress', icon: '🚧' },
18
30
  archived: { name: 'Archived', hidden: true },
19
31
  }
20
32
  const tag = (id) => TAGS[id] ?? { name: id }
33
+ const SORTS = [['newest', 'Newest'], ['updated', 'Recently updated'], ['oldest', 'Oldest']]
21
34
 
22
35
  // Each post is read as text, for its front matter only. Importing it would compile the post and every figure it uses,
23
36
  // so one post that does not compile (an agent in the middle of an edit) would take this page down with it.
24
37
  const posts = Object.entries(import.meta.glob(['/src/pages/posts/*/index.mdx', '!/src/pages/posts/_*/index.mdx'], { query: '?raw', import: 'default', eager: true }))
25
- .map(([path, text]) => ({ ...parseFrontmatter(text).frontmatter, url: import.meta.env.BASE_URL + path.slice('/src/pages/'.length, -'index.mdx'.length) }))
26
- .map((post) => ({ ...post, tags: [post.tags ?? []].flat().map(String) }))
38
+ .map(([path, text]) => ({ ...parseFrontmatter(text).frontmatter, path, url: import.meta.env.BASE_URL + path.slice('/src/pages/'.length, -'index.mdx'.length) }))
39
+ .map((post) => ({ ...post, deck: post.slides !== false && existsSync(join(process.cwd(), post.path.slice(1, -'index.mdx'.length), 'slides.mdx')) }))
40
+ .map((post) => ({ ...post, tags: [...(post.deck ? ['slides'] : []), ...[post.tags ?? []].flat().map(String).filter((id) => !tag(id).computed)] }))
27
41
  .sort((a, b) => new Date(b.date) - new Date(a.date))
28
42
 
29
- // The tags in use, those of TAGS first and in its order, each with its number of posts.
30
- const used = [...new Set([...Object.keys(TAGS), ...posts.flatMap((post) => post.tags)])]
31
- .map((id) => ({ id, ...tag(id), count: posts.filter((post) => post.tags.includes(id)).length }))
43
+ const hidden = (post) => post.tags.some((id) => tag(id).hidden)
44
+ // The posts a chip shows (the chip of `id`, or All for null), as the script below also decides.
45
+ const shows = (post, id) => (id ? post.tags.includes(id) && (tag(id).hidden || !hidden(post)) : !hidden(post))
46
+ // The tags in use, those of TAGS first and in its order, each with the number of posts its chip shows.
47
+ const chips = [...new Set([...Object.keys(TAGS), ...posts.flatMap((post) => post.tags)])]
48
+ .map((id) => ({ id, ...tag(id), count: posts.filter((post) => shows(post, id)).length }))
32
49
  .filter((t) => t.count)
33
- const hiddenAtFirst = (post) => post.tags.some((id) => tag(id).hidden)
34
50
  const wasEdited = (post) => post.edited && isoDate(post.edited) > isoDate(post.date)
35
51
  ---
36
52
  <Base title={site.title}>
37
53
  <main class="wrap">
38
54
  <h1>{site.title}</h1>
39
55
  <p class="lede">{site.lede}</p>
40
- <fieldset class="post-filter">
41
- <legend>Show</legend>
42
- {used.map((t) => (
43
- <label>
44
- <input type="checkbox" name="tag" value={t.id} checked={!t.hidden} />
45
- {t.icon && <span aria-hidden="true">{t.icon}</span>} {t.name} <span class="count">({t.count})</span>
46
- </label>
47
- ))}
48
- <label>
49
- <input type="checkbox" name="edited" /> Last edited
56
+ <div class="post-controls">
57
+ <fieldset class="post-filter" data-hidden={Object.keys(TAGS).filter((id) => TAGS[id].hidden).join(' ')}>
58
+ <legend>Tags</legend>
59
+ <label class="chip"><input type="radio" name="tag" value="" checked /> All <span class="count">{posts.filter((post) => shows(post, null)).length}</span></label>
60
+ {chips.map((t) => (
61
+ <label class="chip">
62
+ <input type="radio" name="tag" value={t.id} />
63
+ {t.svg ? <Fragment set:html={t.svg} /> : t.icon && <span aria-hidden="true">{t.icon}</span>} {t.name} <span class="count">{t.count}</span>
64
+ </label>
65
+ ))}
66
+ </fieldset>
67
+ <label class="post-sort">
68
+ Sort
69
+ <select name="sort">
70
+ {SORTS.map(([value, name]) => <option value={value}>{name}</option>)}
71
+ </select>
50
72
  </label>
51
- </fieldset>
52
- <ol class="post-list" reversed>
73
+ </div>
74
+ <ol class="post-list">
53
75
  {posts.map((post, n) => (
54
- <li data-order={n} data-tags={post.tags.join(' ')} data-date={isoDate(post.date)} data-edited={isoDate(post.edited ?? post.date)} hidden={hiddenAtFirst(post)}>
76
+ <li data-order={n} data-tags={post.tags.join(' ')} data-date={isoDate(post.date)} data-edited={isoDate(post.edited ?? post.date)} hidden={!shows(post, null)}>
55
77
  <time datetime={isoDate(post.date)}>{longDate(post.date)}</time>
56
- {wasEdited(post) && <span class="post-edited" hidden> · edited <time datetime={isoDate(post.edited)}>{longDate(post.edited)}</time></span>}
78
+ {wasEdited(post) && <span class="post-edited"> · updated <time datetime={isoDate(post.edited)}>{longDate(post.edited)}</time></span>}
57
79
  <h2>
80
+ {post.deck && (
81
+ <a class="post-deck" href={`${post.url}slides/`} title="Slides" aria-label={`Slides: ${post.title}`}>
82
+ <Fragment set:html={SLIDES_ICON} />
83
+ </a>
84
+ )}
58
85
  <a href={post.url}>{post.title}</a>
59
- {post.tags.map((id) => tag(id).icon
86
+ {post.tags.filter((id) => !tag(id).computed).map((id) => tag(id).icon
60
87
  ? <span class="post-icon" title={tag(id).name} role="img" aria-label={tag(id).name}>{tag(id).icon}</span>
61
88
  : <span class="post-tag">{tag(id).name}</span>)}
62
89
  </h2>
@@ -68,22 +95,47 @@ const wasEdited = (post) => post.edited && isoDate(post.edited) > isoDate(post.d
68
95
  </Base>
69
96
 
70
97
  <script>
71
- // A post shows when none of its tags is unchecked. "Last edited" shows each edit date and orders the posts by it;
72
- // unchecked, they are in publication order, newest first. The first render hides the tags that start hidden and every
73
- // edit date, in publication order, so the page is right before this runs; the browser may restore a checkbox on Back,
74
- // so this also runs once at load.
98
+ // The chip and the sort, from the URL and back into it (replaceState: no history entry per click). The first render
99
+ // is All and Newest, so the page is right before this runs.
75
100
  const filter = document.querySelector('.post-filter')
101
+ const sort = document.querySelector('.post-sort select')
76
102
  const list = document.querySelector('.post-list')
103
+ const hiddenTags = new Set(filter.dataset.hidden.split(' ').filter(Boolean))
104
+ const chip = () => filter.querySelector('input[name="tag"]:checked')?.value ?? ''
105
+
77
106
  const update = () => {
78
- const off = [...filter.querySelectorAll('input[name="tag"]:not(:checked)')].map((input) => input.value)
107
+ const id = chip()
79
108
  for (const li of list.children) {
80
- li.hidden = li.dataset.tags.split(' ').some((id) => off.includes(id))
109
+ const tags = li.dataset.tags.split(' ')
110
+ const isHidden = tags.some((t) => hiddenTags.has(t))
111
+ li.hidden = id ? !tags.includes(id) || (isHidden && !hiddenTags.has(id)) : isHidden
81
112
  }
82
- const edited = filter.querySelector('input[name="edited"]').checked
83
- for (const span of list.querySelectorAll('.post-edited')) span.hidden = !edited
84
- const key = (li) => (edited ? li.dataset.edited : '') + li.dataset.date
85
- list.append(...[...list.children].sort((a, b) => key(b).localeCompare(key(a)) || a.dataset.order - b.dataset.order))
113
+ const key = { newest: (li) => li.dataset.date, updated: (li) => li.dataset.edited + li.dataset.date, oldest: (li) => li.dataset.date }[sort.value]
114
+ const sign = sort.value === 'oldest' ? -1 : 1
115
+ list.append(...[...list.children].sort((a, b) => sign * key(b).localeCompare(key(a)) || a.dataset.order - b.dataset.order))
116
+ const params = new URLSearchParams(location.search)
117
+ id ? params.set('tag', id) : params.delete('tag')
118
+ sort.value !== 'newest' ? params.set('sort', sort.value) : params.delete('sort')
119
+ const query = params.toString()
120
+ history.replaceState(history.state, '', `${location.pathname}${query ? `?${query}` : ''}${location.hash}`)
86
121
  }
122
+
123
+ // A click on the chosen chip goes back to All.
124
+ let before = ''
125
+ filter.addEventListener('pointerdown', () => { before = chip() })
126
+ filter.addEventListener('keydown', () => { before = chip() })
127
+ filter.addEventListener('click', (event) => {
128
+ const input = event.target instanceof HTMLInputElement ? event.target : null
129
+ if (input?.value && input.value === before) filter.querySelector('input[value=""]').checked = true
130
+ before = chip()
131
+ update()
132
+ })
87
133
  filter.addEventListener('change', update)
134
+ sort.addEventListener('change', update)
135
+
136
+ const params = new URLSearchParams(location.search)
137
+ const chosen = filter.querySelector(`input[name="tag"][value="${CSS.escape(params.get('tag') ?? '')}"]`)
138
+ if (chosen) chosen.checked = true
139
+ if ([...sort.options].some((o) => o.value === params.get('sort'))) sort.value = params.get('sort')
88
140
  update()
89
141
  </script>
@@ -57,10 +57,10 @@ function keptText(island) {
57
57
  const box = (html) => raw(`<div class="fig-text">${html}</div>`)
58
58
 
59
59
  // `out` is the build's output directory; `site` the site's URL, for links back to it (see siteLinks).
60
- export async function agentPage(html, { references, out = dist, site, base }) {
60
+ export async function agentPage(html, { references, out = dist, site, base, pageUrl }) {
61
61
  const figures = await describers()
62
62
  const tree = fromHtml(html)
63
- siteLinks(tree, { site, base })
63
+ siteLinks(tree, { site, base, pageUrl })
64
64
  const meta = (name) => {
65
65
  let content = ''
66
66
  visit(tree, 'element', (node) => { if (node.tagName === 'meta' && node.properties.name === name) content = node.properties.content })
@@ -46,9 +46,10 @@ export const hasClass = (node, name) => (node.properties?.className || []).inclu
46
46
 
47
47
  // Links back to the site: each root-relative link (the blog index, the Slides link) becomes a link to
48
48
  // the deployed site, src/site.js `url`, so it works from a downloaded file when the reader is online.
49
- // `base` is the base path the page was built with (BASE_PATH, as in astro.config.mjs). The download
50
- // control is removed.
51
- export function siteLinks(tree, { site = siteUrl, base = process.env.BASE_PATH || '/' } = {}) {
49
+ // `base` is the base path the page was built with (BASE_PATH, as in astro.config.mjs). `pageUrl`, the page's own
50
+ // URL path under the base ('posts/<path>/'), makes a relative link (`../other-post/`, `./subpage/`) one to the
51
+ // deployed site too; without it, relative links stay as they are. The download control is removed.
52
+ export function siteLinks(tree, { site = siteUrl, base = process.env.BASE_PATH || '/', pageUrl = null } = {}) {
52
53
  visit(tree, 'element', (node, index, parent) => {
53
54
  if (node.properties?.dataDownload !== undefined) {
54
55
  parent.children.splice(index, 1)
@@ -56,7 +57,12 @@ export function siteLinks(tree, { site = siteUrl, base = process.env.BASE_PATH |
56
57
  }
57
58
  const href = node.tagName === 'a' ? node.properties.href : null
58
59
  // Built assets stay relative: each download inlines them (distAsset).
59
- if (typeof href !== 'string' || !href.startsWith(base) || href.startsWith('//') || distAsset(href)) return
60
+ if (typeof href !== 'string' || href.startsWith('//') || distAsset(href)) return
61
+ if (pageUrl && !href.startsWith('/') && !href.startsWith('#') && !/^[a-z][a-z0-9+.-]*:/i.test(href)) {
62
+ node.properties.href = new URL(href, new URL(pageUrl, site)).href
63
+ return
64
+ }
65
+ if (!href.startsWith(base)) return
60
66
  node.properties.href = new URL(href.slice(base.length), site).href
61
67
  })
62
68
  // The byline separators (" / ") left without anything after them.
@@ -26,19 +26,21 @@ export default function postDownloads() {
26
26
  const base = process.env.BASE_PATH || '/'
27
27
  const root = server.config.root
28
28
  const out = join(root, 'node_modules/.cache/post-downloads')
29
- const pattern = new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}posts/([^/]+)/([^/]+)\\.html$`)
29
+ // A page's downloads sit beside it, at any depth under posts/ (lib/pages.js), named after its last part.
30
+ const pattern = new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}posts/(.+)/([^/]+)\\.html$`)
30
31
  server.middlewares.use(async (req, res, next) => {
31
32
  const match = decodeURIComponent((req.url || '').split('?')[0]).match(pattern)
32
- const [, slug, name] = match ?? []
33
- if (!match || (name !== slug && name !== `${slug}-agent`)) return next()
33
+ const [, path, name] = match ?? []
34
+ const last = path?.split('/').at(-1)
35
+ if (!match || (name !== last && name !== `${last}-agent`)) return next()
34
36
  try {
35
37
  logger.info(`building the ${name}.html download`)
36
38
  await scratchBuild(root, out)
37
39
  const { exportPost } = await import('./index.js')
38
- const files = await exportPost({ out, slug, base })
40
+ const files = await exportPost({ out, path, base })
39
41
  res.setHeader('Content-Type', 'text/html; charset=utf-8')
40
42
  res.setHeader('Content-Disposition', `attachment; filename="${name}.html"`)
41
- res.end(name === slug ? files.page : files.agent)
43
+ res.end(name === last ? files.page : files.agent)
42
44
  } catch (error) {
43
45
  logger.error(String(error.stack || error))
44
46
  res.statusCode = 500
@@ -1,21 +1,25 @@
1
- // Both downloads of one built post. `out` is the build's output directory (dist/ after `npm run build`,
2
- // a scratch directory under the dev server); `slug` names the post folder in it.
1
+ // Both downloads of one built page. `out` is the build's output directory (dist/ after `npm run build`,
2
+ // a scratch directory under the dev server); `path` is the page's path under posts/ in it (lib/pages.js): a post's
3
+ // slug, or a subpage's '<slug>/<name>'. `slug`, the older name for it, still works.
3
4
  import { existsSync, readFileSync } from 'node:fs'
4
5
  import { join } from 'node:path'
5
6
  import { root } from './common.js'
6
7
  import { interactivePage } from './page.js'
7
8
  import { agentPage } from './agent.js'
8
9
 
9
- export async function exportPost({ out, slug, site, base }) {
10
- const html = readFileSync(join(out, 'posts', slug, 'index.html'), 'utf8')
10
+ export async function exportPost({ out, path, slug, site, base }) {
11
+ path ??= slug
12
+ const html = readFileSync(join(out, 'posts', path, 'index.html'), 'utf8')
11
13
  const references = JSON.parse(readFileSync(join(root, 'src/references.json'), 'utf8'))
12
- // The deck, when the post has one, travels inside the interactive page.
13
- const deckFile = join(out, 'posts', slug, 'slides', 'index.html')
14
- const deck = existsSync(deckFile) ? await interactivePage(readFileSync(deckFile, 'utf8'), { out, site, base, inFrame: true }) : null
14
+ // The page's own URL path, against which its relative links resolve (siteLinks).
15
+ const pageUrl = `posts/${path}/`
16
+ // The deck, when the page has one, travels inside the interactive page.
17
+ const deckFile = join(out, 'posts', path, 'slides', 'index.html')
18
+ const deck = existsSync(deckFile) ? await interactivePage(readFileSync(deckFile, 'utf8'), { out, site, base, pageUrl: `${pageUrl}slides/`, inFrame: true }) : null
15
19
  return {
16
- page: await interactivePage(html, { out, site, base, deck }),
17
- agent: await agentPage(html, { references, out, site, base }),
20
+ page: await interactivePage(html, { out, site, base, pageUrl, deck }),
21
+ agent: await agentPage(html, { references, out, site, base, pageUrl }),
18
22
  }
19
23
  }
20
24
 
21
- export const downloadNames = (slug) => ({ page: `${slug}.html`, agent: `${slug}-agent.html` })
25
+ export { downloadNames } from '../../lib/pages.js'
@@ -112,12 +112,13 @@ const DECK_IN_FRAME = `(() => {
112
112
  }, true)
113
113
  })()`
114
114
 
115
- // `out` is the build's output directory; `site` the site's URL, for links back to it (see siteLinks).
115
+ // `out` is the build's output directory; `site` the site's URL, for links back to it, and `pageUrl` the page's URL path
116
+ // under the base, against which its relative links resolve (see siteLinks).
116
117
  // `deck` is the post's deck, already exported with `inFrame: true`, to carry inside this page.
117
- export async function interactivePage(html, { out = defaultDist, site, base, deck, inFrame = false } = {}) {
118
+ export async function interactivePage(html, { out = defaultDist, site, base, pageUrl, deck, inFrame = false } = {}) {
118
119
  const asset = (url) => distAsset(url, out)
119
120
  const tree = fromHtml(html)
120
- siteLinks(tree, { site, base })
121
+ siteLinks(tree, { site, base, pageUrl })
121
122
  const modules = new Map() // file in dist -> key in the bundle's module table
122
123
  const sideEffects = [] // module scripts the page runs for their effects
123
124
  const element = (tagName, properties, value) => ({ type: 'element', tagName, properties, children: [{ type: 'text', value }] })
@@ -1,21 +1,36 @@
1
1
  // Run after `astro build` (part of `npm run build`): writes the two downloads that the byline's download
2
- // control links to, beside each built post in dist/posts/<slug>/:
3
- // <slug>.html the interactive page, one file that opens from disk with working figures
4
- // <slug>-agent.html a text export for language models (bloggie/scripts/export/agent.js)
2
+ // control links to, beside each built page under dist/posts/ that offers them (lib/pages.js: every post, and a
3
+ // subpage whose front matter sets `downloads: true`):
4
+ // <name>.html the interactive page, one file that opens from disk with working figures
5
+ // <name>-agent.html a text export for language models (bloggie/scripts/export/agent.js)
6
+ // <name> is the last part of the page's path: the post's slug, or the subpage's name.
7
+ // Each export inlines the page's scripts, styles, fonts and data into one file and bundles its figures, which takes
8
+ // time and space for every page; so a page without the control gets none.
5
9
  // Under `npm run dev`, bloggie/scripts/export/dev.js builds them on request instead.
6
- import { existsSync, readdirSync, writeFileSync } from 'node:fs'
10
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
7
11
  import { join } from 'node:path'
8
12
  import { dist } from './export/common.js'
9
13
  import { downloadNames, exportPost } from './export/index.js'
10
14
 
11
15
  const kb = (text) => `${Math.round(Buffer.byteLength(text) / 1024)} KB`
16
+ // The byline's download control (layouts/Post.astro); a deck's page and a page that turns downloads off have none.
17
+ const OFFERS = /<[^>]*\sdata-download[\s>=]/
18
+
19
+ // The built pages under dist/posts/, by their paths there ('<slug>', '<slug>/<name>', ...).
20
+ function pages(dir, path = '') {
21
+ const found = path && existsSync(join(dir, 'index.html')) ? [path] : []
22
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
23
+ if (entry.isDirectory()) found.push(...pages(join(dir, entry.name), path ? `${path}/${entry.name}` : entry.name))
24
+ }
25
+ return found
26
+ }
12
27
 
13
28
  // A blog with no visible post (e.g. a new blog with the example hidden) has no dist/posts.
14
- const built = existsSync(join(dist, 'posts')) ? readdirSync(join(dist, 'posts')) : []
15
- for (const slug of built) {
16
- if (!existsSync(join(dist, 'posts', slug, 'index.html'))) continue
17
- const files = await exportPost({ out: dist, slug })
18
- const names = downloadNames(slug)
19
- for (const kind of ['page', 'agent']) writeFileSync(join(dist, 'posts', slug, names[kind]), files[kind])
20
- console.log(`export-posts: ${names.page} (${kb(files.page)}), ${names.agent} (${kb(files.agent)})`)
29
+ const built = existsSync(join(dist, 'posts')) ? pages(join(dist, 'posts')) : []
30
+ for (const path of built) {
31
+ if (!OFFERS.test(readFileSync(join(dist, 'posts', path, 'index.html'), 'utf8'))) continue
32
+ const files = await exportPost({ out: dist, path })
33
+ const names = downloadNames(path)
34
+ for (const kind of ['page', 'agent']) writeFileSync(join(dist, 'posts', path, names[kind]), files[kind])
35
+ console.log(`export-posts: ${path}/${names.page} (${kb(files.page)}), ${names.agent} (${kb(files.agent)})`)
21
36
  }
@@ -75,7 +75,8 @@ a time, with the post's own interactive figures.
75
75
  - do not repeat a symbol explained on the previous slide or very recently; if it returns
76
76
  much later, give a one-line reminder.
77
77
  7. **Minimize builds.** Every animation is overhead for the presenter. Default to none. Use a
78
- build only when the slide asks a question and the build reveals the answer.
78
+ build only when the slide asks a question and the build reveals the answer, or when the author asks for one.
79
+ `## [text build=true] Title` reveals the slide's list items one per click.
79
80
  8. **Prefer a short list to cards.** Use cards only when items need a visual group that a list
80
81
  cannot give. When an item has a main idea and a description, make the size difference
81
82
  large: main idea 56px bold, description 40px in the secondary color.
@@ -123,7 +124,8 @@ its figure components the same way: the deck must run the post's real interactiv
123
124
 
124
125
  - A deck is `slides.mdx` beside the post's `index.mdx` (`src/pages/posts/<slug>/slides.mdx`), with
125
126
  `layout: '@bloggie/layouts/Slides.astro'` in its front matter; Astro serves it at
126
- `/posts/<slug>/slides/`. The pairing is automatic: when `slides.mdx` exists, the post's byline
127
+ `/posts/<slug>/slides/`. A subpage has a deck only as a folder with its own `index.mdx`
128
+ (`posts/<slug>/<name>/slides.mdx`); a file subpage (`<name>.mdx`) shares its post's. The pairing is automatic: when `slides.mdx` exists, the post's byline
127
129
  links to the deck and S on the post opens it; Esc (or ✕) on the deck returns to the post, with
128
130
  its scroll position when the reader came from it. A post without a deck has neither, and
129
131
  `slides: false` in a post's front matter hides a deck that exists. `bloggie/lib/slides.js` is the
@@ -169,7 +171,16 @@ its figure components the same way: the deck must run the post's real interactiv
169
171
  `<p slot="note">…</p>`, placed with `noteTop=310px` (from the top of the figure area); one
170
172
  sentence. It scrolls with the figure, so it never covers text the figure scrolls up.
171
173
  - `video`: only the `<video>`, full bleed on `bg` (sample the color from the poster image);
172
- the heading is not shown, and names the slide in the speaker view.
174
+ the heading is not shown, and names the slide in the speaker view. A video on YouTube is
175
+ `<YouTube id="…" title="…" />` (import it from `@bloggie/components/YouTube.astro`) on `bg=#000`:
176
+ YouTube's own player fills the stage, and the deck pauses it when the slide is left.
177
+ - `embed`: only a live web page, `<Embed src="…" title="…" />` (import it from
178
+ `@bloggie/components/Embed.astro`), the full width of the stage, for an interactive article the
179
+ presenter explores in the talk. The page loads when its slide or the one before it is shown. A
180
+ 24px band at the bottom stays the deck's: a click there gives the keys back to the deck, and the
181
+ pointer there shows the nav in full screen. Check first that the site allows framing. To show
182
+ only an article's demo, give `crop="x y width height"`: the rectangle of the page, laid out
183
+ 1440 px wide (`layout` changes it), that the slide shows; measure it in a headless browser.
173
184
  - A `title` prop on a hand-written `<Slide>` is HTML, not Markdown; a heading title can hold math.
174
185
  - Code blocks are highlighted by Shiki at build time; the fence's language picks the grammar
175
186
  (rule 16), and the syntax a slide teaches must be the part that is colored. Fence MDX source as