Skip to content

Commit 8fef83f

Browse files
committed
Render classes on the same line
1 parent 089557b commit 8fef83f

3 files changed

Lines changed: 81 additions & 112 deletions

File tree

backend/web/ui/index.go

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ type IndexPageData struct {
2121
func IndexPage(data IndexPageData) g.Node {
2222
return PageLayout(data.PageLayoutData,
2323
// Header (search)
24-
h.Header(
25-
h.Class("articles-header"),
26-
g.If(data.Search != "", h.H1(
27-
h.Class("articles-header__title"),
28-
g.Text("Relevant Articles"),
29-
)),
30-
g.If(data.Search == "", h.H1(
31-
h.Class("articles-header__title"),
32-
g.Text("Recent Articles"),
33-
)),
24+
h.Header(h.Class("articles-header"),
25+
g.If(data.Search != "",
26+
h.H1(h.Class("articles-header__title"),
27+
g.Text("Relevant Articles"),
28+
),
29+
),
30+
g.If(data.Search == "",
31+
h.H1(h.Class("articles-header__title"),
32+
g.Text("Recent Articles"),
33+
),
34+
),
3435
// TODO: Replace this with <search> once gomponents supports it.
3536
h.Div(
3637
h.Form(
3738
h.Method("GET"),
3839
h.Action("/"),
39-
h.Input(
40-
h.Class("input"),
40+
h.Input(h.Class("input"),
4141
h.Type("text"),
4242
h.Name("q"),
4343
h.Value(data.Search),
@@ -48,23 +48,17 @@ func IndexPage(data IndexPageData) g.Node {
4848
),
4949

5050
// Articles
51-
h.Section(
52-
h.Class("articles"),
51+
h.Section(h.Class("articles"),
5352
g.Map(data.Articles, func(article finder.Article) g.Node {
54-
return h.Article(
55-
h.Class("article"),
56-
h.Header(
57-
h.Class("article__header"),
58-
h.Span(
59-
h.Class("article__date"),
53+
return h.Article(h.Class("article"),
54+
h.Header(h.Class("article__header"),
55+
h.Span(h.Class("article__date"),
6056
g.Text(article.PublishedAt.Format("Jan 2, 2006")),
6157
),
62-
h.Ul(
63-
h.Class("article__tags"),
58+
h.Ul(h.Class("article__tags"),
6459
g.Map(article.Tags, func(tag string) g.Node {
6560
return h.Li(
66-
h.A(
67-
h.Class("article__tag"),
61+
h.A(h.Class("article__tag"),
6862
h.Href(fmt.Sprintf("/?q=%s", tag)),
6963
g.Text(tag),
7064
),
@@ -73,15 +67,13 @@ func IndexPage(data IndexPageData) g.Node {
7367
),
7468
),
7569
h.P(
76-
h.A(
77-
h.Class("article__title"),
70+
h.A(h.Class("article__title"),
7871
h.Href(article.URL),
7972
g.Text(article.Title),
8073
),
8174
),
8275
h.P(
83-
h.A(
84-
h.Class("article__blog-title"),
76+
h.A(h.Class("article__blog-title"),
8577
h.Href(article.BlogURL),
8678
g.Text(article.BlogTitle),
8779
),
@@ -91,22 +83,19 @@ func IndexPage(data IndexPageData) g.Node {
9183
g.If(len(data.Articles) == 0,
9284
g.Group{
9385
g.If(data.Search != "",
94-
h.Article(
95-
h.Class("articles-cta"),
86+
h.Article(h.Class("articles-cta"),
9687
h.P(
9788
g.Text("No relevant articles! Try searching for something else."),
9889
),
9990
),
10091
),
10192
g.If(data.Search == "",
102-
h.Article(
103-
h.Class("articles-cta"),
93+
h.Article(h.Class("articles-cta"),
10494
h.P(
10595
g.Text("No posts found! Get started by following your favorite blogs."),
10696
),
10797
h.P(
108-
h.A(
109-
h.Class("button"),
98+
h.A(h.Class("button"),
11099
h.Href("/blogs"),
111100
g.Text("Follow Blogs"),
112101
),
@@ -119,18 +108,19 @@ func IndexPage(data IndexPageData) g.Node {
119108

120109
// Footer (pagination)
121110
g.If(data.HasMorePages,
122-
h.Footer(
123-
h.Class("articles-footer"),
124-
g.If(data.Search == "", h.A(
125-
h.Class("button button--outline"),
126-
h.Href(fmt.Sprintf("/?p=%d&q=%s", data.NextPage, data.Search)),
127-
g.Text("See More"),
128-
)),
129-
g.If(data.Search != "", h.A(
130-
h.Class("button button--outline"),
131-
h.Href(fmt.Sprintf("/?p=%d", data.NextPage)),
132-
g.Text("See More"),
133-
)),
111+
h.Footer(h.Class("articles-footer"),
112+
g.If(data.Search == "",
113+
h.A(h.Class("button button--outline"),
114+
h.Href(fmt.Sprintf("/?p=%d&q=%s", data.NextPage, data.Search)),
115+
g.Text("See More"),
116+
),
117+
),
118+
g.If(data.Search != "",
119+
h.A(h.Class("button button--outline"),
120+
h.Href(fmt.Sprintf("/?p=%d", data.NextPage)),
121+
g.Text("See More"),
122+
),
123+
),
134124
),
135125
),
136126
)

backend/web/ui/layout.go

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,63 +35,56 @@ func PageLayout(data PageLayoutData, children ...g.Node) g.Node {
3535
h.Async(),
3636
)),
3737
},
38-
Body: []g.Node{
39-
h.Class("sans-serif"),
38+
Body: []g.Node{h.Class("sans-serif"),
4039
// Header (nav bar)
41-
h.Header(
42-
h.Class("header"),
40+
h.Header(h.Class("header"),
4341
h.Nav(
44-
h.Ul(
45-
h.Class("header__links"),
46-
h.Li(
47-
h.Class("header__link--first"),
48-
h.A(
49-
h.Class("header__link header__link--home"),
42+
h.Ul(h.Class("header__links"),
43+
h.Li(h.Class("header__link--first"),
44+
h.A(h.Class("header__link header__link--home"),
5045
h.Href("/"),
5146
g.Text("Bloggulus"),
5247
),
5348
),
54-
g.If(data.Account != nil, g.Group{
55-
h.Li(
56-
h.A(
57-
h.Class("header__link"),
58-
h.Href("/blogs"),
59-
g.Text("Blogs"),
60-
),
61-
),
62-
h.Li(
63-
h.Form(
64-
h.Method("POST"),
65-
h.Action("/signout"),
66-
h.Input(
67-
h.Type("hidden"),
68-
h.Name("csrf_token"),
69-
h.Value(data.CSRFToken),
49+
g.If(data.Account != nil,
50+
g.Group{
51+
h.Li(
52+
h.A(h.Class("header__link"),
53+
h.Href("/blogs"),
54+
g.Text("Blogs"),
7055
),
71-
h.Button(
72-
h.Class("header__link"),
73-
h.Type("submit"),
74-
g.Text("Sign Out"),
56+
),
57+
h.Li(
58+
h.Form(
59+
h.Method("POST"),
60+
h.Action("/signout"),
61+
h.Input(
62+
h.Type("hidden"),
63+
h.Name("csrf_token"),
64+
h.Value(data.CSRFToken),
65+
),
66+
h.Button(h.Class("header__link"),
67+
h.Type("submit"),
68+
g.Text("Sign Out"),
69+
),
7570
),
7671
),
77-
),
78-
}),
79-
g.If(data.Account == nil, g.Group{
72+
},
73+
),
74+
g.If(data.Account == nil,
8075
h.Li(
81-
h.A(
82-
h.Class("header__link"),
76+
h.A(h.Class("header__link"),
8377
h.Href("/signin"),
8478
g.Text("Sign In"),
8579
),
8680
),
87-
}),
81+
),
8882
),
8983
),
9084
),
9185
// Toast message
9286
g.If(data.Toast != "",
93-
h.Div(
94-
h.Class("toast"),
87+
h.Div(h.Class("toast"),
9588
h.Div(
9689
g.Text(data.Toast),
9790
),
@@ -102,28 +95,23 @@ func PageLayout(data PageLayoutData, children ...g.Node) g.Node {
10295
g.Group(children),
10396
),
10497
// Footer
105-
h.Footer(
106-
h.Class("footer"),
98+
h.Footer(h.Class("footer"),
10799
h.Nav(
108-
h.Ul(
109-
h.Class("footer__links"),
100+
h.Ul(h.Class("footer__links"),
110101
h.Li(
111-
h.A(
112-
h.Class("footer__link footer__link--big"),
102+
h.A(h.Class("footer__link footer__link--big"),
113103
h.Href("/"),
114104
g.Text("Bloggulus"),
115105
),
116106
),
117107
h.Li(
118-
h.A(
119-
h.Class("footer__link footer__link--small"),
108+
h.A(h.Class("footer__link footer__link--small"),
120109
h.Href("/docs/privacy.html"),
121110
g.Text("Privacy Policy"),
122111
),
123112
),
124113
h.Li(
125-
h.A(
126-
h.Class("footer__link"),
114+
h.A(h.Class("footer__link"),
127115
h.Href("https://shallowbrooksoftware.com"),
128116
g.Text("Shallow Brook Software"),
129117
),

backend/web/ui/signin.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ type SignInPageData struct {
1313

1414
func SignInPage(data SignInPageData) g.Node {
1515
return PageLayout(data.PageLayoutData,
16-
h.Section(
17-
h.Class("signin"),
18-
h.Article(
19-
h.Class("signin__card"),
20-
h.H2(
21-
h.Class("signin__heading"),
16+
h.Section(h.Class("signin"),
17+
h.Article(h.Class("signin__card"),
18+
h.H2(h.Class("signin__heading"),
2219
g.Text("Welcome!"),
2320
),
2421

@@ -33,33 +30,27 @@ func SignInPage(data SignInPageData) g.Node {
3330
h.Name("csrf_token"),
3431
h.Value(data.CSRFToken),
3532
),
36-
h.Button(
37-
h.Class("signin__button"),
33+
h.Button(h.Class("signin__button"),
3834
h.Type("submit"),
39-
h.Img(
40-
h.Class("signin__icon"),
35+
h.Img(h.Class("signin__icon"),
4136
h.Src("/img/bloggulus.png"),
4237
),
4338
g.Text("Sign in with Debug"),
4439
),
4540
),
4641
),
4742

48-
h.A(
49-
h.Class("signin__button"),
43+
h.A(h.Class("signin__button"),
5044
h.Href("/github/signin"),
51-
h.Img(
52-
h.Class("signin__icon"),
45+
h.Img(h.Class("signin__icon"),
5346
h.Src("/img/github.png"),
5447
),
5548
g.Text("Sign in with GitHub"),
5649
),
5750

58-
h.A(
59-
h.Class("signin__button"),
51+
h.A(h.Class("signin__button"),
6052
h.Href("/google/signin"),
61-
h.Img(
62-
h.Class("signin__icon"),
53+
h.Img(h.Class("signin__icon"),
6354
h.Src("/img/google.png"),
6455
),
6556
g.Text("Sign in with Google"),

0 commit comments

Comments
 (0)