From 6a59d5a97cbabd3ac514817cb598a1aa58d1526e Mon Sep 17 00:00:00 2001 From: Luca Zeuch Date: Wed, 1 Jan 2025 11:43:59 +0100 Subject: [PATCH 1/2] frontend: add selfhosting view toggle Preliminary commit to cater some feedback about its design and underlying JS code; will implement actual content modification later. Signed-off-by: Luca Zeuch --- assets/js/custom.js | 21 +++++++++++++++++++++ assets/scss/common/_custom.scss | 22 ++++++++++++++++++++++ config/postcss.config.js | 1 + layouts/partials/header/header.html | 18 ++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/assets/js/custom.js b/assets/js/custom.js index b1746116..58db3539 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -1 +1,22 @@ // Put your custom JS code here + +// self-hosting view. +const getSelfhost = () => { + return localStorage.getItem('selfhost') || 'no'; +}; + +const setSelfhost = (selfhost) => { + localStorage.setItem('selfhost', selfhost); + document.documentElement.setAttribute('data-selfhost', selfhost); +}; + +setSelfhost(getSelfhost()); + +window.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('[data-selfhost-value]').forEach((element) => { + element.addEventListener('click', (event) => { + const selfhost = element.getAttribute('data-selfhost-value'); + setSelfhost(selfhost); + }); + } +)}); diff --git a/assets/scss/common/_custom.scss b/assets/scss/common/_custom.scss index d5ae54de..028588a3 100644 --- a/assets/scss/common/_custom.scss +++ b/assets/scss/common/_custom.scss @@ -147,6 +147,28 @@ pre.shiki { opacity: var(--ec-frm-inlBtnBgActOpa); } +// show active server if self-hosting view enabled +html[data-selfhost="yes"] { + .icon-tabler-server { + display: block; + } + + .icon-tabler-server-off { + display: none; + } +} + +// hide active server if self-hosting view disabled +html[data-selfhost="no"] { + .icon-tabler-server { + display: none; + } + + .icon-tabler-server-off { + display: block; + } +} + @media (hover: hover) { .highlight .copy button { opacity: 0; diff --git a/config/postcss.config.js b/config/postcss.config.js index 1bbd8ec9..3b1e9817 100644 --- a/config/postcss.config.js +++ b/config/postcss.config.js @@ -26,6 +26,7 @@ module.exports = { 'data-global-alert', 'data-pane', // tabs.js 'data-popper-placement', + 'data-selfhost', 'data-sizes', 'data-toggle-tab', // tabs.js 'id', diff --git a/layouts/partials/header/header.html b/layouts/partials/header/header.html index 6847d2be..ae88e56c 100644 --- a/layouts/partials/header/header.html +++ b/layouts/partials/header/header.html @@ -272,6 +272,24 @@
{{ .Site.Params.T {{ end -}} + + {{ if site.Params.doks.navBarButton -}} From a9d764c603cc0dc465222fabddeba709d2148a5f Mon Sep 17 00:00:00 2001 From: Luca Zeuch Date: Wed, 1 Jan 2025 12:45:07 +0100 Subject: [PATCH 2/2] layouts: add selfhosting shortcode and start using it Signed-off-by: Luca Zeuch --- assets/scss/common/_custom.scss | 4 ++++ content/docs/moderation/logging.md | 8 ++++++-- content/docs/moderation/verification.md | 4 ++++ content/docs/welcome/premium.md | 4 ++++ layouts/shortcodes/selfhosting.html | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 layouts/shortcodes/selfhosting.html diff --git a/assets/scss/common/_custom.scss b/assets/scss/common/_custom.scss index 028588a3..cfee50ef 100644 --- a/assets/scss/common/_custom.scss +++ b/assets/scss/common/_custom.scss @@ -167,6 +167,10 @@ html[data-selfhost="no"] { .icon-tabler-server-off { display: block; } + + .selfhosting { + display: none; + } } @media (hover: hover) { diff --git a/content/docs/moderation/logging.md b/content/docs/moderation/logging.md index a5d2176f..7496f670 100644 --- a/content/docs/moderation/logging.md +++ b/content/docs/moderation/logging.md @@ -28,7 +28,7 @@ contains an embed, it is serialized and saved in JSON format. Message logs on the official YAGPDB instance will be automatically deleted after 30 days of their creation. -If you're self-hosting, see [Message Log Purge](#message-log-purge-self-hosting-only) for more information. +If you're self-hosting, see [Message Log Purge](#message-log-purge) for more information. {{< /callout >}} @@ -114,8 +114,12 @@ channels. Users with write access to the control panel may delete individual logs or delete all logs on the server using the control panel. -## Message Log Purge [Self-hosting only] +{{< selfhosting >}} + +## Message Log Purge If you are self-hosting your own instance of YAGPDB, you can set `enable_message_log_purge=true` to automatically purge message logs older than 30 days. This option is enabled on the official instance of YAGPDB hosted by Botlabs but is disabled by default on a fresh self-host. + +{{< /selfhosting >}} diff --git a/content/docs/moderation/verification.md b/content/docs/moderation/verification.md index b4c28249..08814c8e 100644 --- a/content/docs/moderation/verification.md +++ b/content/docs/moderation/verification.md @@ -97,6 +97,8 @@ If a new user who verifies is detected as an alt but none of their associated ac send a log to the verification log channel if specified, identifying the new user as an alt and listing other users who verified at the same IP address. +{{< selfhosting >}} + ### Disable Alt Detection Globally For self hosters, the environment variable to enable this feature is `verification.track_ips`. It is `true` by default. @@ -112,3 +114,5 @@ Do not proceed unless you are hosting your own version of the YAGPDB codebase. Verification requires the `google.recaptcha_secret` and `google.recaptcha_site_key` env variables to be configured and valid. To get a reCAPTCHA secret and site key, [register a site on reCAPTCHA](https://www.google.com/recaptcha/admin/create) and copy the generated secret and key. + +{{< /selfhosting >}} diff --git a/content/docs/welcome/premium.md b/content/docs/welcome/premium.md index 957d9fc7..06bf8c21 100644 --- a/content/docs/welcome/premium.md +++ b/content/docs/welcome/premium.md @@ -127,6 +127,8 @@ You can assign your premium slots to any server with YAGPDB in it and no existin ![Redeemed Premium Slots](slots_premium.png) +{{< selfhosting >}} + ## Self Hosting YAGPDB Do not proceed unless you are hosting your own version of the YAGPDB codebase. @@ -153,3 +155,5 @@ recommended you familiarize yourself with the codebase before making changes. Fi defined and alter their values as you wish. ![Example of limit definitions in Advanced Automoderator](limits_example.png) + +{{< /selfhosting >}} diff --git a/layouts/shortcodes/selfhosting.html b/layouts/shortcodes/selfhosting.html new file mode 100644 index 00000000..c8b81615 --- /dev/null +++ b/layouts/shortcodes/selfhosting.html @@ -0,0 +1,4 @@ +{{/* wraps the inner content in a div with a class of "selfhosting", such that it can be conditionally hidden by some JS code. */}} +
+ {{ .Inner | $.Page.RenderString }} +