@videinfra/static-website-builder 2.0.3 → 2.0.5
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/CHANGELOG.md +8 -0
- package/init/test/src/html/other.twig +1 -1
- package/lib/get-config.js +3 -4
- package/package.json +1 -1
- package/tasks/data/get-data.js +42 -3
- package/tasks/html/task.js +2 -2
- package/tests/build/build.test.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.0.5] - 2026-02-12
|
|
8
|
+
### Added
|
|
9
|
+
- Expose `currentPagePath` to Twig templates
|
|
10
|
+
|
|
11
|
+
## [2.0.4] - 2026-02-11
|
|
12
|
+
### Fixed
|
|
13
|
+
- Path error on windows
|
|
14
|
+
|
|
7
15
|
## [2.0.3] - 2026-02-03
|
|
8
16
|
### Added
|
|
9
17
|
- Allow writing ASSETS_VERSION to .env file
|
package/lib/get-config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { getProjectPath } from './get-path.js';
|
|
6
6
|
import runPreprocess from './run-preprocess.js';
|
|
@@ -13,7 +13,6 @@ import isPlainObject from 'lodash/isPlainObject.js';
|
|
|
13
13
|
import isArray from 'lodash/isArray.js';
|
|
14
14
|
import reduce from 'lodash/reduce.js';
|
|
15
15
|
import get from 'lodash/get.js';
|
|
16
|
-
import { Module } from 'node:module';
|
|
17
16
|
|
|
18
17
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
18
|
|
|
@@ -50,7 +49,7 @@ export async function getConfigAsync(builderConfigFile) {
|
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
if (hasProjectConfigFile) {
|
|
53
|
-
await import(projectConfigPath).then((config) => {
|
|
52
|
+
await import(pathToFileURL(projectConfigPath)).then((config) => {
|
|
54
53
|
projectTaskConfig = itterateConfig(config, mergeConfigMode);
|
|
55
54
|
});
|
|
56
55
|
}
|
|
@@ -193,7 +192,7 @@ async function loadConfig() {
|
|
|
193
192
|
return;
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
return import(configFileName).then((config) => {
|
|
195
|
+
return import(pathToFileURL(configFileName)).then((config) => {
|
|
197
196
|
taskConfig = merge(taskConfig, config);
|
|
198
197
|
});
|
|
199
198
|
}
|
package/package.json
CHANGED
package/tasks/data/get-data.js
CHANGED
|
@@ -78,19 +78,58 @@ let cache = null;
|
|
|
78
78
|
|
|
79
79
|
export default function (options) {
|
|
80
80
|
const build = options && !!options.build;
|
|
81
|
+
const htmlSourceFolders = getSourcePaths('html');
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Calculate current page path based on file path which is being processed
|
|
85
|
+
* @param {*} file
|
|
86
|
+
* @returns {string} Current page path
|
|
87
|
+
*/
|
|
88
|
+
const getCurrentPagePath = function (file) {
|
|
89
|
+
let currentPagePath = '';
|
|
90
|
+
|
|
91
|
+
// Remove extension
|
|
92
|
+
const htmlFilePath = file.path ? file.path.replace(/\..+?$/, '') : '';
|
|
93
|
+
|
|
94
|
+
// Remove html source folder from path
|
|
95
|
+
if (htmlFilePath && htmlSourceFolders.length) {
|
|
96
|
+
for (let i = 0; i < htmlSourceFolders.length; i++) {
|
|
97
|
+
const htmlSourceFolder = htmlSourceFolders[i];
|
|
98
|
+
if (htmlFilePath.indexOf(htmlSourceFolder) === 0) {
|
|
99
|
+
currentPagePath = htmlFilePath
|
|
100
|
+
.replace(htmlSourceFolder, '')
|
|
101
|
+
.replace(/[\/\\]index$/, '');
|
|
102
|
+
|
|
103
|
+
// Make sure that the root page is just '/', not empty string
|
|
104
|
+
currentPagePath = currentPagePath || '/';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return currentPagePath;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return function (file) {
|
|
113
|
+
// We expose `currentPagePath` to Twig templates
|
|
114
|
+
const currentPagePath = getCurrentPagePath(file);
|
|
81
115
|
|
|
82
|
-
return function () {
|
|
83
116
|
if (build) {
|
|
84
117
|
// Cache during full build
|
|
85
118
|
if (!cache) {
|
|
86
119
|
cache = getData();
|
|
87
120
|
}
|
|
88
121
|
|
|
89
|
-
return
|
|
122
|
+
return {
|
|
123
|
+
currentPagePath,
|
|
124
|
+
...cache
|
|
125
|
+
};
|
|
90
126
|
} else {
|
|
91
127
|
// Don't cache during watch build
|
|
92
128
|
cache = null;
|
|
93
|
-
return
|
|
129
|
+
return {
|
|
130
|
+
currentPagePath,
|
|
131
|
+
...getData(),
|
|
132
|
+
};
|
|
94
133
|
}
|
|
95
134
|
};
|
|
96
135
|
}
|
package/tasks/html/task.js
CHANGED
|
@@ -61,8 +61,8 @@ function html(options) {
|
|
|
61
61
|
.pipe(taskStart())
|
|
62
62
|
|
|
63
63
|
// Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
|
|
64
|
-
.pipe(gulpif(!!getTaskConfig('html', 'dependents'), cached('html')))
|
|
65
|
-
.pipe(gulpif(!!getTaskConfig('html', 'dependents'), dependents(getTaskConfig('dependents'))))
|
|
64
|
+
.pipe(gulpif(!build && !!getTaskConfig('html', 'dependents'), cached('html')))
|
|
65
|
+
.pipe(gulpif(!build && !!getTaskConfig('html', 'dependents'), dependents(getTaskConfig('dependents'))))
|
|
66
66
|
|
|
67
67
|
// Prevent file from being rendered if it's in the ignore list
|
|
68
68
|
.pipe(ignore.exclude(getGlobIgnorePaths(), {}))
|
|
@@ -131,6 +131,12 @@ test('process.env available in html/data', () => {
|
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
+
test('currentPagePath available in templates', () => {
|
|
135
|
+
return fsPromises.readFile(path.resolve(publicPath, 'other.html'), { encoding: 'utf8' }).then((html) => {
|
|
136
|
+
expect(html.indexOf('Current page path: "/other"')).not.toBe(-1);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
134
140
|
test('icons generated', () => {
|
|
135
141
|
return fsPromises.readFile(path.resolve(publicPath, 'assets/images/icons.svg'), { encoding: 'utf8' }).then((svg) => {
|
|
136
142
|
expect(svg.indexOf('<symbol id="example-arrow">')).not.toBe(-1);
|