fix(engine): do not inject imports if exists in md

This commit is contained in:
Thomas Allmer
2022-06-13 14:10:40 +02:00
parent 2bc4282efa
commit aeb5ad2e99
8 changed files with 72 additions and 4 deletions

View File

@@ -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

View File

@@ -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');
}

View File

@@ -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'
);
}

View File

@@ -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',

View File

@@ -0,0 +1 @@
export { html } from 'lit';

View File

@@ -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

View File

@@ -0,0 +1,9 @@
{
"name": "index.rocket.md",
"menuLinkText": "index.rocket.md",
"url": "/",
"outputRelativeFilePath": "index.html",
"sourceRelativeFilePath": "index.rocket.md",
"level": 0,
"control": ""
}

View File

@@ -0,0 +1,3 @@
export { html } from 'lit';
export const control = '';