-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
132 lines (118 loc) · 3.57 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
require('dotenv').config()
const markdownIt = require('markdown-it')
const { EleventyI18nPlugin } = require('@11ty/eleventy')
const { DateTime } = require('luxon')
const htmlmin = require('html-minifier')
const faviconPlugin = require('eleventy-favicon')
const eleventySass = require('eleventy-sass')
const i18n = require('eleventy-plugin-i18n')
const mdReplaceLink = require('markdown-it-replace-link')
const translations = require('./src/_data/i18n')
const md = new markdownIt({
html: true,
})
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: 'en',
})
eleventyConfig.addPlugin(i18n, {
translations,
fallbackLocales: {
'*': 'en',
},
})
eleventyConfig.addPlugin(eleventySass)
eleventyConfig.addWatchTarget('./src/sass/')
eleventyConfig.addPlugin(faviconPlugin, { destination: './public' })
eleventyConfig.addPassthroughCopy('./src/assets/js')
eleventyConfig.addPassthroughCopy('./src/assets/images')
eleventyConfig.addPassthroughCopy('./src/_redirects')
eleventyConfig.addPassthroughCopy({
'./_original': 'original',
})
eleventyConfig.addPassthroughCopy('./src/manifest.json')
eleventyConfig.addPassthroughCopy('./src/robots.txt')
eleventyConfig.addPassthroughCopy({
'./node_modules/leaflet/dist': 'assets/js/leaflet',
})
eleventyConfig.addGlobalData(
'isProduction',
process.env.NODE_ENV && process.env.NODE_ENV === 'production'
)
eleventyConfig.amendLibrary('md', (mdLib) =>
mdLib.use(mdReplaceLink, {
replaceLink: (link, env) => {
if (['/en', '/es'].includes(link)) {
return link
}
if (link.startsWith('/')) {
return `/${env.page.lang}${link}`
}
return link
},
})
)
if (process.env.NODE_ENV && process.env.NODE_ENV === 'production') {
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
if (outputPath && outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
})
return minified
}
return content
})
}
eleventyConfig.addFilter('markdown', (content) => {
return md.render(content)
})
eleventyConfig.addFilter('json', (content) => {
return JSON.stringify(content)
})
eleventyConfig.addFilter('switchUrlLanguage', (url) => {
if (url.includes('/en/')) {
return url.replace('/en/', '/es/')
}
return url.replace('/es/', '/en/')
})
eleventyConfig.addFilter('accessPointsJson', ({ points, geo, lang }) => {
return JSON.stringify(
points
.filter((point) => point.page.lang === lang)
.map((point) => ({
title: point.data.title,
lat: geo[point.fileSlug].lat,
lon: geo[point.fileSlug].lon,
url: `/access-points/${point.fileSlug}`,
}))
)
})
eleventyConfig.addFilter('tripsJson', ({ trips, geo, lang }) => {
return JSON.stringify(
trips
.filter((trip) => trip.page.lang === lang)
.map((trip) => ({
title: trip.data.title,
lat: geo[trip.fileSlug].lat,
lon: geo[trip.fileSlug].lon,
length: trip.data.length,
url: `/trips/${trip.fileSlug}`,
}))
)
})
eleventyConfig.addShortcode(
'buildDate',
() =>
`${DateTime.now().toLocaleString(DateTime.DATE_FULL)} at ${DateTime.now()
.toLocaleString(DateTime.TIME_SIMPLE)
.toLowerCase()}`
)
return {
dir: {
input: 'src',
output: 'public',
},
}
}