-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
156 lines (124 loc) · 3.77 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const MODE_DEVELOPMENT = 'dev';
const eleventyNavigationPlugin = require('@11ty/eleventy-navigation');
const htmlmin = require('html-minifier');
const now = new Date();
const {MODE: mode} = process.env;
const publishedPosts = (post) => {
if (mode === MODE_DEVELOPMENT) return true;
return post.date <= now && !post.data.draft;
};
const capitalize = str => {
const parts = str.split('');
parts[0] = parts[0].toUpperCase();
return parts.join('');
}
function getLocaleDate(date) {
return date.toLocaleString('es-ES', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
}
module.exports = function (config) {
config.addPassthroughCopy({'_src/assets/_domain/cname.txt': '/CNAME'});
config.addPassthroughCopy({'_src/assets/_icon/favicon.ico': '/favicon.ico'});
config.addPassthroughCopy('_src/blog/**/img/*.{png,svg,jpg,webp}');
config.addPassthroughCopy('_src/assets/fonts');
config.addPassthroughCopy('_src/assets/css');
config.addPassthroughCopy('_src/assets/images');
config.addPassthroughCopy('_src/assets/js');
config.addPassthroughCopy({'_src/assets/feed': '/feed'});
config.addPlugin(eleventyNavigationPlugin);
config.addTransform('htmlmin', function (content, outputPath) {
if (outputPath.endsWith('.html')) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
preserveLineBreaks: false,
caseSensitive: true
});
}
if (outputPath.endsWith('.xml')) {
const regex = /(max-width:[0-9]{1,}(px|%)*;)/g;
const undangeredContent = content.replace(regex, '');
return undangeredContent;
}
return content;
});
config.addCollection('blog', collection => {
return collection
.getFilteredByGlob('_src/blog/**/index.md')
.filter(publishedPosts);
});
config.addNunjucksFilter('hashtag', function(str) {
const tag = str
.toLowerCase()
.trim()
.normalize("NFD")
.replace(/\p{Diacritic}/gu, '')
.replace(/[¿?!¡\.,-]/g, '')
.replace(/ +/g, ' ')
.split(' ')
.map(word => capitalize(word))
.join('');
return `#${tag} #SiDiosTeDaLimones`;
});
config.addNunjucksFilter('spanMe', function(str) {
return str.split(' ')
.map(word => `<span class="post__title-mark-item">${word}</span>`)
.join(' ');
});
config.addNunjucksFilter('isFuture', function(date) {
const postDate = new Date(date);
const now = new Date();
return postDate > now ? 'home-post--future': '';
});
config.addNunjucksFilter('filterByYear', function(collection, year) {
return collection
.filter(post => {
return year === post.data.date.getFullYear();
});
});
config.addNunjucksFilter('datetime', function(date) {
return getLocaleDate(date)
.split('/')
.reverse()
.join('-');;
});
config.addNunjucksFilter('formatDate', function(date) {
return getLocaleDate(date);
});
config.addNunjucksFilter('convertToAbsoluteURL', function(post, postURL) {
const targetStr = 'src="./img';
const resultStr = `src="https://sidiostedalimones.com${postURL}img`;
const content = post.replaceAll(targetStr, resultStr);
return content;
});
config.addNunjucksFilter('rfc822Inator', function(strDate) {
return new Date(strDate).toUTCString();
});
config.addNunjucksFilter('getWordGender', function(str) {
const strAbbr = str.toUpperCase();
const GENDER = {
M: 'Nombre masculino',
H: 'Nombre femenino'
};
if (!GENDER[strAbbr]) return '';
return `<abbr title="${GENDER[strAbbr]}">${ str }.</abbr> `;
});
config.addNunjucksFilter('getWordSynonyms', function(list) {
return `<abbr title="Sinónmimo o afín">Sin.</abbr>: ${list.join(', ')}.`;
});
return {
dir: {
input: '_src',
output: 'dist',
includes: '_templates',
data: '_data',
},
templateFormats: ['njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
}
}