Skip to content

Commit

Permalink
feat: allow hiding "powered by" link (#12)
Browse files Browse the repository at this point in the history
* add HidePoweredBy to config

* hide powered by link based on config flag

* fix background not stretching full height

* update apitypes

* fix comment
  • Loading branch information
JonasHiltl authored Sep 20, 2024
1 parent ff52735 commit 1825ece
Show file tree
Hide file tree
Showing 25 changed files with 334 additions and 219 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.2

require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240913181521-3708ddadc4d2
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240920110319-6925911f7f64
golang.org/x/net v0.25.0
)

Expand Down
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240913181521-3708ddadc4d2 h1:HasYzw37auhdq6nHXyvgEocAxeTPxRUjczIdLfkTdmY=
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240913181521-3708ddadc4d2/go.mod h1:xnbFN3Wrw2B1F/D7pvjjwoeXSt+njRI31ccPFno0BM0=
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240920110319-6925911f7f64 h1:yeoqi6Ur2IdboPLZU4I5XR+VzSQVEH+EwW4kPhun/EU=
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20240920110319-6925911f7f64/go.mod h1:xnbFN3Wrw2B1F/D7pvjjwoeXSt+njRI31ccPFno0BM0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand Down
86 changes: 51 additions & 35 deletions apitypes/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
// Represents the Changelog returned by the API via json encoding.
// Implements json un-/marshaling.
type Changelog struct {
ID string
WorkspaceID string
Subdomain string
Domain NullString
Title NullString
Subtitle NullString
ColorScheme ColorScheme
Logo Logo
Source Source
CreatedAt time.Time
ID string
WorkspaceID string
Subdomain string
Domain NullString
Title NullString
Subtitle NullString
ColorScheme ColorScheme
HidePoweredBy bool
Logo Logo
Source Source
CreatedAt time.Time
}

