mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-10 08:51:24 +00:00
fix(engine): do not inject imports if exists in md
This commit is contained in:
5
TODO.md
5
TODO.md
@@ -1,3 +1,8 @@
|
||||
## TODO
|
||||
|
||||
- 404 page background images are not being loaded
|
||||
- sitemap.xml not deployed on netlify
|
||||
|
||||
## Features
|
||||
|
||||
- recursive rendering of lit / html / and markdown
|
||||
|
||||
@@ -285,7 +285,7 @@ export class RocketHeader {
|
||||
}
|
||||
|
||||
if (startIndex >= 0 && endIndex >= 0) {
|
||||
return lines.splice(endIndex + 1).join('\n');
|
||||
return [...lines.slice(0, startIndex), ...lines.slice(endIndex + 1)].join('\n');
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { basename } from 'path';
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isRocketIndexFile(filePath) {
|
||||
const fileName = basename(filePath);
|
||||
return (
|
||||
filePath.endsWith('index.rocket.js') ||
|
||||
filePath.endsWith('index.rocket.md') ||
|
||||
filePath.endsWith('index.rocket.html')
|
||||
fileName === 'index.rocket.js' ||
|
||||
fileName === 'index.rocket.md' ||
|
||||
fileName === 'index.rocket.html'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -334,6 +334,42 @@ describe('Engine Data Cascade', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('08b: does not inject imports if the file itself imports the key [md]', async () => {
|
||||
const { build, readSource, writeSource } = await setupTestEngine(
|
||||
'fixtures/01-data-cascade/08b-consider-user-imports-[md]/docs',
|
||||
);
|
||||
await writeSource(
|
||||
'index.rocket.md',
|
||||
[
|
||||
'```js server',
|
||||
'/* START - Rocket auto generated - do not touch */',
|
||||
'/* END - Rocket auto generated - do not touch */',
|
||||
'',
|
||||
"import { html } from './_dep.js';",
|
||||
'```',
|
||||
'',
|
||||
'index',
|
||||
].join('\n'),
|
||||
);
|
||||
await build();
|
||||
|
||||
expect(readSource('index.rocket.md')).to.equal(
|
||||
[
|
||||
'```js server',
|
||||
'/* START - Rocket auto generated - do not touch */',
|
||||
"export const sourceRelativeFilePath = 'index.rocket.md';",
|
||||
"import { control } from './recursive.data.js';",
|
||||
'export { control };',
|
||||
'/* END - Rocket auto generated - do not touch */',
|
||||
'',
|
||||
"import { html } from './_dep.js';",
|
||||
'```',
|
||||
'',
|
||||
'index',
|
||||
].join('\n'),
|
||||
);
|
||||
});
|
||||
|
||||
it('09: only injects into the first header it finds', async () => {
|
||||
const { build, readSource, writeSource } = await setupTestEngine(
|
||||
'fixtures/01-data-cascade/09-touch-only-first-header/docs',
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { html } from 'lit';
|
||||
@@ -0,0 +1,11 @@
|
||||
```js server
|
||||
/* START - Rocket auto generated - do not touch */
|
||||
export const sourceRelativeFilePath = 'index.rocket.md';
|
||||
import { control } from './recursive.data.js';
|
||||
export { control };
|
||||
/* END - Rocket auto generated - do not touch */
|
||||
|
||||
import { html } from './_dep.js';
|
||||
```
|
||||
|
||||
index
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "index.rocket.md",
|
||||
"menuLinkText": "index.rocket.md",
|
||||
"url": "/",
|
||||
"outputRelativeFilePath": "index.html",
|
||||
"sourceRelativeFilePath": "index.rocket.md",
|
||||
"level": 0,
|
||||
"control": ""
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export { html } from 'lit';
|
||||
|
||||
export const control = '';
|
||||
Reference in New Issue
Block a user