From afb7827f4021fbe4516d29e87087cd242301a62b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 3 Mar 2022 23:05:37 -0600 Subject: [PATCH] Allow features overrides, document `custom/` directory --- app/soapbox/utils/features.js | 17 ++++++++++++-- docs/development/build-config.md | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index 0516ef02d..917653a3a 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -4,6 +4,19 @@ import { createSelector } from 'reselect'; import gte from 'semver/functions/gte'; import lt from 'semver/functions/lt'; +// FIXME: We have to use a dynamic import to trick Webpack into treating it as +// optional, but this causes custom locales to become part of the main chunk. +const importCustom = path => { + try { + return require(`custom/${path}.json`); + } catch(e) { + return {}; + } +}; + +// Import custom overrides, if exists +const overrides = importCustom('features'); + const any = arr => arr.some(Boolean); // For uglification @@ -16,7 +29,7 @@ export const getFeatures = createSelector([instance => instance], instance => { const features = instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()); const federation = instance.getIn(['pleroma', 'metadata', 'federation'], ImmutableMap()); - return { + return Object.assign({ bookmarks: any([ v.software === MASTODON && gte(v.compatVersion, '3.1.0'), v.software === PLEROMA && gte(v.version, '0.9.9'), @@ -93,7 +106,7 @@ export const getFeatures = createSelector([instance => instance], instance => { v.software === MASTODON && gte(v.compatVersion, '3.2.0'), v.software === PLEROMA && gte(v.version, '2.4.50'), ]), - }; + }, overrides); }); export const parseVersion = version => { diff --git a/docs/development/build-config.md b/docs/development/build-config.md index e5083b8a0..a5f9a741b 100644 --- a/docs/development/build-config.md +++ b/docs/development/build-config.md @@ -1,5 +1,45 @@ # Build Configuration +Soapbox supports compile-time customizations in the form of environment variables and a gitignored `custom/` directory. + +## `custom/` directory + +You can place files into the `custom/` directory to customize the Soapbox build. + +### Custom locales (`custom/locales/*.json`) + +It is possible to override locale messages by creating a file for each language, eg `custom/locales/en.json`. +In this file, add only the messages you want to be overridden. +For example: + +```json +{ + "account.posts": "Poasts", + "account.posts_with_replies": "Poasts & Replies", + "compose.submit_success": "Your poast was sent!", + "compose_form.publish": "Poast" +} +``` + +These messages will be merged into the language file shipped with Soapbox. + +### Feature overrides (`custom/features.json`) + +You can create a file called `custom/features.json` to disable version-checking and force some features on or off. +For example: + +```json +{ + "bookmarks": false, + "lists": false, + "quotePosts": true +} +``` + +See `app/soapbox/utils/features.js` for the full list of features. + +## Environment variables + When compiling Soapbox FE, environment variables may be passed to change the build itself. For example: