[feature] User-selectable preset CSS themes for accounts (#2777)

* [feature] User-selectable preset themes

* docs, more theme stuff

* lint, tests

* fix css name

* correct some little issues

* add another theme

* fix poll background

* okay last theme i swear

* make retrieval of apimodel themes more conventional

* preallocate stylesheet slices
This commit is contained in:
tobi 2024-03-25 18:32:24 +01:00 committed by GitHub
commit 8953f57d88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 1230 additions and 28 deletions

30
docs/admin/themes.md Normal file
View file

@ -0,0 +1,30 @@
# Themes
Users on your instance can select a theme for their profile from any css files present in the `web/assets/themes` directory.
GoToSocial comes with some theme files already, but you can add more yourself by doing the following:
1. Create a file in `web/assets/themes` called (for example) `new-theme.css`.
2. (Optional) Include the following comment at the top of your theme file to title and describe your theme:
```css
/*
theme-title: My New Theme
theme-description: This is an example theme
*/
```
You can use any text you like for these fields, but bear in mind whatever you write here will appear in the settings panel to help users when selecting a theme, so keep it short and sweet.
3. Fill out your custom CSS in the rest of the file. You can use one of the existing CSS files to guide you. Also see [this page](../user_guide/custom_css.md) for some rough guidelines about how to write accessible CSS.
4. Restart your instance so that the new CSS file is picked up.
!!! info
If you're using Docker for your deployment, you can mount theme files from the host machine into your GoToSocial `web/assets/themes` directory instead, by including entries for them in the `volumes` section of your Docker configuration.
For example, say you've created a theme on your host machine at `~/gotosocial/my-themes/new-theme.css`, you could mount that theme into the GoToSocial Docker container in the following way:
```yaml
volumes:
[.... some other volume entries ...]
- "~/gotosocial/my-themes/new-theme.css:/gotosocial/web/assets/themes/new-theme.css"
```
Bear in mind if you mount an entire directory to `/gotosocial/web/assets/themes` instead of mounting individual theme files, you'll override the default themes.

View file

@ -294,6 +294,10 @@ definitions:
description: Account has been suspended by our instance.
type: boolean
x-go-name: Suspended
theme:
description: Filename of user-selected CSS theme to include when rendering this account's profile or statuses. Eg., `blurple-light.css`.
type: string
x-go-name: Theme
url:
description: Web location of the account's profile page.
example: https://example.org/@some_user
@ -2463,6 +2467,24 @@ definitions:
type: object
x-go-name: Tag
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
theme:
properties:
description:
description: User-facing description of this theme.
type: string
x-go-name: Description
file_name:
description: FileName of this theme in the themes directory.
type: string
x-go-name: FileName
title:
description: User-facing title of this theme.
type: string
x-go-name: Title
title: Theme represents one user-selectable preset CSS theme.
type: object
x-go-name: Theme
x-go-package: github.com/superseriousbusiness/gotosocial/internal/api/model
wellKnownResponse:
description: See https://webfinger.net/
properties:
@ -3448,6 +3470,34 @@ paths:
summary: Search for accounts by username and/or display name.
tags:
- accounts
/api/v1/accounts/themes:
get:
operationId: accountThemes
produces:
- application/json
responses:
"200":
description: Array of themes.
schema:
items:
$ref: '#/definitions/theme'
type: array
"400":
description: bad request
"401":
description: unauthorized
"404":
description: not found
"406":
description: not acceptable
"500":
description: internal server error
security:
- OAuth2 Bearer:
- read:accounts
summary: See preset CSS themes available to accounts on this instance.
tags:
- accounts
/api/v1/accounts/update_credentials:
patch:
consumes:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Before After
Before After

View file

@ -22,6 +22,15 @@ A preview of the image as it will appear on your profile will be shown. If you'r
If you navigate to your profile and refresh the page, your new avatar / header will be shown. It might take a bit longer for the update to federate out to remote instances.
### Select Theme
GoToSocial provides themes for you to choose from for the web view of your profile, to change your profile's appearance and vibe.
To choose a theme, just select it from the profile settings page, and click/tap "Save profile info" at the bottom of the page. When you look at your profile in the web view (you may need to refresh the page), you'll see the new theme applied, and so will anyone else visiting your profile.
!!! tip "Adding more themes"
Instance admins can add more themes by dropping css files into the `web/assets/themes` folder. See the [themes](../admin/themes.md) part of the admin docs for more information.
### Basic Information
#### Display Name
@ -109,9 +118,14 @@ Turning on the discoverable flag may take a week or more to propagate; your acco
#### Custom CSS
If enabled on your instance by the instance administrator, [Custom CSS](./custom_css.md) allows you to theme the way your profile looks when visited through a browser.
If enabled on your instance by the instance administrator, custom CSS allows you to further customize the way your profile looks when visited through a browser.
When this setting is not enabled by the instance administrator, the text input box is read-only.
When this setting is not enabled by the instance administrator, the text input box is read-only and custom CSS will not be applied.
See the [Custom CSS](./custom_css.md) page for some tips on writing custom CSS for your profile.
!!! tip
Any custom CSS you add in this box will be applied *after* your selected theme, so you can pick a preset theme that you like and then make your own tweaks!
## Post Settings