astro-lilypond 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -9,42 +9,12 @@ An [Astro](https://astro.build) integration for rendering [LilyPond](https://lil
9
9
  - Use the content loader to pass in a folder full of `.ly` files and get back an Astro content collection.
10
10
  - Works with all LilyPond syntax.
11
11
 
12
- Read the docs: https://lilypond.ky.fyi
13
-
14
- ## Quick Start
15
-
16
- ### 1. Install `astro-lilypond`
12
+ ## Quick start
17
13
 
18
14
  ```sh
19
- pnpm add astro-lilypond
20
- ```
21
-
22
- ### 2. Add the integration to your Astro config
23
-
24
- ```js
25
- // astro.config.mjs
26
- import { defineConfig } from 'astro/config';
27
- import lilypond from 'astro-lilypond';
28
-
29
- export default defineConfig({
30
- integrations: [lilypond()]
31
- });
15
+ npx astro add astro-lilypond
32
16
  ```
33
17
 
34
- ### 3. Write your music
35
-
36
- Write LilyPond code within fenced code blocks with the `lilypond`, `ly`, or `ily` language tag.
37
-
38
- ````md
39
- ```lilypond
40
- \\score ...
41
- ```
42
- ````
43
-
44
- Your score will be built to `.svg` or `.png` and display alongside the rest of your content.
45
-
46
- ---
47
-
48
18
  For more info, refer to the docs: https://lilypond.ky.fyi
49
19
 
50
20
  Happy notating!
package/dist/index.d.ts CHANGED
@@ -94,5 +94,11 @@ export interface LilypondOptions extends PluginOptions {
94
94
  * @default true
95
95
  */
96
96
  autoInstall?: boolean | AutoInstallOptions;
97
+ /**
98
+ * Extra directories to search for `\include`d files, in addition to each
99
+ * score's own directory. Relative paths resolve against the project root.
100
+ * @default []
101
+ */
102
+ includePaths?: string[];
97
103
  }
98
104
  export default function lilypond(options?: LilypondOptions): AstroIntegration;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { fileURLToPath } from "node:url";
1
2
  import { createComponent, renderComponent, renderTemplate, unescapeHTML, } from "astro/runtime/server/index.js";
2
3
  import emitAssetIntegration from "astro-emit-asset";
3
4
  import { resolveAutoInstallOption, resolveLilypondBinary, } from "./binary/index.js";
@@ -114,7 +115,7 @@ function lyFilePlugin(options) {
114
115
  return;
115
116
  const { version } = resolveDefaults(options.defaults);
116
117
  const src = version ? prependVersion(source, version) : source;
117
- const includePaths = includePathsFor(id);
118
+ const includePaths = includePathsFor(id, options.includePaths);
118
119
  const sourceName = sourceNameFor(id);
119
120
  const assetTitle = titleFor(sourceName);
120
121
  const meta = toLilypondMetadata(parseLyHeaderFields(source));
@@ -147,12 +148,15 @@ export default function lilypond(options = {}) {
147
148
  warn: (message) => logger.warn(message),
148
149
  });
149
150
  options.binaryPath = binaryPath;
151
+ const includePaths = (options.includePaths ?? []).map((path) => fileURLToPath(new URL(path, config.root)));
152
+ options.includePaths = includePaths;
150
153
  setLilypondState({
151
154
  binaryPath,
152
155
  defaults: options.defaults,
153
156
  timeout: options.timeout,
154
157
  isDev,
155
158
  logger,
159
+ includePaths,
156
160
  });
157
161
  updateConfig({
158
162
  integrations: [emitAssetIntegration()],
package/dist/loader.js CHANGED
@@ -80,7 +80,7 @@ export function lilypondLoader({ pattern = DEFAULT_PATTERN, base, generateId = d
80
80
  const id = generateId({ entry, base: baseUrl, header: headerFields });
81
81
  const digest = generateDigest(source);
82
82
  const src = prependVersion(source, version);
83
- const includePaths = includePathsFor(filePath);
83
+ const includePaths = includePathsFor(filePath, getLilypondState().includePaths);
84
84
  const sourceName = sourceNameFor(filePath);
85
85
  const assetTitle = titleFor(sourceName);
86
86
  const meta = toLilypondMetadata(headerFields);
@@ -9,7 +9,7 @@ export const remarkPlugin = (options) => {
9
9
  const renderOptions = { ...options, logger };
10
10
  return async (tree, file) => {
11
11
  const promises = [];
12
- const includePaths = includePathsFor(file?.path);
12
+ const includePaths = includePathsFor(file?.path, options.includePaths);
13
13
  const sourceName = sourceNameFor(file?.path);
14
14
  const title = titleFor(sourceName);
15
15
  visit(tree, "code", (node, index, parent) => {
@@ -16,7 +16,7 @@ export function satteriPlugin(options) {
16
16
  title: titleFor(sourceName),
17
17
  value: node.value,
18
18
  meta: node.meta,
19
- includePaths: includePathsFor(ctx.fileURL),
19
+ includePaths: includePathsFor(ctx.fileURL, options.includePaths),
20
20
  sourceName,
21
21
  });
22
22
  return { rawHtml };
@@ -6,4 +6,5 @@ export interface PluginOptions {
6
6
  binaryPath?: string;
7
7
  isDev?: boolean;
8
8
  logger?: Pick<AstroIntegrationLogger, "warn" | "error">;
9
+ includePaths?: string[];
9
10
  }
package/dist/state.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface LilypondState {
6
6
  timeout: number | undefined;
7
7
  isDev: boolean;
8
8
  logger: Pick<AstroIntegrationLogger, "warn" | "error">;
9
+ includePaths: string[];
9
10
  }
10
11
  export declare function setLilypondState(state: LilypondState): void;
11
12
  export declare function getLilypondState(): LilypondState;
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Derives `render()`'s `includePaths` from the source file's path or URL, so
3
- * `\include`d sibling files resolve even though rendering happens in a temp
4
- * directory. Returns `[]` when the source location is unknown.
2
+ * Make sure that any `\include` definitions resolve correctly when
3
+ * LilyPond compiles the score. `source` is the current directory or URL
4
+ * of the .ly file; `extra` is for user-defined locations from the
5
+ * config setting `includePaths`.
5
6
  */
6
- export declare function includePathsFor(source: string | URL | null | undefined): string[];
7
+ export declare function includePathsFor(source: string | URL | null | undefined, extra?: string[]): string[];
@@ -1,13 +1,14 @@
1
1
  import { dirname } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
  /**
4
- * Derives `render()`'s `includePaths` from the source file's path or URL, so
5
- * `\include`d sibling files resolve even though rendering happens in a temp
6
- * directory. Returns `[]` when the source location is unknown.
4
+ * Make sure that any `\include` definitions resolve correctly when
5
+ * LilyPond compiles the score. `source` is the current directory or URL
6
+ * of the .ly file; `extra` is for user-defined locations from the
7
+ * config setting `includePaths`.
7
8
  */
8
- export function includePathsFor(source) {
9
+ export function includePathsFor(source, extra = []) {
9
10
  if (!source)
10
- return [];
11
+ return extra;
11
12
  const path = typeof source === "string" ? source : fileURLToPath(source);
12
- return [dirname(path)];
13
+ return [dirname(path), ...extra];
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-lilypond",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "An Astro integration for rendering Lilypond markup to music notation.",
5
5
  "homepage": "https://lilypond.ky.fyi",
6
6
  "author": "Ky Decker",