@lincyaw/workspace 1.0.0-rc.13 → 1.0.0-rc.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/workspace",
3
- "version": "1.0.0-rc.13",
3
+ "version": "1.0.0-rc.14",
4
4
  "description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -33,12 +33,12 @@
33
33
  "image-size": "2.0.4",
34
34
  "mime-types": "3.0.2",
35
35
  "yaml": "^2.9.1",
36
- "@lincyaw/kernel": "1.0.0-rc.13",
37
- "@lincyaw/compiler": "1.0.0-rc.13",
38
- "@lincyaw/server": "1.0.0-rc.13"
36
+ "@lincyaw/compiler": "1.0.0-rc.14",
37
+ "@lincyaw/server": "1.0.0-rc.14",
38
+ "@lincyaw/kernel": "1.0.0-rc.14"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/mime-types": "^3.0.1",
42
- "@lincyaw/mcp": "1.0.0-rc.13"
42
+ "@lincyaw/mcp": "1.0.0-rc.14"
43
43
  }
44
44
  }
package/src/node/build.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { cpSync, existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
1
+ import { cpSync, existsSync, readdirSync, rmSync } from 'node:fs'
2
2
  import { isAbsolute, join, resolve } from 'node:path'
3
3
  import { build, Compiler } from '@lincyaw/compiler'
4
4
  import type { Compilation, RunStats } from '@lincyaw/compiler'
5
- import { errorMessage, isRecord } from '@lincyaw/kernel'
5
+ import { APP_DIR, errorMessage, isRecord, SLIDES_DIR } from '@lincyaw/kernel'
6
6
  import type { Finding, IRDocument, SiteSpec } from '@lincyaw/kernel'
7
7
  import { listDocuments, readWorkspaceConfig } from './config.ts'
8
8
  import { siteContext, siteDocument, siteIR, siteSpec, siteTranslations, webRenderer } from './site.ts'
@@ -25,7 +25,7 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
25
25
  for (const document of found) {
26
26
  const compilation = await new Compiler(join(config.root, document.entry), { bundled: options.bundled, settings: config.settings }).compile({ pruneCache: true })
27
27
  compilations.push(compilation)
28
- const to = presentations(compilation, `${base}${urlPath(document.dir)}/`, siteLook(config.site, config.root))
28
+ const to = presentations(compilation, base, `${base}${urlPath(document.dir)}/`, siteLook(config.site, config.root))
29
29
  if (to.length > 0) forms.push({ dir: document.dir, compilation, to })
30
30
  const translated = await siteTranslations(compilation)
31
31
  findings.push(...compilation.doc.diagnostics, ...translated.findings)
@@ -50,7 +50,7 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
50
50
  const report = await build(compilation, { outDir: work, to })
51
51
  findings.push(...report.findings)
52
52
  for (const form of to) if (existsSync(join(work, form))) cpSync(join(work, form), join(outDir, dir, form), { recursive: true })
53
- if (to.includes('slides')) shareSlidesApp(join(outDir, dir, 'slides'), `${base}${urlPath(dir)}/slides/`, outDir, base)
53
+ if (to.includes('slides')) moveApps(join(outDir, dir, SLIDES_DIR), outDir)
54
54
  } catch (error) {
55
55
  findings.push({ checkId: 'presmium.render', severity: 'error', message: `document ${dir}: its ${to.join(' and ')} failed: ${errorMessage(error)}` })
56
56
  }
@@ -90,31 +90,26 @@ function siteLook(site: Record<string, unknown>, root: string): Record<string, u
90
90
 
91
91
  const urlPath = (dir: string) => dir.split('/').map(encodeURIComponent).join('/')
92
92
 
93
- /**
94
- * Every document's slides run the same viewer app: it moves to the site's `_app/<key>/`, beside the web pages' own,
95
- * so a reader downloads it once for all the presentations of the site, and the slides' page points there.
96
- */
97
- function shareSlidesApp(slides: string, slidesBase: string, outDir: string, base: string): void {
98
- const app = join(slides, '_app')
99
- if (!existsSync(app)) return
100
- for (const key of readdirSync(app)) if (!existsSync(join(outDir, '_app', key))) cpSync(join(app, key), join(outDir, '_app', key), { recursive: true })
101
- rmSync(app, { recursive: true, force: true })
102
- const page = join(slides, 'index.html')
103
- writeFileSync(page, readFileSync(page, 'utf8').replaceAll(`${slidesBase}_app/`, `${base}_app/`))
93
+ /** The presentation's viewer app goes where its page names it (`appBase`): with the site's own, downloaded once for all. */
94
+ function moveApps(presentation: string, outDir: string): void {
95
+ const apps = join(presentation, APP_DIR)
96
+ if (!existsSync(apps)) return
97
+ for (const key of readdirSync(apps)) if (!existsSync(join(outDir, APP_DIR, key))) cpSync(join(apps, key), join(outDir, APP_DIR, key), { recursive: true })
98
+ rmSync(apps, { recursive: true, force: true })
104
99
  }
105
100
 
106
101
  /**
107
102
  * The presentation forms a document asks for (`metadata.renderers.slides` or `lecture`), set to be served below its
108
- * pages at `prefix`: the slides at `slides/`, and the web pages and the slides linked to each other.
103
+ * pages at `prefix`, with its viewer app below the site's `base`: the slides at `slides/`, and the web pages and the slides linked to each other.
109
104
  */
110
- function presentations(compilation: Compilation, prefix: string, look: Record<string, unknown>): string[] {
105
+ function presentations(compilation: Compilation, base: string, prefix: string, look: Record<string, unknown>): string[] {
111
106
  const { renderers } = compilation.doc.config
112
107
  const to = PRESENTATIONS.filter(form => renderers[form] !== undefined)
113
108
  if (to.length === 0) return to
114
- if (to.includes('slides')) renderers.slides = { ...look, ...isRecord(renderers.slides) ? renderers.slides : {}, base: `${prefix}slides/` }
109
+ if (to.includes('slides')) renderers.slides = { ...look, ...isRecord(renderers.slides) ? renderers.slides : {}, base: `${prefix}${SLIDES_DIR}/`, appBase: base }
115
110
  const settings = compilation.doc.config.presmium ??= {}
116
111
  const web = isRecord(settings['presmium.web']) ? settings['presmium.web'] : {}
117
- settings['presmium.web'] = { ...web, webUrl: prefix, ...to.includes('slides') ? { slidesUrl: `${prefix}slides/` } : {} }
112
+ settings['presmium.web'] = { ...web, webUrl: prefix, ...to.includes('slides') ? { slidesUrl: `${prefix}${SLIDES_DIR}/` } : {} }
118
113
  // The slides find the lecture where it is built, without probing `slides/lecture/` first.
119
114
  if (to.includes('lecture')) {
120
115
  const lecture = isRecord(settings['presmium.lecture']) ? settings['presmium.lecture'] : {}
@@ -125,6 +125,7 @@ export function readDocumentSummary(config: WorkspaceConfig, { dir, entry }: Doc
125
125
  ...typeof headmatter.description === 'string' && headmatter.description.trim() ? { description: headmatter.description.trim() } : {},
126
126
  ...typeof headmatter.lang === 'string' && headmatter.lang.trim() ? { lang: headmatter.lang.trim() } : {},
127
127
  ...tags.length > 0 ? { tags } : {},
128
+ ...isRecord(headmatter.renderers) && headmatter.renderers.slides !== undefined ? { slides: true } : {},
128
129
  }
129
130
  }
130
131
 
package/src/node/site.ts CHANGED
@@ -35,7 +35,7 @@ export async function siteTranslations(compilation: Compilation): Promise<{ tran
35
35
  }
36
36
 
37
37
  export function siteDocument(document: DocumentSummary, doc?: IRDocument, translations?: SiteDocument['translations'], compilation?: Compilation): SiteDocument {
38
- return { dir: document.dir, title: document.title, description: document.description, ...document.lang ? { lang: document.lang } : {}, ...document.tags ? { tags: document.tags } : {}, ...doc ? { doc } : {}, ...translations?.length ? { translations } : {}, ...compilation ? { nodeVitePlugins: nodeVitePlugins(compilation) } : {} }
38
+ return { dir: document.dir, title: document.title, description: document.description, ...document.lang ? { lang: document.lang } : {}, ...document.tags ? { tags: document.tags } : {}, ...document.slides ? { slides: true } : {}, ...doc ? { doc } : {}, ...translations?.length ? { translations } : {}, ...compilation ? { nodeVitePlugins: nodeVitePlugins(compilation) } : {} }
39
39
  }
40
40
 
41
41
  export function refreshDocumentVitePlugins(site: SiteSpec, dir: string, compilation: Compilation): void {