Skip to content

Commit 0b9789e

Browse files
committed
Merge branch 'release/1.4.0'
2 parents fb8107d + 03eb457 commit 0b9789e

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ it will help for setting a dev environment.
1212
scan html content looking for pattern like :
1313
```
1414
<!--#include virtual="/your/path/file.html" -->
15+
<!--#include file"/your/path/file.html" -->
1516
```
1617

1718
if found any :
@@ -50,8 +51,9 @@ module: {
5051
### Parameters
5152
| Parameters | Type | Default | Description |
5253
| ---------------- |:-------------:|:--------------:| :------------ |
53-
| location | string | | http url where the file can be dl ex:'https://mywebsite.com/' |
54+
| location | string | | http url where the file can be dl ex:'https://mywebsite.com/' |
5455
| localPath | string | | path where the include files could be found ex: path.join(__dirname, '/public') |
55-
| depthMax | number | 4 | how far should the SSI include should look for match within included files (don't touch unless you know what you are doing) |
56+
| depthMax | number | 4 | how far should the SSI include should look for match within included files |
5657
| disableLocalScan | boolean | false | if you want the script to look only on the `location` url |
5758
| includesMatcher | regex | /&lt;!--\s?#\s?include\s+(?:virtual&#124;file)=&quot;([^&quot;]+)&quot;(?:\s+stub=&quot;(\w+)&quot;)?\s?--&gt;/ | regex of the matching string (don't touch unless you know what you are doing) |
59+
| defaultCharset | string | utf-8 | force the file reader to convert the file content into a specific charset |

lib/ssi.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const fs = require('fs');
1212
* @param {number} [param.depthMax=4] how far should the SSI include should look for match withing inluded files
1313
* @param {boolean} [param.disableLocalScan=false] if you want the script to look only on the `param.location` url
1414
* @param {regex} [param.includesMatcher=/<!--\s?#\s?include\s+(?:virtual|file)="([^"]+)"(?:\s+stub="(\w+)")?\s?-->/] regex of the matching string (don't touch unless you know what you are doing)
15-
* }
15+
* @param {string} [param.defaultCharset='utf-8'] force the file reader to convert the file content into a specific charset
16+
*
1617
* @return {string} formated HTML with the SSI include files content
1718
*/
1819
const SSI = function (param) {
1920
const defaultOptions = {
20-
depthMax: 5,
21+
depthMax: 4,
2122
disableLocalScan: false,
2223
includesMatcher: /<!--\s?#\s?include\s+(?:virtual|file)="([^"]+)"(?:\s+stub="(\w+)")?\s?-->/,
2324
}
@@ -68,28 +69,27 @@ const SSI = function (param) {
6869
}
6970
}
7071

71-
async function processInclude(part, content, i) {
72+
async function processInclude(part, i) {
7273
const matches = part.match(options.includesMatcher);
7374
if (!matches) {
74-
return content + part;
75+
return part;
7576
}
7677

7778
const ssiString = matches[0];
7879
const location = matches[1];
7980

8081
const body = await getContent(location);
81-
const formatedContent = content + part.replace(ssiString, '');
82-
if(i >= options.depthMax) return formatedContent + body;
83-
else return await processInclude(body, formatedContent, i + 1);
82+
if(i >= options.depthMax) return body;
83+
else return await compile(body, i + 1);
8484
}
8585

86-
async function compile(content) {
86+
async function compile(content, i = 0) {
8787
let output = [];
8888
const splitContent = content.split('\n');
8989
// eslint-disable-next-line
9090
for (const line of splitContent) {
9191
const part = line.trim();
92-
output += await processInclude(part, '', 0);
92+
output += await processInclude(part, i);
9393
}
9494

9595
return output;

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-ssi-include-loader",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Webpack SSI Include Loader",
55
"main": "index.js",
66
"scripts": {},
@@ -14,8 +14,6 @@
1414
"dependencies": {
1515
"chardet": "^1.0.0",
1616
"iconv-lite": "^0.5.1",
17-
"loader-utils": "^2.0.0",
18-
"object-assign": "^4.1.1",
1917
"then-request": "^6.0.2"
2018
}
2119
}

0 commit comments

Comments
 (0)