1
0
Fork 0
mirror of https://github.com/GuerillaStudio/vanillalist.git synced 2024-10-22 17:37:29 +00:00
vanillalist/.eleventy.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-02-21 15:52:38 +00:00
const glob = require("glob-promise")
2022-02-10 20:07:25 +00:00
const fs = require("fs/promises")
2021-02-21 15:52:38 +00:00
const { URL } = require("url")
const sharpPlugin = require("eleventy-plugin-sharp")
2022-06-04 19:15:09 +00:00
const pluginRss = require("@11ty/eleventy-plugin-rss");
2021-02-21 15:52:38 +00:00
module.exports = function (eleventyConfig) {
2022-06-04 19:15:09 +00:00
eleventyConfig.addGlobalData('generated', () => {
let now = new Date();
return new Intl.DateTimeFormat(
'en-US', { dateStyle: 'full', timeStyle: 'long' }
).format(now);
});
2021-02-21 15:52:38 +00:00
eleventyConfig.setBrowserSyncConfig({ port: 1312 })
eleventyConfig.addPlugin(sharpPlugin(
{
urlPath: '/uploads',
outputDir: 'public/uploads'
}
))
eleventyConfig.addCollection('plugins', async () => {
const files = (await glob('plugins/*.json')).map(filename => {
2022-02-10 20:07:25 +00:00
return fs.readFile(filename, { encoding: 'utf-8' })
2021-02-21 15:52:38 +00:00
})
const plugins = await Promise.all(files)
2022-01-03 14:04:54 +00:00
return plugins.map(JSON.parse).sort((a, b) => b.id - a.id)
2021-02-21 15:52:38 +00:00
});
eleventyConfig.addFilter('JSONstringify', (value) => {
return JSON.stringify(value)
})
eleventyConfig.addFilter("absoluteUrl", (url, base) => {
try { return new URL(url, base).toString() } catch (e) {
console.error(`Trying to convert ${url} to be an absolute url with base ${base} and failed, returning: ${url} (invalid url)`);
return url;
}
});
2022-02-10 20:07:25 +00:00
eleventyConfig.addFilter("base64", async (url) => {
return fs.readFile(url, 'base64')
});
2021-02-21 15:52:38 +00:00
eleventyConfig.addShortcode("titleGenerator", (title, site, pageUrl, pagination) => {
2021-03-01 03:02:37 +00:00
let endTitle = `${site.name}${site.description}`
2021-02-21 15:52:38 +00:00
let paginationSuffix = (pagination && pagination.pageNumber) ? ` (page ${pagination.pageNumber + 1})` : ''
if (title) { endTitle = `${title}${site.name}` }
if (pageUrl === '/') { endTitle = `${site.name}${site.description}` }
return endTitle + paginationSuffix
});
eleventyConfig.addPassthroughCopy({ "./src/static/": "/"})
eleventyConfig.addWatchTarget("./src/sass/")
eleventyConfig.addWatchTarget("./src/static/")
2022-06-04 19:15:09 +00:00
// RSS
eleventyConfig.addPlugin(pluginRss);
2021-02-21 15:52:38 +00:00
return {
dir: {
input: "src",
output: "public",
},
};
};