kawapress 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,8 @@ import type { Plugin, ViteDevServer } from 'vite'
2
2
  import type { MarkdownPageLoader } from '../../../compiler/page-loader'
3
3
  import type { DeadLink, ResolvedDeadLinkConfig } from '../../../core/dead-links'
4
4
  import type { PageRouteIndex } from './pages'
5
- import { markdownFileToSourcePath } from '../../../compiler/page-loader'
5
+ import { markdownFileToRoutePath } from '../../../compiler/page-path'
6
6
  import { findPageDeadLinks, formatDeadLink } from '../../../core/dead-links'
7
- import { markdownPagePathToRoutePath } from '../../../core/markdown-route'
8
7
 
9
8
  export interface DevDeadLinksOptions {
10
9
  pageLoader: MarkdownPageLoader
@@ -35,8 +34,10 @@ export function devDeadLinksPlugin(options: DevDeadLinksOptions): Plugin {
35
34
  return
36
35
  }
37
36
 
38
- const route = markdownPagePathToRoutePath(
39
- markdownFileToSourcePath(file, options.pageLoader.sourceRoot),
37
+ const route = markdownFileToRoutePath(
38
+ file,
39
+ options.pageLoader.sourceRoot,
40
+ options.pageLoader.rewrites,
40
41
  )
41
42
  const page = options.pageLoader.registry.get(route)
42
43
  if (!page) {
@@ -13,7 +13,11 @@ export function markdownPlugin(pageLoader: MarkdownPageLoader): Plugin {
13
13
  }
14
14
 
15
15
  const source = await readFile(file, 'utf8')
16
- const { html, env, pageData } = await pageLoader.load(source, file)
16
+ const { html, env, pageData, dependencies } = await pageLoader.load(source, file)
17
+ // An edit to an included file or a code snippet then updates the page.
18
+ for (const dependency of dependencies) {
19
+ this.addWatchFile(dependency)
20
+ }
17
21
  return assembleVueSfc(html, env, pageData)
18
22
  },
19
23
  }
@@ -63,6 +63,8 @@ export function pageScope(
63
63
  return {
64
64
  sourceRoot: pageLoader.sourceRoot,
65
65
  publicDir: resolve(pageLoader.sourceRoot, publicDir),
66
+ exclude: pageLoader.srcExclude,
67
+ rewrites: pageLoader.rewrites,
66
68
  }
67
69
  }
68
70
 
package/src/generator.ts CHANGED
@@ -2,12 +2,15 @@
2
2
  * Node.js helpers for Generator Plugins. They run only on the generator side;
3
3
  * never import this entry from a Runtime Plugin.
4
4
  */
5
+ export { expandMarkdownSource, readMarkdownSource } from './compiler/markdown-source'
6
+ export type { ExpandedMarkdownSource, MarkdownSourceLocation } from './compiler/markdown-source'
7
+ export { markdownFileToPagePath, markdownFileToRoutePath } from './compiler/page-path'
5
8
  export { createPageSummaryReader } from './compiler/page-summary'
6
9
  export type { PageSummaryReader } from './compiler/page-summary'
7
10
  export { resolveHeadingTitle } from './core/heading-title'
8
11
  export type { PageSummary } from './core/page-manifest'
9
12
  export { parseGitLog, readGitLastUpdated } from './generator/git'
10
13
  export type { ReadGitLastUpdatedOptions } from './generator/git'
11
- export { isMarkdownPage, listMarkdownPages, markdownFileToRoutePath } from './generator/pages'
14
+ export { isMarkdownPage, listMarkdownPages } from './generator/pages'
12
15
  export type { MarkdownPage, MarkdownPageScope } from './generator/pages'
13
16
  export { useRuntimeDependencies } from './generator/runtime-dependencies'
package/src/index.ts CHANGED
@@ -66,6 +66,7 @@ export type {
66
66
  LocaleDirection,
67
67
  LocaleLink,
68
68
  PageHeader,
69
+ PageRewrites,
69
70
  ResolvedSiteData,
70
71
  SiteConfig,
71
72
  SiteData,
@@ -6,31 +6,46 @@ import type {
6
6
  } from '../core/outlet'
7
7
  import { assertOutletName, OUTLET_NAMES } from '../core/outlet'
8
8
 
9
+ type OutletSide = 'prepend' | 'append'
10
+ type OutletAdder = (outlet: OutletName, item: OutletItemInput) => void
11
+
9
12
  export interface OutletCollector {
10
13
  /**
11
- * Registers an item for one plugin. The plugin name is bound once by the
12
- * caller so a plugin cannot claim items that belong to another plugin.
14
+ * The two registration functions of one plugin. The plugin name is bound once
15
+ * by the caller so a plugin cannot claim items that belong to another plugin.
13
16
  */
14
- addForPlugin: (pluginName: string) => (outlet: OutletName, item: OutletItemInput) => void
17
+ forPlugin: (pluginName: string) => {
18
+ prependToOutlet: OutletAdder
19
+ appendToOutlet: OutletAdder
20
+ }
15
21
  /** Freezes the collected items into the registry handed to the Vue app. */
16
22
  createRegistry: () => OutletRegistry
17
23
  }
18
24
 
19
25
  export function createOutletCollector(): OutletCollector {
20
- const itemsByOutlet = new Map<OutletName, OutletItem[]>()
26
+ const sides: Record<OutletSide, Map<OutletName, OutletItem[]>> = {
27
+ prepend: new Map(),
28
+ append: new Map(),
29
+ }
21
30
  const outletsById = new Map<string, OutletName>()
22
31
 
23
- function add(pluginName: string, outlet: OutletName, item: OutletItemInput): void {
32
+ function add(
33
+ side: OutletSide,
34
+ pluginName: string,
35
+ outlet: OutletName,
36
+ item: OutletItemInput,
37
+ ): void {
38
+ const method = `${side}ToOutlet`
24
39
  assertOutletName(
25
40
  outlet,
26
- `plugin ${JSON.stringify(pluginName)} calling api.addToOutlet()`,
41
+ `plugin ${JSON.stringify(pluginName)} calling api.${method}()`,
27
42
  )
28
43
 
29
44
  const localId = item?.id
30
45
  if (typeof localId !== 'string' || localId.trim() === '') {
31
46
  throw new Error(
32
- `[${pluginName} / runtime / addToOutlet] Item id for outlet ${JSON.stringify(outlet)} `
33
- + `must be a non-empty string. Pass { id: 'my-item', component } to api.addToOutlet().`,
47
+ `[${pluginName} / runtime / ${method}] Item id for outlet ${JSON.stringify(outlet)} `
48
+ + `must be a non-empty string. Pass { id: 'my-item', component } to api.${method}().`,
34
49
  )
35
50
  }
36
51
 
@@ -38,30 +53,30 @@ export function createOutletCollector(): OutletCollector {
38
53
  const existingOutlet = outletsById.get(id)
39
54
  if (existingOutlet) {
40
55
  throw new Error(
41
- `[${pluginName} / runtime / addToOutlet] Duplicate item id ${JSON.stringify(id)} `
56
+ `[${pluginName} / runtime / ${method}] Duplicate item id ${JSON.stringify(id)} `
42
57
  + `(already used for outlet ${JSON.stringify(existingOutlet)}). `
43
- + `Item ids must be unique per plugin; rename one of the api.addToOutlet() calls.`,
58
+ + `Item ids must be unique per plugin; rename one of the outlet calls.`,
44
59
  )
45
60
  }
46
61
 
47
62
  outletsById.set(id, outlet)
48
- const items = itemsByOutlet.get(outlet) ?? []
49
- items.push({
50
- id,
51
- owner: pluginName,
52
- component: item.component,
53
- })
54
- itemsByOutlet.set(outlet, items)
63
+ const items = sides[side].get(outlet) ?? []
64
+ items.push({ id, owner: pluginName, component: item.component })
65
+ sides[side].set(outlet, items)
55
66
  }
56
67
 
57
68
  return {
58
- addForPlugin: pluginName => (outlet, item) => {
59
- add(pluginName, outlet, item)
60
- },
69
+ forPlugin: pluginName => ({
70
+ prependToOutlet: (outlet, item) => add('prepend', pluginName, outlet, item),
71
+ appendToOutlet: (outlet, item) => add('append', pluginName, outlet, item),
72
+ }),
61
73
  createRegistry() {
62
- const registry = {} as Record<OutletName, readonly OutletItem[]>
74
+ const registry = {} as Record<OutletName, OutletRegistry[OutletName]>
63
75
  for (const name of OUTLET_NAMES) {
64
- registry[name] = Object.freeze([...(itemsByOutlet.get(name) ?? [])])
76
+ registry[name] = Object.freeze({
77
+ prepend: Object.freeze([...(sides.prepend.get(name) ?? [])]),
78
+ append: Object.freeze([...(sides.append.get(name) ?? [])]),
79
+ })
65
80
  }
66
81
  return Object.freeze(registry)
67
82
  },
@@ -26,7 +26,7 @@ export async function createRuntimePluginRunner(
26
26
 
27
27
  for (const plugin of plugins) {
28
28
  const api: RuntimePluginAPI = {
29
- addToOutlet: outletCollector.addForPlugin(plugin.name),
29
+ ...outletCollector.forPlugin(plugin.name),
30
30
  vueApp: handler => vueAppHandlers.add(plugin.name, handler),
31
31
  router: handler => routerHandlers.add(plugin.name, handler),
32
32
  }