type ColorScheme string
Expand All @@ -30,25 +31,27 @@ const (

func (l Changelog) MarshalJSON() ([]byte, error) {
obj := struct {
ID string `json:"id"`
WorkspaceID string `json:"workspaceId"`
Subdomain string `json:"subdomain,omitempty"`
Title string `json:"title,omitempty"`
Domain string `json:"domain,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
ColorScheme string `json:"colorScheme,omitempty"`
Logo *Logo `json:"logo,omitempty"`
Source Source `json:"source,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
ID string `json:"id"`
WorkspaceID string `json:"workspaceId"`
Subdomain string `json:"subdomain,omitempty"`
Title string `json:"title,omitempty"`
Domain string `json:"domain,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
ColorScheme string `json:"colorScheme,omitempty"`
HidePoweredBy bool `json:"hidePoweredBy"`
Logo *Logo `json:"logo,omitempty"`
Source Source `json:"source,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
}{
ID: l.ID,
WorkspaceID: l.WorkspaceID,
Subdomain: l.Subdomain,
Domain: l.Domain.V(),
Title: l.Title.V(),
Subtitle: l.Subtitle.V(),
ColorScheme: string(l.ColorScheme),
Source: l.Source,
ID: l.ID,
WorkspaceID: l.WorkspaceID,
Subdomain: l.Subdomain,
Domain: l.Domain.V(),
Title: l.Title.V(),
Subtitle: l.Subtitle.V(),
ColorScheme: string(l.ColorScheme),
HidePoweredBy: l.HidePoweredBy,
Source: l.Source,
}

if l.Logo.IsValid() {
Expand Down Expand Up @@ -119,6 +122,13 @@ func (c *Changelog) UnmarshalJSON(b []byte) error {
}
}

if hidePoweredByRaw, ok := objMap["hidePoweredBy"]; ok {
err = json.Unmarshal(*hidePoweredByRaw, &c.HidePoweredBy)
if err != nil {
return err
}
}

if logoRaw, ok := objMap["logo"]; ok {
err = json.Unmarshal(*logoRaw, &c.Logo)
if err != nil {
Expand Down Expand Up @@ -207,14 +217,20 @@ func (l Logo) IsValid() bool {
}

type CreateChangelogBody struct {
Title NullString `json:"title"`
Subtitle NullString `json:"subtitle"`
Logo Logo `json:"logo"`
Domain NullString `json:"domain"`
ColorScheme ColorScheme `json:"colorScheme"`
Title NullString `json:"title"`
Subtitle NullString `json:"subtitle"`
Logo Logo `json:"logo"`
Domain NullString `json:"domain"`
ColorScheme ColorScheme `json:"colorScheme"`
HidePoweredBy bool `json:"hidePoweredBy"`
}

type UpdateChangelogBody struct {
CreateChangelogBody
Subdomain NullString `json:"subdomain"`
Title NullString `json:"title"`
Subtitle NullString `json:"subtitle"`
Logo Logo `json:"logo"`
Domain NullString `json:"domain"`
ColorScheme ColorScheme `json:"colorScheme"`
Subdomain NullString `json:"subdomain"`
HidePoweredBy *bool `json:"hidePoweredBy,omitempty"`
}
89 changes: 50 additions & 39 deletions apitypes/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func TestChangelogMarshaling(t *testing.T) {
Repo: "openchangelog",
Path: ".testdata",
},
ColorScheme: Dark,
CreatedAt: now,
ColorScheme: Dark,
HidePoweredBy: true,
CreatedAt: now,
},
expect: fmt.Sprintf(`{
"id": "cl_xxxx",
Expand All @@ -63,23 +64,26 @@ func TestChangelogMarshaling(t *testing.T) {
"repo": "openchangelog",
"path": ".testdata"
},
"hidePoweredBy": true,
"colorScheme": "dark",
"createdAt": "%s"
}`, nowStr),
},
{
input: Changelog{
ID: "cl_xxxx",
WorkspaceID: "ws_xxxx",
Title: NewString("Test Title"),
ColorScheme: System,
CreatedAt: now,
ID: "cl_xxxx",
WorkspaceID: "ws_xxxx",
Title: NewString("Test Title"),
ColorScheme: System,
HidePoweredBy: false,
CreatedAt: now,
},
expect: fmt.Sprintf(`{
"id": "cl_xxxx",
"workspaceId": "ws_xxxx",
"title": "Test Title",
"colorScheme": "system",
"hidePoweredBy": false,
"createdAt": "%s"
}`, nowStr),
},
Expand All @@ -94,6 +98,7 @@ func TestChangelogMarshaling(t *testing.T) {
expect: `{
"id": "cl_xxxx",
"workspaceId": "ws_xxxx",
"hidePoweredBy": false,
"logo": {
"alt": "test"
}
Expand Down Expand Up @@ -127,8 +132,9 @@ func TestChangelogUnmarshal(t *testing.T) {
Repo: "openchangelog",
Path: ".testdata",
},
ColorScheme: Dark,
CreatedAt: time.Unix(1715958564, 0).UTC(),
HidePoweredBy: true,
ColorScheme: Dark,
CreatedAt: time.Unix(1715958564, 0).UTC(),
},
{
ID: "cl_xxxx",
Expand Down Expand Up @@ -158,6 +164,7 @@ func TestChangelogUnmarshal(t *testing.T) {
}

func TestUpdateChangelogBodyMarshal(t *testing.T) {
hidePoweredBy := true
tests := []struct {
name string
input UpdateChangelogBody
Expand All @@ -178,9 +185,7 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
{
name: "valid title",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Title: NewString("test"),
},
Title: NewString("test"),
},
expected: `{
"title": "test",
Expand All @@ -194,9 +199,7 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
{
name: "null title",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Title: NewNullString(),
},
Title: NewNullString(),
},
expected: `{
"title": null,
Expand All @@ -210,10 +213,8 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
{
name: "valid logo",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Logo: Logo{
Src: NewString("test"),
},
Logo: Logo{
Src: NewString("test"),
},
},
expected: `{
Expand All @@ -230,9 +231,7 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
{
name: "valid color scheme",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
ColorScheme: Dark,
},
ColorScheme: Dark,
},
expected: `{
"title": "",
Expand All @@ -243,6 +242,21 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
"colorScheme": "dark"
}`,
},
{
name: "valid hide powered by",
input: UpdateChangelogBody{
HidePoweredBy: &hidePoweredBy,
},
expected: `{
"title": "",
"subtitle": "",
"logo": {},
"domain": "",
"subdomain": "",
"colorScheme": "",
"hidePoweredBy": true
}`,
},
}

for _, test := range tests {
Expand All @@ -258,6 +272,7 @@ func TestUpdateChangelogBodyMarshal(t *testing.T) {
}

func TestUpdateChangelogBodyUnmarshal(t *testing.T) {
hidePoweredBy := true
tests := []struct {
name string
input UpdateChangelogBody
Expand All @@ -269,45 +284,41 @@ func TestUpdateChangelogBodyUnmarshal(t *testing.T) {
{
name: "valid title",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Title: NewString("test"),
},
Title: NewString("test"),
},
},
{
name: "null title",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Title: NewNullString(),
},
Title: NewNullString(),
},
},
{
name: "valid logo",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Logo: Logo{
Src: NewString("test"),
},
Logo: Logo{
Src: NewString("test"),
},
},
},
{
name: "null logo src",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
Logo: Logo{
Src: NewNullString(),
},
Logo: Logo{
Src: NewNullString(),
},
},
},
{
name: "valid color scheme",
input: UpdateChangelogBody{
CreateChangelogBody: CreateChangelogBody{
ColorScheme: Dark,
},
ColorScheme: Dark,
},
},
{
name: "valid hide powered by",
input: UpdateChangelogBody{
HidePoweredBy: &hidePoweredBy,
},
},
}
Expand Down
10 changes: 10 additions & 0 deletions apitypes/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ func NewNullString() NullString {
}

type NullColorScheme = Null[ColorScheme]

type NullBool = Null[bool]

func NewBool(b bool) NullBool {
return NewValue(b)
}

func NewNullBool() NullBool {
return NewNull[bool]()
}
20 changes: 13 additions & 7 deletions components/footer.templ
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package components

templ Footer() {
<footer class="border-t border-t-gray-200 dark:border-t-gray-800 mt-10 pt-10 pb-20">
<div class="text-caption px-4 sm:px-0">
Powered by <a href="https://openchangelog.com" target="_blank">Openchangelog</a>
</div>
</footer>
}
type FooterArgs struct {
HidePoweredBy bool
}

templ Footer(args FooterArgs) {
<footer class="border-t border-t-gray-200 dark:border-t-gray-800 mt-10 pt-10 pb-20">
if !args.HidePoweredBy {
<div class="text-caption px-4 sm:px-0">
Powered by <a href="https://openchangelog.com" target="_blank">Openchangelog</a>
</div>
}
</footer>
}
Loading

0 comments on commit 1825ece

Please sign in to comment.