astro-d2 0.1.0 → 0.1.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.
- package/index.ts +2 -2
- package/libs/d2.ts +1 -1
- package/libs/remark.ts +7 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ export default function astroD2Integration(userConfig?: AstroD2UserConfig): Astr
|
|
|
24
24
|
return {
|
|
25
25
|
name: 'astro-d2-integration',
|
|
26
26
|
hooks: {
|
|
27
|
-
'astro:config:setup': async ({ command, logger, updateConfig }) => {
|
|
27
|
+
'astro:config:setup': async ({ command, config: astroConfig, logger, updateConfig }) => {
|
|
28
28
|
if (command !== 'build' && command !== 'dev') {
|
|
29
29
|
return
|
|
30
30
|
}
|
|
@@ -45,7 +45,7 @@ export default function astroD2Integration(userConfig?: AstroD2UserConfig): Astr
|
|
|
45
45
|
|
|
46
46
|
updateConfig({
|
|
47
47
|
markdown: {
|
|
48
|
-
remarkPlugins: [[remarkAstroD2, config]],
|
|
48
|
+
remarkPlugins: [[remarkAstroD2, { ...config, base: astroConfig.base }]],
|
|
49
49
|
},
|
|
50
50
|
})
|
|
51
51
|
},
|
package/libs/d2.ts
CHANGED
|
@@ -85,7 +85,7 @@ async function getD2Version() {
|
|
|
85
85
|
try {
|
|
86
86
|
const [version] = await exec('d2', ['--version'])
|
|
87
87
|
|
|
88
|
-
if (!version ||
|
|
88
|
+
if (!version || !/^v?\d+\.\d+\.\d+/.test(version)) {
|
|
89
89
|
throw new Error(`Invalid D2 version, got '${version}'.`)
|
|
90
90
|
}
|
|
91
91
|
|
package/libs/remark.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { type DiagramAttributes, getAttributes } from './attributes'
|
|
|
10
10
|
import { generateD2Diagram, type D2Size, getD2DiagramSize } from './d2'
|
|
11
11
|
import { throwErrorWithHint } from './integration'
|
|
12
12
|
|
|
13
|
-
export function remarkAstroD2(config:
|
|
13
|
+
export function remarkAstroD2(config: RemarkAstroD2Config) {
|
|
14
14
|
return async function transformer(tree: Root, file: VFile) {
|
|
15
15
|
const d2Nodes: [node: Code, context: VisitorContext][] = []
|
|
16
16
|
|
|
@@ -70,7 +70,7 @@ function makHtmlImgNode(attributes: DiagramAttributes, imgPath: string, size: D2
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function getOutputPaths(config:
|
|
73
|
+
function getOutputPaths(config: RemarkAstroD2Config, file: VFile, nodeIndex: number) {
|
|
74
74
|
const relativePath = path.relative(file.cwd, file.path).replace(/^src\/(content|pages)\//, '')
|
|
75
75
|
const parsedRelativePath = path.parse(relativePath)
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ function getOutputPaths(config: AstroD2Config, file: VFile, nodeIndex: number) {
|
|
|
78
78
|
|
|
79
79
|
return {
|
|
80
80
|
fsPath: path.join(file.cwd, 'public', config.output, relativeOutputPath),
|
|
81
|
-
imgPath: path.posix.join(
|
|
81
|
+
imgPath: path.posix.join(config.base, config.output, relativeOutputPath),
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -100,3 +100,7 @@ interface VisitorContext {
|
|
|
100
100
|
index: number | undefined
|
|
101
101
|
parent: Parent | undefined
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
interface RemarkAstroD2Config extends AstroD2Config {
|
|
105
|
+
base: string
|
|
106
|
+
}
|
package/package.json
CHANGED