X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/c5cbbd3835ccd509179504cdf7d5e74356d7dca5..0307770b088afcc207bc5d84c63f8b681db0aebf:/config/config.js?ds=inline diff --git a/config/config.js b/config/config.js index 5a1f793..cf2a386 100644 --- a/config/config.js +++ b/config/config.js @@ -1,10 +1,48 @@ -'use strict'; +import { fileURLToPath } from 'url'; +import { join, resolve, dirname } from 'path'; +import Getenv from 'getenv'; -const Path = require('path'); -const Getenv = require('getenv'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const internals = { - blogDirectory: Getenv('BLOG_DIRECTORY', Path.resolve(Path.join(__dirname, '../.blog'))), + // We'll use this to store configuration, such as the remote config, + // templates, and the static directory. + configDirectory: Getenv('BLOG_CONFIG_DIRECTORY', + resolve( + join( + Getenv( + 'XDG_CONFIG_HOME', + join(Getenv('HOME'), '.config') + ), + 'blog' + ) + ) + ), + // We'll use this to store the actual blog contents. + dataDirectory: Getenv('BLOG_DATA_DIRECTORY', + resolve( + join( + Getenv( + 'XDG_DATA_HOME', + join(Getenv('HOME'), '.local/share') + ), + 'blog' + ) + ) + ), + // We'll use this to store the actual blog contents. + outputDirectory: Getenv('BLOG_OUTPUT_DIRECTORY', + resolve( + join( + Getenv( + 'XDG_CACHE_HOME', + join(Getenv('HOME'), '.cache') + ), + 'blog' + ) + ) + ) }; /** @@ -16,21 +54,44 @@ const internals = { * @typedef {object} tConfiguration * @property {number} maxPosts=3 the max number of posts that can exist * at one time - * @property {string} postsDirectory=/.posts the location of + * @property {string} configDirectory=$XDG_CONFIG_HOME/blog the location of + * the configuration files. + * @property {string} dataDirectory=$XDG_DATA_HOME/blog the location of + * the blog data. + * @property {string} outputDirectory=$XDG_CACHE_HOME/blog the location of + * the generated blog files. + * @property {string} postsDirectory=$XDG_DATA_HOME/blog/posts the location of * the directory where the posts will be stored. - * @property {string} staticDirectory=/static the location of + * @property {string} archiveDirectory=$XDG_DATA_HOME/blog/archive the location of + * the directory where the archive will be stored. + * @property {string} staticDirectory=$XDG_DATA_HOME/blog/static the location of * the directory where the generated files will be placed. NOTE: There * are some pre-built style files in the default directory, if you * select another one, make sure you include them manually. - * @property {string} templatesDirectory=/templates the + * @property {string} templatesDirectory=$XDG_CONFIG_HOME/blog/templates the + * location of the templates we'll use to generate the index.html, feed.xml, + * and index.txt. + * @property {string} remoteConfig=$XDG_CONFIG_HOME/blog/blogremotee the * location of the templates we'll use to generate the index.html */ -module.exports = internals.Config = { +export default { + // XDG_CONFIG_HOME and XDG_DATA_HOME defaults. + configDirectory: internals.configDirectory, + dataDirectory: internals.dataDirectory, + outputDirectory: internals.outputDirectory, + + // User configuration, changeable with BLOG_ env variables. maxPosts: Getenv.int('BLOG_MAX_POSTS', 3), - blogDirectory: internals.blogDirectory, - postsDirectory: Getenv('BLOG_POSTS_DIRECTORY', Path.resolve(Path.join(internals.blogDirectory, 'posts'))), - archiveDirectory: Getenv('BLOG_ARCHIVE_DIRECTORY', Path.resolve(Path.join(internals.blogDirectory, 'archive'))), - staticDirectory: Getenv('BLOG_STATIC_DIRECTORY', Path.resolve(Path.join(__dirname, '../static'))), - templatesDirectory: Getenv('BLOG_TEMPLATES_DIRECTORY', Path.resolve(Path.join(__dirname, '../templates'))), - remoteConfig: Getenv('BLOG_REMOTE_CONFIG', Path.resolve(Path.join(__dirname, '../.blogremote'))), + postsDirectory: resolve(join(internals.dataDirectory, 'posts')), + archiveDirectory: resolve(join(internals.dataDirectory, 'archive')), + staticDirectory: resolve(join(internals.dataDirectory, 'static')), + templatesDirectory: resolve(join(internals.dataDirectory, 'templates')), + + remoteConfig: resolve(join(internals.configDirectory, 'blogremote')), + + blogOutputDirectory: resolve(join(internals.outputDirectory, 'blog')), + archiveOutputDirectory: resolve(join(internals.outputDirectory, 'archive')), + + // Internal config: This can't be modified. + defaultTemplatesDirectory: resolve(join(__dirname, '../templates')) };