-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] User-selectable preset CSS themes for accounts #2777
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
13b4e19
[feature] User-selectable preset themes
tsmethurst dbba95f
docs, more theme stuff
tsmethurst da12f8f
lint, tests
tsmethurst 7f41444
fix css name
tsmethurst 0225550
correct some little issues
tsmethurst 254842f
add another theme
tsmethurst c80e2d9
fix poll background
tsmethurst 42ababa
okay last theme i swear
tsmethurst 54d53a1
make retrieval of apimodel themes more conventional
tsmethurst aca9863
preallocate stylesheet slices
tsmethurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// GoToSocial | ||
// Copyright (C) GoToSocial Authors admin@gotosocial.org | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package accounts | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | ||
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" | ||
"github.com/superseriousbusiness/gotosocial/internal/gtserror" | ||
"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||
) | ||
|
||
// AccountThemesGETHandler swagger:operation GET /api/v1/accounts/themes accountThemes | ||
// | ||
// See preset CSS themes available to accounts on this instance. | ||
// | ||
// --- | ||
// tags: | ||
// - accounts | ||
// | ||
// produces: | ||
// - application/json | ||
// | ||
// security: | ||
// - OAuth2 Bearer: | ||
// - read:accounts | ||
// | ||
// responses: | ||
// '200': | ||
// name: statuses | ||
// description: Array of themes. | ||
// schema: | ||
// type: array | ||
// items: | ||
// "$ref": "#/definitions/theme" | ||
// '400': | ||
// description: bad request | ||
// '401': | ||
// description: unauthorized | ||
// '404': | ||
// description: not found | ||
// '406': | ||
// description: not acceptable | ||
// '500': | ||
// description: internal server error | ||
func (m *Module) AccountThemesGETHandler(c *gin.Context) { | ||
_, err := oauth.Authed(c, true, true, true, true) | ||
if err != nil { | ||
apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) | ||
return | ||
} | ||
|
||
if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { | ||
apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) | ||
return | ||
} | ||
|
||
// Retrieve available themes. | ||
gtsThemes := m.processor.Account().ThemesGet() | ||
|
||
// Convert themes to apimodel. | ||
themes := make([]apimodel.Theme, len(gtsThemes.SortedByTitle)) | ||
for i, gtsTheme := range gtsThemes.SortedByTitle { | ||
themes[i] = apimodel.Theme{ | ||
Title: gtsTheme.Title, | ||
Description: gtsTheme.Description, | ||
FileName: gtsTheme.FileName, | ||
} | ||
} | ||
|
||
apiutil.JSON(c, http.StatusOK, themes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// GoToSocial | ||
// Copyright (C) GoToSocial Authors admin@gotosocial.org | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package model | ||
|
||
// Theme represents one user-selectable preset CSS theme. | ||
// | ||
// swagger:model theme | ||
type Theme struct { | ||
// User-facing title of this theme. | ||
Title string `json:"title"` | ||
|
||
// User-facing description of this theme. | ||
Description string `json:"description"` | ||
|
||
// FileName of this theme in the themes directory. | ||
FileName string `json:"file_name"` | ||
} |
55 changes: 55 additions & 0 deletions
55
internal/db/bundb/migrations/20240320114447_preset_css_themes.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// GoToSocial | ||
// Copyright (C) GoToSocial Authors admin@gotosocial.org | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package migrations | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/uptrace/bun" | ||
) | ||
|
||
func init() { | ||
up := func(ctx context.Context, db *bun.DB) error { | ||
// Add theme to account settings table. | ||
_, err := db.ExecContext(ctx, | ||
"ALTER TABLE ? ADD COLUMN ? TEXT", | ||
bun.Ident("account_settings"), bun.Ident("theme"), | ||
) | ||
if err != nil { | ||
e := err.Error() | ||
if !(strings.Contains(e, "already exists") || | ||
strings.Contains(e, "duplicate column name") || | ||
strings.Contains(e, "SQLSTATE 42701")) { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
down := func(ctx context.Context, db *bun.DB) error { | ||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | ||
return nil | ||
}) | ||
} | ||
|
||
if err := Migrations.Register(up, down); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's probably worth moving this to the typeconverter package just for conformity. though probably not something that needs to be a method receiver to the Converter{} type itself, just a regular package function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and i assume probably worth making the account function instead return api theme models too, just to fit with how a lot of it is already done. what do you think??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm yes, I will change it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: 54d53a1