@litodocs/cli 1.4.0 → 1.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/config.js +32 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litodocs/cli",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Beautiful documentation sites from Markdown. Fast, simple, and open-source.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -108,15 +108,43 @@ export async function generateConfig(projectDir, options, frameworkConfig = null
108
108
  if (await pathExists(astroConfigPath)) {
109
109
  let content = await readFile(astroConfigPath, "utf-8");
110
110
 
111
- // Add import after the last existing import line
112
- const importLine = `import astroLlmsTxt from '@4hse/astro-llms-txt';`;
113
- if (!content.includes(importLine)) {
111
+ // Add imports after the last existing import line
112
+ const importLines = [
113
+ `import _astroLlmsTxt from '@4hse/astro-llms-txt';`,
114
+ `import { fileURLToPath as _llmsFileURLToPath } from 'url';`,
115
+ ];
116
+ // Wrapper: fix Windows dir.pathname (/C:/... → C:/...) before passing to plugin
117
+ const wrapperFn = `function astroLlmsTxt(opts) {
118
+ const inner = _astroLlmsTxt(opts);
119
+ const origHook = inner.hooks['astro:build:done'];
120
+ inner.hooks['astro:build:done'] = async (args) => {
121
+ if (args.dir && args.dir.pathname) {
122
+ const fixed = _llmsFileURLToPath(args.dir);
123
+ args = { ...args, dir: { ...args.dir, pathname: fixed } };
124
+ }
125
+ return origHook(args);
126
+ };
127
+ return inner;
128
+ }`;
129
+ for (const importLine of importLines) {
130
+ if (!content.includes(importLine)) {
131
+ const lines = content.split('\n');
132
+ let lastImportIdx = 0;
133
+ for (let i = 0; i < lines.length; i++) {
134
+ if (lines[i].startsWith('import ')) lastImportIdx = i;
135
+ }
136
+ lines.splice(lastImportIdx + 1, 0, importLine);
137
+ content = lines.join('\n');
138
+ }
139
+ }
140
+ // Inject wrapper function after imports
141
+ if (!content.includes('function astroLlmsTxt(')) {
114
142
  const lines = content.split('\n');
115
143
  let lastImportIdx = 0;
116
144
  for (let i = 0; i < lines.length; i++) {
117
145
  if (lines[i].startsWith('import ')) lastImportIdx = i;
118
146
  }
119
- lines.splice(lastImportIdx + 1, 0, importLine);
147
+ lines.splice(lastImportIdx + 1, 0, '', wrapperFn);
120
148
  content = lines.join('\n');
121
149
  }
122
150