@videinfra/static-website-builder 2.0.2 → 2.0.4
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/.prettierrc +11 -11
- package/CHANGELOG.md +214 -210
- package/README.md +102 -102
- package/bin/builder.js +40 -40
- package/eslint.config.js +39 -39
- package/gulpfile.js +63 -63
- package/init/default/config/config.js +44 -44
- package/init/default/src/html/data/global.js +9 -9
- package/init/default/src/javascripts/_entries.js +14 -14
- package/init/index.js +63 -63
- package/init/test/.env +6 -6
- package/init/test/.env.local +3 -2
- package/init/test/config/config.js +71 -67
- package/init/test/src/html/404.twig +12 -12
- package/init/test/src/html/data/global.js +10 -10
- package/init/test/src/html/env.twig +21 -21
- package/init/test/src/html/layouts/base.twig +1 -1
- package/init/test/src/html/other.twig +9 -9
- package/init/test/src/html/preposition.twig +4 -4
- package/init/test/src/javascripts/_entries-alt.js +10 -10
- package/init/test/src/javascripts/_entries.js +19 -19
- package/init/test/src/javascripts/common.js +13 -13
- package/init/test/src/javascripts/main.js +8 -8
- package/init/test/src/javascripts/something.ts +9 -9
- package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
- package/init/test/src/stylesheets/env-test.scss +28 -28
- package/init/test/src/stylesheets/ignore-test.scss +4 -4
- package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
- package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
- package/lib/camelize-file-name.js +21 -21
- package/lib/generate-gulp-tasks.js +85 -85
- package/lib/get-config.js +203 -204
- package/lib/get-file-names.js +23 -23
- package/lib/get-path.js +102 -102
- package/lib/globs-helper.js +243 -243
- package/lib/gulp/dynamic-task.js +8 -8
- package/lib/gulp/resolve-dynamic-task.js +11 -11
- package/lib/gulp/task-before-dest.js +8 -8
- package/lib/gulp/task-end.js +10 -10
- package/lib/gulp/task-start.js +12 -12
- package/lib/gulp/task-watch.js +66 -66
- package/lib/init/copy-folder.js +50 -50
- package/lib/init/folder-exists.js +10 -10
- package/lib/init/get-folder-list.js +16 -16
- package/lib/init/merge-package.js +17 -17
- package/lib/init/read-package.js +17 -17
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- package/lib/run-preprocess.js +32 -32
- package/lib/task-order.js +19 -19
- package/package.json +68 -68
- package/plugins/example/preprocess-config.js +17 -17
- package/plugins/example/task.js +55 -55
- package/plugins/example.js +38 -38
- package/plugins/sass-engine/preprocess-config.js +59 -59
- package/plugins/sass.js +41 -41
- package/plugins/twig/lodash-filters/filters.js +91 -91
- package/plugins/twig/lodash-filters.js +14 -14
- package/plugins/twig/symfony-filters/filters.js +102 -102
- package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
- package/plugins/twig/symfony-filters.js +14 -14
- package/plugins/twig/symfony-functions/functions.js +31 -31
- package/plugins/twig/symfony-functions.js +14 -14
- package/plugins/twig-engine/preprocess-config.js +53 -53
- package/plugins/twig.js +74 -74
- package/tasks/browser-sync/config.js +39 -39
- package/tasks/browser-sync/preprocess-config.js +32 -32
- package/tasks/browser-sync/task.js +9 -9
- package/tasks/clean/config.js +20 -20
- package/tasks/clean/preprocess-config.js +19 -19
- package/tasks/clean/task.js +7 -7
- package/tasks/data/config.js +34 -34
- package/tasks/data/data-loader-js.js +14 -14
- package/tasks/data/data-loader-json.js +5 -5
- package/tasks/data/get-data.js +96 -96
- package/tasks/env/config.js +26 -23
- package/tasks/env/get-env.js +113 -81
- package/tasks/fonts/config.js +24 -24
- package/tasks/fonts/task.js +47 -47
- package/tasks/global/config.js +7 -7
- package/tasks/html/config.js +42 -42
- package/tasks/html/task.js +91 -91
- package/tasks/icons/config.js +47 -47
- package/tasks/icons/preprocess-config.js +60 -60
- package/tasks/icons/task.js +56 -56
- package/tasks/images/config.js +27 -27
- package/tasks/images/task.js +46 -46
- package/tasks/javascripts/config.js +69 -69
- package/tasks/javascripts/preprocess-config.js +109 -109
- package/tasks/javascripts/task.js +86 -86
- package/tasks/sitemap/config.js +48 -48
- package/tasks/sitemap/preprocess-config.js +18 -18
- package/tasks/sitemap/task.js +69 -69
- package/tasks/sizereport/config.js +23 -23
- package/tasks/sizereport/task.js +16 -16
- package/tasks/static/config.js +27 -27
- package/tasks/static/task.js +46 -46
- package/tasks/stylesheets/config.js +85 -85
- package/tasks/stylesheets/preprocess-config.js +41 -41
- package/tasks/stylesheets/task.js +73 -73
- package/tests/build/build.test.js +153 -153
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/generate-gulp-tasks.test.js +78 -78
- package/tests/glob-helper.test.js +99 -99
- package/tests/merge.test.js +10 -10
- package/tests/preposition_nbsp.test.js +50 -50
- package/tests/run-preprocess.test.js +90 -90
- package/tests/sass-stringify.test.js +24 -24
- package/tests/sitemap.test.js +12 -12
- package/vendor/gulp-rolldown/index.js +151 -151
- package/vendor/gulp-rolldown/plugin-raw.js +17 -17
- package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
- package/vendor/gulp-sass/CHANGELOG.md +168 -168
- package/vendor/gulp-sass/LICENSE +20 -20
- package/vendor/gulp-sass/README.md +187 -187
- package/vendor/gulp-sass/index.js +208 -208
- package/vendor/gulp-sass/package.json +61 -61
- package/vendor/gulp-sass/sass-stringify.js +32 -32
- package/vendor/gulp-twig/LICENSE +20 -20
- package/vendor/gulp-twig/README.md +167 -167
- package/vendor/gulp-twig/index.js +138 -138
- package/vendor/gulp-twig/package.json +44 -44
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
const exports = [];
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Filter with lodash 'omit' functionality
|
|
5
|
-
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
exports.push({
|
|
9
|
-
name: 'omit',
|
|
10
|
-
func: function (data, args) {
|
|
11
|
-
const output = {};
|
|
12
|
-
const keys = args[0] || [];
|
|
13
|
-
|
|
14
|
-
for (let key in data) {
|
|
15
|
-
if (key !== '_keys' && keys.indexOf(key) === -1) {
|
|
16
|
-
output[key] = data[key];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Filter with lodash 'pick' functionality
|
|
26
|
-
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
exports.push({
|
|
30
|
-
name: 'pick',
|
|
31
|
-
func: function (data, args) {
|
|
32
|
-
const output = {};
|
|
33
|
-
const keys = args[0] || [];
|
|
34
|
-
|
|
35
|
-
for (let key in data) {
|
|
36
|
-
if (key !== '_keys' && keys.indexOf(key) !== -1) {
|
|
37
|
-
output[key] = data[key];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return output;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Filter with lodash 'filter' functionality
|
|
47
|
-
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
import filter from 'lodash/filter.js';
|
|
51
|
-
import omit from 'lodash/omit.js';
|
|
52
|
-
|
|
53
|
-
exports.push({
|
|
54
|
-
name: 'filter',
|
|
55
|
-
func: function (data, args) {
|
|
56
|
-
const predicate = omit(args[0], ['_keys']);
|
|
57
|
-
return filter(data, predicate);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Filter with lodash 'reject' functionality
|
|
63
|
-
* !!!CAUTION!!! There is no reject in TWIG with this functionality!
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
import reject from 'lodash/reject.js';
|
|
67
|
-
|
|
68
|
-
exports.push({
|
|
69
|
-
name: 'reject',
|
|
70
|
-
func: function (data, args) {
|
|
71
|
-
const predicate = omit(args[0], ['_keys']);
|
|
72
|
-
return reject(data, predicate);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Filter with lodash 'find' functionality
|
|
78
|
-
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
import find from 'lodash/find.js';
|
|
82
|
-
|
|
83
|
-
exports.push({
|
|
84
|
-
name: 'find',
|
|
85
|
-
func: function (data, args) {
|
|
86
|
-
const predicate = omit(args[0], ['_keys']);
|
|
87
|
-
return find(data, predicate);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export default exports;
|
|
1
|
+
const exports = [];
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filter with lodash 'omit' functionality
|
|
5
|
+
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
exports.push({
|
|
9
|
+
name: 'omit',
|
|
10
|
+
func: function (data, args) {
|
|
11
|
+
const output = {};
|
|
12
|
+
const keys = args[0] || [];
|
|
13
|
+
|
|
14
|
+
for (let key in data) {
|
|
15
|
+
if (key !== '_keys' && keys.indexOf(key) === -1) {
|
|
16
|
+
output[key] = data[key];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Filter with lodash 'pick' functionality
|
|
26
|
+
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
exports.push({
|
|
30
|
+
name: 'pick',
|
|
31
|
+
func: function (data, args) {
|
|
32
|
+
const output = {};
|
|
33
|
+
const keys = args[0] || [];
|
|
34
|
+
|
|
35
|
+
for (let key in data) {
|
|
36
|
+
if (key !== '_keys' && keys.indexOf(key) !== -1) {
|
|
37
|
+
output[key] = data[key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return output;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Filter with lodash 'filter' functionality
|
|
47
|
+
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
import filter from 'lodash/filter.js';
|
|
51
|
+
import omit from 'lodash/omit.js';
|
|
52
|
+
|
|
53
|
+
exports.push({
|
|
54
|
+
name: 'filter',
|
|
55
|
+
func: function (data, args) {
|
|
56
|
+
const predicate = omit(args[0], ['_keys']);
|
|
57
|
+
return filter(data, predicate);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Filter with lodash 'reject' functionality
|
|
63
|
+
* !!!CAUTION!!! There is no reject in TWIG with this functionality!
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
import reject from 'lodash/reject.js';
|
|
67
|
+
|
|
68
|
+
exports.push({
|
|
69
|
+
name: 'reject',
|
|
70
|
+
func: function (data, args) {
|
|
71
|
+
const predicate = omit(args[0], ['_keys']);
|
|
72
|
+
return reject(data, predicate);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Filter with lodash 'find' functionality
|
|
78
|
+
* !!!CAUTION!!! There is no filter in TWIG with this functionality!
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
import find from 'lodash/find.js';
|
|
82
|
+
|
|
83
|
+
exports.push({
|
|
84
|
+
name: 'find',
|
|
85
|
+
func: function (data, args) {
|
|
86
|
+
const predicate = omit(args[0], ['_keys']);
|
|
87
|
+
return find(data, predicate);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export default exports;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import filters from './lodash-filters/filters.js';
|
|
2
|
-
|
|
3
|
-
export const preprocess = {
|
|
4
|
-
html: [
|
|
5
|
-
function lodashFiltersPlugin (config) {
|
|
6
|
-
// Add filters to TWIG configurtion
|
|
7
|
-
config.twig = config.twig || {};
|
|
8
|
-
config.twig.filters = config.twig.filters || [];
|
|
9
|
-
config.twig.filters = config.twig.filters.concat(filters);
|
|
10
|
-
|
|
11
|
-
return config;
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
};
|
|
1
|
+
import filters from './lodash-filters/filters.js';
|
|
2
|
+
|
|
3
|
+
export const preprocess = {
|
|
4
|
+
html: [
|
|
5
|
+
function lodashFiltersPlugin (config) {
|
|
6
|
+
// Add filters to TWIG configurtion
|
|
7
|
+
config.twig = config.twig || {};
|
|
8
|
+
config.twig.filters = config.twig.filters || [];
|
|
9
|
+
config.twig.filters = config.twig.filters.concat(filters);
|
|
10
|
+
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
};
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { getTaskConfig } from '../../../lib/get-config.js';
|
|
2
|
-
import { loadEnvData } from '../../../tasks/env/get-env.js';
|
|
3
|
-
import preposition_nbsp from './preposition_nbsp.js';
|
|
4
|
-
|
|
5
|
-
const exports = [];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* CDN filter
|
|
9
|
-
* Adds a CDN path to the url
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* {{ '/images/px.gif' | cdn }}
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const cdnsResourceMap = {};
|
|
16
|
-
let cdnIndex = -1;
|
|
17
|
-
|
|
18
|
-
exports.push({
|
|
19
|
-
name: 'cdnify',
|
|
20
|
-
func: function (path) {
|
|
21
|
-
const normalizedPath = (path || path === 0 ? String(path) : '');
|
|
22
|
-
const cdnsConfig = getTaskConfig('html', 'cdns');
|
|
23
|
-
|
|
24
|
-
if (cdnsResourceMap[normalizedPath]) return cdnsResourceMap[normalizedPath]; // cache so that same resource always use same cdn
|
|
25
|
-
if (!cdnsConfig || !cdnsConfig.length) return normalizedPath;
|
|
26
|
-
|
|
27
|
-
cdnIndex = (cdnIndex + 1) % cdnsConfig.length;
|
|
28
|
-
cdnsResourceMap[normalizedPath] = cdnsConfig[cdnIndex] + normalizedPath.replace(/^[a-z]+:\/\/[^/]+/i);
|
|
29
|
-
return cdnsResourceMap[normalizedPath];
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Version filter
|
|
36
|
-
* Adds a version string to the url
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* {{ '/images/px.gif' | version }}
|
|
40
|
-
* Output: /images/px.gif?dshnv
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
exports.push({
|
|
44
|
-
name: 'version',
|
|
45
|
-
func: function (path) {
|
|
46
|
-
if (!getTaskConfig('html', 'version')) return path;
|
|
47
|
-
const envData = loadEnvData();
|
|
48
|
-
const assetVersion = envData['ASSETS_VERSION'];
|
|
49
|
-
|
|
50
|
-
if (!assetVersion) return path;
|
|
51
|
-
|
|
52
|
-
const normalizedPath = (path || path === 0 ? String(path) : '');
|
|
53
|
-
const parts = normalizedPath.match(/^([^?#]*)(\?[^#]*)?(#.*)?$/i);
|
|
54
|
-
const pathname = parts[1];
|
|
55
|
-
const params = parts[2] || '';
|
|
56
|
-
const hash = parts[3] || '';
|
|
57
|
-
|
|
58
|
-
return pathname + params + (params ? '&v=' : '?v=') + assetVersion + hash;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Humanize filter
|
|
65
|
-
* Makes a technical name human readable
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* {{ 'helloWorld' | humanize }}
|
|
69
|
-
* Output: hello world
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
exports.push({
|
|
73
|
-
name: 'humanize',
|
|
74
|
-
func: function (text) {
|
|
75
|
-
text = String(text);
|
|
76
|
-
text = text.replace(/([A-Z])/g, '_$1');
|
|
77
|
-
text = text.replace(/[_\s]+/g, ' ');
|
|
78
|
-
text = text.toLowerCase();
|
|
79
|
-
text = text.trim();
|
|
80
|
-
text = text.slice(0,1 ).toUpperCase() + text.slice(1);
|
|
81
|
-
|
|
82
|
-
return text;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Preposition filter
|
|
88
|
-
* Adds a non-breaking space between prepositions and other words
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* {{ 'hello at world' | preposition_nbsp }}
|
|
92
|
-
* Output: hello at world
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
exports.push({
|
|
96
|
-
name: 'preposition_nbsp',
|
|
97
|
-
func: function (text) {
|
|
98
|
-
return preposition_nbsp(text);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
export default exports;
|
|
1
|
+
import { getTaskConfig } from '../../../lib/get-config.js';
|
|
2
|
+
import { loadEnvData } from '../../../tasks/env/get-env.js';
|
|
3
|
+
import preposition_nbsp from './preposition_nbsp.js';
|
|
4
|
+
|
|
5
|
+
const exports = [];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CDN filter
|
|
9
|
+
* Adds a CDN path to the url
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* {{ '/images/px.gif' | cdn }}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const cdnsResourceMap = {};
|
|
16
|
+
let cdnIndex = -1;
|
|
17
|
+
|
|
18
|
+
exports.push({
|
|
19
|
+
name: 'cdnify',
|
|
20
|
+
func: function (path) {
|
|
21
|
+
const normalizedPath = (path || path === 0 ? String(path) : '');
|
|
22
|
+
const cdnsConfig = getTaskConfig('html', 'cdns');
|
|
23
|
+
|
|
24
|
+
if (cdnsResourceMap[normalizedPath]) return cdnsResourceMap[normalizedPath]; // cache so that same resource always use same cdn
|
|
25
|
+
if (!cdnsConfig || !cdnsConfig.length) return normalizedPath;
|
|
26
|
+
|
|
27
|
+
cdnIndex = (cdnIndex + 1) % cdnsConfig.length;
|
|
28
|
+
cdnsResourceMap[normalizedPath] = cdnsConfig[cdnIndex] + normalizedPath.replace(/^[a-z]+:\/\/[^/]+/i);
|
|
29
|
+
return cdnsResourceMap[normalizedPath];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Version filter
|
|
36
|
+
* Adds a version string to the url
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* {{ '/images/px.gif' | version }}
|
|
40
|
+
* Output: /images/px.gif?dshnv
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
exports.push({
|
|
44
|
+
name: 'version',
|
|
45
|
+
func: function (path) {
|
|
46
|
+
if (!getTaskConfig('html', 'version')) return path;
|
|
47
|
+
const envData = loadEnvData();
|
|
48
|
+
const assetVersion = envData['ASSETS_VERSION'];
|
|
49
|
+
|
|
50
|
+
if (!assetVersion) return path;
|
|
51
|
+
|
|
52
|
+
const normalizedPath = (path || path === 0 ? String(path) : '');
|
|
53
|
+
const parts = normalizedPath.match(/^([^?#]*)(\?[^#]*)?(#.*)?$/i);
|
|
54
|
+
const pathname = parts[1];
|
|
55
|
+
const params = parts[2] || '';
|
|
56
|
+
const hash = parts[3] || '';
|
|
57
|
+
|
|
58
|
+
return pathname + params + (params ? '&v=' : '?v=') + assetVersion + hash;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Humanize filter
|
|
65
|
+
* Makes a technical name human readable
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* {{ 'helloWorld' | humanize }}
|
|
69
|
+
* Output: hello world
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
exports.push({
|
|
73
|
+
name: 'humanize',
|
|
74
|
+
func: function (text) {
|
|
75
|
+
text = String(text);
|
|
76
|
+
text = text.replace(/([A-Z])/g, '_$1');
|
|
77
|
+
text = text.replace(/[_\s]+/g, ' ');
|
|
78
|
+
text = text.toLowerCase();
|
|
79
|
+
text = text.trim();
|
|
80
|
+
text = text.slice(0,1 ).toUpperCase() + text.slice(1);
|
|
81
|
+
|
|
82
|
+
return text;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Preposition filter
|
|
88
|
+
* Adds a non-breaking space between prepositions and other words
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* {{ 'hello at world' | preposition_nbsp }}
|
|
92
|
+
* Output: hello at world
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
exports.push({
|
|
96
|
+
name: 'preposition_nbsp',
|
|
97
|
+
func: function (text) {
|
|
98
|
+
return preposition_nbsp(text);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export default exports;
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
const prepositions = [
|
|
2
|
-
'about', 'above', 'across', 'after', 'against', 'along', 'amid', 'among', 'around', 'as', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'besides', 'between', 'beyond', 'by', 'concerning', 'despite', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'onto', 'out', 'outside', 'over', 'past', 'regarding', 'round', 'since', 'through', 'throughout', 'to', 'toward', 'towards', 'under', 'underneath', 'until', 'unto', 'up', 'upon', 'with', 'within', 'without', 'a', 'an', 'the',
|
|
3
|
-
'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', 'со', 'против', 'во', 'ко', 'ото', 'изо', 'надо', 'подо', 'передо', 'передо', 'из-за', 'чтобы', 'когда', 'его', 'которое', 'как', 'и', 'ей', 'они', 'мы', 'или', 'всё', 'я', 'которое', 'вашей', 'эти', 'что', 'вам', 'не уверены', 'а', 'вы', 'этим', 'вашим', 'все', 'если', 'о которой', 'в этом', 'но', 'которые', 'же', 'ваш', 'этой'
|
|
4
|
-
];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Word boundary regex
|
|
8
|
-
// (?<= # Lookbehind, but don't consume
|
|
9
|
-
// (^| # Start of string or
|
|
10
|
-
// [^\\p{L}] # Non-letter, works with unicode characters too
|
|
11
|
-
const regexWordBoundary = '(?<=(^|[^\\p{L}]))';
|
|
12
|
-
const regexEscape = /[.*+?^${}()|[\]\\]/g;
|
|
13
|
-
const regexSplitTags = /<[^>]+>/ug;
|
|
14
|
-
|
|
15
|
-
const regexMdash = /\s+—/uig;
|
|
16
|
-
const regexNdash = /\s+–/uig;
|
|
17
|
-
const regexHyphen = /\s+-/uig; // actual hyphen from keyboard
|
|
18
|
-
const regexHyphen2 = /\s+‐/uig;
|
|
19
|
-
const regexFigureDash = /\s+‒/uig;
|
|
20
|
-
|
|
21
|
-
const regexMdashEntity = /\s+—/uig;
|
|
22
|
-
const regexNdashEntity = /\s+–/uig;
|
|
23
|
-
const regexHyphenEntity = /\s+-/uig;
|
|
24
|
-
const regexHyphen2Entity = /\s+‐/uig;
|
|
25
|
-
const regexFigureDashEntity = /\s+‒/uig;
|
|
26
|
-
const regexDashEntity = /\s+‐/uig;
|
|
27
|
-
|
|
28
|
-
let prepositionsRegex = null;
|
|
29
|
-
|
|
30
|
-
function escapeRegExp(string) {
|
|
31
|
-
return string.replace(regexEscape, '\\$&'); // $& means the whole matched string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function prepositionNbsp(text) {
|
|
35
|
-
if (!text) {
|
|
36
|
-
return '';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!prepositionsRegex) {
|
|
40
|
-
const prepositionsEscaped = prepositions.map(preposition => escapeRegExp(preposition));
|
|
41
|
-
prepositionsRegex = new RegExp(`${regexWordBoundary}(${prepositionsEscaped.join('|')})\\s+`, 'uig');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Split text into regular text and HTML tags
|
|
45
|
-
const textTags = text.match(regexSplitTags) || [];
|
|
46
|
-
const textNoTags = text.split(regexSplitTags);
|
|
47
|
-
|
|
48
|
-
// Replace prepositions in regular text
|
|
49
|
-
for (let i = 0; i < textNoTags.length; i++) {
|
|
50
|
-
let textPart = textNoTags[i];
|
|
51
|
-
|
|
52
|
-
// Replace prepositions with non-breaking space
|
|
53
|
-
textPart = textPart.replace(prepositionsRegex, '$2 ');
|
|
54
|
-
|
|
55
|
-
textPart = textPart.replace(regexMdash, ' —', textPart);
|
|
56
|
-
textPart = textPart.replace(regexNdash, ' –', textPart);
|
|
57
|
-
textPart = textPart.replace(regexHyphen, ' -', textPart);
|
|
58
|
-
textPart = textPart.replace(regexHyphen2, ' ‐', textPart);
|
|
59
|
-
textPart = textPart.replace(regexFigureDash, ' ‒', textPart);
|
|
60
|
-
|
|
61
|
-
textPart = textPart.replace(regexMdashEntity, ' —', textPart);
|
|
62
|
-
textPart = textPart.replace(regexNdashEntity, ' –', textPart);
|
|
63
|
-
textPart = textPart.replace(regexHyphenEntity, ' -', textPart);
|
|
64
|
-
textPart = textPart.replace(regexHyphen2Entity, ' ‐', textPart);
|
|
65
|
-
textPart = textPart.replace(regexFigureDashEntity, ' ‒', textPart);
|
|
66
|
-
textPart = textPart.replace(regexDashEntity, ' ‐', textPart);
|
|
67
|
-
|
|
68
|
-
textNoTags[i] = textPart;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Iterate over regular text and and join back together with tags
|
|
72
|
-
return textNoTags.map((text, index) => {
|
|
73
|
-
return text + (textTags[index] || '');
|
|
74
|
-
}).join('');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default prepositionNbsp;
|
|
1
|
+
const prepositions = [
|
|
2
|
+
'about', 'above', 'across', 'after', 'against', 'along', 'amid', 'among', 'around', 'as', 'at', 'before', 'behind', 'below', 'beneath', 'beside', 'besides', 'between', 'beyond', 'by', 'concerning', 'despite', 'down', 'during', 'except', 'for', 'from', 'in', 'inside', 'into', 'like', 'near', 'of', 'off', 'on', 'onto', 'out', 'outside', 'over', 'past', 'regarding', 'round', 'since', 'through', 'throughout', 'to', 'toward', 'towards', 'under', 'underneath', 'until', 'unto', 'up', 'upon', 'with', 'within', 'without', 'a', 'an', 'the',
|
|
3
|
+
'в', 'на', 'по', 'к', 'у', 'от', 'из', 'с', 'над', 'под', 'при', 'без', 'до', 'для', 'за', 'через', 'перед', 'около', 'вокруг', 'о', 'об', 'обо', 'про', 'среди', 'между', 'ради', 'вдоль', 'вне', 'кроме', 'сквозь', 'вследствие', 'благодаря', 'согласно', 'вопреки', 'вроде', 'насчёт', 'касательно', 'со', 'против', 'во', 'ко', 'ото', 'изо', 'надо', 'подо', 'передо', 'передо', 'из-за', 'чтобы', 'когда', 'его', 'которое', 'как', 'и', 'ей', 'они', 'мы', 'или', 'всё', 'я', 'которое', 'вашей', 'эти', 'что', 'вам', 'не уверены', 'а', 'вы', 'этим', 'вашим', 'все', 'если', 'о которой', 'в этом', 'но', 'которые', 'же', 'ваш', 'этой'
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Word boundary regex
|
|
8
|
+
// (?<= # Lookbehind, but don't consume
|
|
9
|
+
// (^| # Start of string or
|
|
10
|
+
// [^\\p{L}] # Non-letter, works with unicode characters too
|
|
11
|
+
const regexWordBoundary = '(?<=(^|[^\\p{L}]))';
|
|
12
|
+
const regexEscape = /[.*+?^${}()|[\]\\]/g;
|
|
13
|
+
const regexSplitTags = /<[^>]+>/ug;
|
|
14
|
+
|
|
15
|
+
const regexMdash = /\s+—/uig;
|
|
16
|
+
const regexNdash = /\s+–/uig;
|
|
17
|
+
const regexHyphen = /\s+-/uig; // actual hyphen from keyboard
|
|
18
|
+
const regexHyphen2 = /\s+‐/uig;
|
|
19
|
+
const regexFigureDash = /\s+‒/uig;
|
|
20
|
+
|
|
21
|
+
const regexMdashEntity = /\s+—/uig;
|
|
22
|
+
const regexNdashEntity = /\s+–/uig;
|
|
23
|
+
const regexHyphenEntity = /\s+-/uig;
|
|
24
|
+
const regexHyphen2Entity = /\s+‐/uig;
|
|
25
|
+
const regexFigureDashEntity = /\s+‒/uig;
|
|
26
|
+
const regexDashEntity = /\s+‐/uig;
|
|
27
|
+
|
|
28
|
+
let prepositionsRegex = null;
|
|
29
|
+
|
|
30
|
+
function escapeRegExp(string) {
|
|
31
|
+
return string.replace(regexEscape, '\\$&'); // $& means the whole matched string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function prepositionNbsp(text) {
|
|
35
|
+
if (!text) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!prepositionsRegex) {
|
|
40
|
+
const prepositionsEscaped = prepositions.map(preposition => escapeRegExp(preposition));
|
|
41
|
+
prepositionsRegex = new RegExp(`${regexWordBoundary}(${prepositionsEscaped.join('|')})\\s+`, 'uig');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Split text into regular text and HTML tags
|
|
45
|
+
const textTags = text.match(regexSplitTags) || [];
|
|
46
|
+
const textNoTags = text.split(regexSplitTags);
|
|
47
|
+
|
|
48
|
+
// Replace prepositions in regular text
|
|
49
|
+
for (let i = 0; i < textNoTags.length; i++) {
|
|
50
|
+
let textPart = textNoTags[i];
|
|
51
|
+
|
|
52
|
+
// Replace prepositions with non-breaking space
|
|
53
|
+
textPart = textPart.replace(prepositionsRegex, '$2 ');
|
|
54
|
+
|
|
55
|
+
textPart = textPart.replace(regexMdash, ' —', textPart);
|
|
56
|
+
textPart = textPart.replace(regexNdash, ' –', textPart);
|
|
57
|
+
textPart = textPart.replace(regexHyphen, ' -', textPart);
|
|
58
|
+
textPart = textPart.replace(regexHyphen2, ' ‐', textPart);
|
|
59
|
+
textPart = textPart.replace(regexFigureDash, ' ‒', textPart);
|
|
60
|
+
|
|
61
|
+
textPart = textPart.replace(regexMdashEntity, ' —', textPart);
|
|
62
|
+
textPart = textPart.replace(regexNdashEntity, ' –', textPart);
|
|
63
|
+
textPart = textPart.replace(regexHyphenEntity, ' -', textPart);
|
|
64
|
+
textPart = textPart.replace(regexHyphen2Entity, ' ‐', textPart);
|
|
65
|
+
textPart = textPart.replace(regexFigureDashEntity, ' ‒', textPart);
|
|
66
|
+
textPart = textPart.replace(regexDashEntity, ' ‐', textPart);
|
|
67
|
+
|
|
68
|
+
textNoTags[i] = textPart;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Iterate over regular text and and join back together with tags
|
|
72
|
+
return textNoTags.map((text, index) => {
|
|
73
|
+
return text + (textTags[index] || '');
|
|
74
|
+
}).join('');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default prepositionNbsp;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import filters from './symfony-filters/filters.js';
|
|
2
|
-
|
|
3
|
-
export const preprocess = {
|
|
4
|
-
html: [
|
|
5
|
-
function symfonyFiltersPlugin(config) {
|
|
6
|
-
// Add filters to TWIG configurtion
|
|
7
|
-
config.twig = config.twig || {};
|
|
8
|
-
config.twig.filters = config.twig.filters || [];
|
|
9
|
-
config.twig.filters = config.twig.filters.concat(filters);
|
|
10
|
-
|
|
11
|
-
return config;
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
};
|
|
1
|
+
import filters from './symfony-filters/filters.js';
|
|
2
|
+
|
|
3
|
+
export const preprocess = {
|
|
4
|
+
html: [
|
|
5
|
+
function symfonyFiltersPlugin(config) {
|
|
6
|
+
// Add filters to TWIG configurtion
|
|
7
|
+
config.twig = config.twig || {};
|
|
8
|
+
config.twig.filters = config.twig.filters || [];
|
|
9
|
+
config.twig.filters = config.twig.filters.concat(filters);
|
|
10
|
+
|
|
11
|
+
return config;
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|