fix: gulpfile.js twig functions gulp dist
1 parent 791d2fb commit 8c7830eb9f114d368f2b188df2e823b1c409a39a
@EcosistemaWebIuav EcosistemaWebIuav authored on 17 Jan 2024
Showing 1 changed file
View
274
gulpfile.js
});
}
},
{
name: "startswith",
func: function (string, match) {
return string.startsWith(match);
}
},
{
name: "hasitemwith",
func: function (obj, match) {
let indexHasItem = false;
obj.forEach(i => {
if (i['title'].startsWith(match)){
indexHasItem = true;
}
})
if (indexHasItem) {
return true;
}
}
},
{
name: "lastwordstartswith",
func: function (string, match) {
string = string.split(' ')
string = string[string.length - 1]
return string.startsWith(match);
}
},
{
name: "lastwordhasitemwith",
func: function (obj, match) {
let indexHasItem = false;
obj.forEach(i => {
let string = i['title']
string = string.split(' ')
string = string[string.length - 1]
if (string.startsWith(match)){
indexHasItem = true;
}
})
if (indexHasItem) {
return true;
}
}
}
]
}))
.pipe(prettyHtml())
.pipe(gulp.dest(options.paths.build.base));
}
exports.twig_root = twig_root;
 
function twig_pages(){
return gulp.src(`${options.paths.src.base}/pages/**/*.twig`)
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./data.json'));
}))
.pipe(twig({
filters: [
{
name: "sortby",
func: function (obj, key) {
return obj.sort(function(a,b){
var a = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key];
var b = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key];
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
}
},
{
name: "sortbylast",
func: function (obj, key) {
return obj.sort(function(a,b){
var a, b;
}
]
}))
.pipe(prettyHtml())
.pipe(gulp.dest(`${options.paths.build.base}/pages`));
}
exports.twig_pages = twig_pages;
 
const twig_build = series(twig_root, twig_pages);
exports.twig_build = twig_build;
 
function twig_root_prettify(){
return gulp.src(`${options.paths.src.base}/*.twig`)
.pipe(gulp.dest(options.paths.build.base));
}
exports.twig_root = twig_root;
 
function twig_pages(){
return gulp.src(`${options.paths.src.base}/pages/**/*.twig`)
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./data.json'));
}))
.pipe(twig({
func: function (obj, key) {
return obj.sort(function(a,b){
var a = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key];
var b = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key];
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
}
},
{
name: "sortbylast",
func: function (obj, key) {
return obj.sort(function(a,b){
var a, b;
if (typeof a[key] === 'string') {
a = a[key].split(' ');
a = a[a.length - 1];
a.toUpperCase();
} else {
a[key];
}
if (typeof b[key] === 'string') {
b = b[key].split(' ');
b = b[b.length - 1];
b.toUpperCase();
} else {
b[key];
}
if (a < b) {
return -1;
}
if (a > b) {
}
}
}
]
}))
}))
.pipe(prettyHtml())
.pipe(processhtml())
.pipe(gulp.dest(options.paths.dist.base));
}
function twig_pages_prettify(){
return gulp.src(`${options.paths.src.base}/pages/**/*.twig`)
.pipe(gulp.dest(`${options.paths.build.base}/pages`));
}
exports.twig_pages = twig_pages;
 
const twig_build = series(twig_root, twig_pages);
exports.twig_build = twig_build;
 
function twig_root_prettify(){
return gulp.src(`${options.paths.src.base}/*.twig`)
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./data.json'));
}))
.pipe(twig({
func: function (obj, key) {
return obj.sort(function(a,b){
var a = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key];
var b = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key];
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
}
},
{
name: "sortbylast",
func: function (obj, key) {
return obj.sort(function(a,b){
var a, b;
if (typeof a[key] === 'string') {
a = a[key].split(' ');
a = a[a.length - 1];
a.toUpperCase();
} else {
a[key];
}
if (typeof b[key] === 'string') {
b = b[key].split(' ');
b = b[b.length - 1];
b.toUpperCase();
} else {
b[key];
}
if (a < b) {
return -1;
}
if (a > b) {
}
}
}
]
}))
.pipe(prettyHtml())
.pipe(processhtml())
.pipe(gulp.dest(options.paths.dist.base));
}
function twig_pages_prettify(){
return gulp.src(`${options.paths.src.base}/pages/**/*.twig`)
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./data.json'));
}))
.pipe(twig({
filters: [
{
name: "sortby",
func: function (obj, key) {
return obj.sort(function(a,b){
var a = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key];
var b = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key];
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
}
},
{
name: "sortbylast",
func: function (obj, key) {
return obj.sort(function(a,b){
var a, b;
if (typeof a[key] === 'string') {
a = a[key].split(' ');
a = a[a.length - 1];
a.toUpperCase();
} else {
a[key];
}
if (typeof b[key] === 'string') {
b = b[key].split(' ');
b = b[b.length - 1];
b.toUpperCase();
} else {
b[key];
}
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
}
},
{
name: "startswith",
func: function (string, match) {
return string.startsWith(match);
}
},
{
name: "hasitemwith",
func: function (obj, match) {
let indexHasItem = false;
obj.forEach(i => {
if (i['title'].startsWith(match)){
indexHasItem = true;
}
})
if (indexHasItem) {
return true;
}
}
},
{
name: "lastwordstartswith",
func: function (string, match) {
string = string.split(' ')
string = string[string.length - 1]
return string.startsWith(match);
}
},
{
name: "lastwordhasitemwith",
func: function (obj, match) {
let indexHasItem = false;
obj.forEach(i => {
let string = i['title']
string = string.split(' ')
string = string[string.length - 1]
if (string.startsWith(match)){
indexHasItem = true;
}
})
if (indexHasItem) {
return true;
}
}
}
]
}))
.pipe(prettyHtml())
.pipe(processhtml())
.pipe(gulp.dest(`${options.paths.dist.base}/pages`));