Skip to content

Commit d059a8c

Browse files
committed
add featured image field
1 parent fba571f commit d059a8c

File tree

10 files changed

+70
-61
lines changed

10 files changed

+70
-61
lines changed

pkg/pages/relations.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ func mapRelations(relations []dbx.Page, settings dbx.Setting) []pages.Relation {
1010
mapped := make([]pages.Relation, len(relations))
1111
for i, rel := range relations {
1212
mapped[i] = pages.Relation{
13-
ID: rel.ID,
14-
Title: rel.Title,
15-
Path: rel.Path,
16-
Url: rel.Url.String,
17-
Level: rel.Level.Int32,
18-
CreatedAt: rel.CreatedAt.Time,
19-
UpdatedAt: rel.UpdatedAt.Time,
20-
Meta: getMeta(rel, settings),
13+
ID: rel.ID,
14+
Title: rel.Title,
15+
Path: rel.Path,
16+
Url: rel.Url.String,
17+
Level: rel.Level.Int32,
18+
FeaturedImage: rel.FeaturedImage,
19+
CreatedAt: rel.CreatedAt.Time,
20+
UpdatedAt: rel.UpdatedAt.Time,
21+
Meta: getMeta(rel, settings),
2122
}
2223
}
2324
return mapped

pkg/pages/router.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ func pageHandler(c echo.Context) error {
9090
}
9191

9292
pageComponent := &pages.Page{
93-
ID: page.Page.ID,
94-
Title: page.Page.Title,
95-
Path: page.Page.Path,
96-
Url: page.Page.Url.String,
97-
Level: page.Page.Level.Int32,
98-
Tags: page.Page.Tags,
99-
Categories: page.Page.Categories,
100-
CreatedAt: page.Page.CreatedAt.Time,
101-
UpdatedAt: page.Page.UpdatedAt.Time,
102-
PublishedAt: page.Page.PublishedAt.Time,
103-
Meta: getMeta(page.Page, settings),
104-
PageType: pageType,
105-
Ancestors: mapRelations(ancestors, settings),
106-
Children: mapRelations(children, settings),
93+
ID: page.Page.ID,
94+
Title: page.Page.Title,
95+
Path: page.Page.Path,
96+
Url: page.Page.Url.String,
97+
Level: page.Page.Level.Int32,
98+
Tags: page.Page.Tags,
99+
Categories: page.Page.Categories,
100+
FeaturedImage: page.Page.FeaturedImage,
101+
CreatedAt: page.Page.CreatedAt.Time,
102+
UpdatedAt: page.Page.UpdatedAt.Time,
103+
PublishedAt: page.Page.PublishedAt.Time,
104+
Meta: getMeta(page.Page, settings),
105+
PageType: pageType,
106+
Ancestors: mapRelations(ancestors, settings),
107+
Children: mapRelations(children, settings),
107108
}
108109

109110
html := pageComponent.HTML()

pkg/storage/db/dbx/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/storage/db/dbx/page.sql.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/storage/db/dbx/page_type.sql.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/storage/db/migrations/000001_initial.up.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ create table page
128128
title varchar(160) not null,
129129
tags text[] not null default '{}',
130130
categories text[] not null default '{}',
131+
featured_image text not null default '',
131132
is_in_sitemap boolean not null default true,
132133
is_searchable boolean not null default true,
133134
search_vector tsvector not null default to_tsvector(''),

pkg/storage/db/migrations/000002_data.up.sql

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@ values
77
'index, follow'
88
);
99

10-
insert into page_html (path, title, meta_description, meta_og_image, html)
10+
insert into page_html (path, title, featured_image, meta_description, html)
1111
values
1212
(
1313
'',
1414
'home',
15-
'description for the home page',
1615
'https://placehold.co/600/6b7280/f9fafb?text=home&font=open-sans',
16+
'description for the home page',
1717
'<div class="space-y-6"><div class="h-48 bg-gray-100 rounded-lg"></div><div class="space-y-3"><p>Some crappy text on the home page.</p><div class="h-4 bg-gray-100 rounded w-2/3"></div><div class="h-4 bg-gray-100 rounded w-1/2"></div><div class="h-4 bg-gray-100 rounded w-full"></div></div></div>'
1818
);
1919

20-
insert into page (path, title, no_cache, meta_description, meta_og_image, meta_robots, page_type, is_in_sitemap, is_searchable)
20+
insert into page (path, title, no_cache, meta_description, meta_robots, page_type, is_in_sitemap, is_searchable)
2121
values
2222
(
2323
'about',
2424
'about',
2525
false,
2626
'description for the about page',
27-
'https://placehold.co/600/6b7280/f9fafb?text=about&font=open-sans',
2827
null,
2928
'listing',
3029
true,
@@ -35,40 +34,39 @@ values
3534
'search',
3635
true,
3736
'description for the search page',
38-
'https://placehold.co/600/6b7280/f9fafb?text=search&font=open-sans',
3937
'noindex, follow',
4038
'search',
4139
false,
4240
false
4341
);
4442

45-
insert into page_html (path, title, tags, categories, meta_description, meta_og_image, html)
43+
insert into page_html (path, title, featured_image, tags, categories, meta_description, html)
4644
values
4745
(
4846
'about.dave',
4947
'dave',
48+
'https://placehold.co/600/6b7280/f9fafb?text=dave&font=open-sans',
5049
'{"Owner"}',
5150
'{"Team"}',
5251
'description for the dave page',
53-
'https://placehold.co/600/6b7280/f9fafb?text=dave&font=open-sans',
5452
'<div class="space-y-6"><div class="flex items-center space-x-4"><div class="h-32 w-32 bg-gray-100 rounded-full"></div><div class="space-y-2"><div class="h-4 bg-gray-100 rounded w-1/2"></div><div class="h-4 bg-gray-100 rounded w-1/3"></div></div></div><div class="space-y-3"><p>Hello im dave a strapping six footer from the rough end of the trench.</p><div class="h-4 bg-gray-100 rounded w-full"></div><div class="h-4 bg-gray-100 rounded w-5/6"></div><div class="h-4 bg-gray-100 rounded w-4/6"></div></div></div>'
5553
),
5654
(
5755
'about.karen',
5856
'karen',
57+
'https://placehold.co/600/6b7280/f9fafb?text=karen&font=open-sans',
5958
'{"Manager"}',
6059
'{"Team"}',
6160
'description for the karen page',
62-
'https://placehold.co/600/6b7280/f9fafb?text=karen&font=open-sans',
6361
'<div class="space-y-6"><div class="flex items-center space-x-4"><div class="h-32 w-32 bg-gray-100 rounded-full"></div><div class="space-y-2"><div class="h-4 bg-gray-100 rounded w-1/2"></div><div class="h-4 bg-gray-100 rounded w-1/3"></div></div></div><div class="space-y-3"><p>Hello im karen, daves better half.</p><div class="h-4 bg-gray-100 rounded w-full"></div><div class="h-4 bg-gray-100 rounded w-5/6"></div><div class="h-4 bg-gray-100 rounded w-4/6"></div></div></div>'
6462
),
6563
(
6664
'about.geoff',
6765
'geoff',
66+
'https://placehold.co/600/6b7280/f9fafb?text=geoff&font=open-sans',
6867
'{"Owner"}',
6968
'{"Team"}',
7069
'description for the geoff page',
71-
'https://placehold.co/600/6b7280/f9fafb?text=geoff&font=open-sans',
7270
'<div class="space-y-6"><div class="flex items-center space-x-4"><div class="h-32 w-32 bg-gray-100 rounded-full"></div><div class="space-y-2"><div class="h-4 bg-gray-100 rounded w-1/2"></div><div class="h-4 bg-gray-100 rounded w-1/3"></div></div></div><div class="space-y-3"><p>Hello im geoff and I love a good factory.</p><div class="h-4 bg-gray-100 rounded w-full"></div><div class="h-4 bg-gray-100 rounded w-5/6"></div><div class="h-4 bg-gray-100 rounded w-4/6"></div></div></div>'
7371
);
7472

pkg/ui/pages/page_listing.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ templ (t *PageTypeListing) Body(page *Page) {
77
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
88
for _, child := range page.Children {
99
<a class="space-y-3" href={ templ.URL(child.Url) }>
10-
<img class="w-full" src={ child.Meta.OGImage } alt={ child.Title }/>
10+
<img class="w-full" src={ child.FeaturedImage } alt={ child.Title }/>
1111
<div class="text-xl font-semibold tracking-tight">{ child.Title }</div>
1212
<div>{ child.Meta.Description }</div>
1313
</a>

pkg/ui/pages/page_listing_templ.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ui/pages/types.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ type Meta struct {
2828

2929
// Relation is a relation of a page
3030
type Relation struct {
31-
ID int32
32-
Title string
33-
Path string
34-
Url string
35-
Level int32
36-
CreatedAt time.Time
37-
UpdatedAt time.Time
38-
Meta Meta
31+
ID int32
32+
Title string
33+
Path string
34+
Url string
35+
Level int32
36+
FeaturedImage string
37+
CreatedAt time.Time
38+
UpdatedAt time.Time
39+
Meta Meta
3940
}
4041

4142
// PageType is an interface used as the page type Body is used to render the body tag.
@@ -45,20 +46,21 @@ type PageType interface {
4546

4647
// Page struct.
4748
type Page struct {
48-
ID int32
49-
Title string
50-
Path string
51-
Url string
52-
Level int32
53-
Tags []string
54-
Categories []string
55-
CreatedAt time.Time
56-
UpdatedAt time.Time
57-
PublishedAt time.Time
58-
Meta Meta
59-
PageType PageType
60-
Ancestors []Relation
61-
Children []Relation
49+
ID int32
50+
Title string
51+
Path string
52+
Url string
53+
Level int32
54+
Tags []string
55+
Categories []string
56+
FeaturedImage string
57+
CreatedAt time.Time
58+
UpdatedAt time.Time
59+
PublishedAt time.Time
60+
Meta Meta
61+
PageType PageType
62+
Ancestors []Relation
63+
Children []Relation
6264
}
6365

6466
// PageTypeListing is used when the content listed from the children and only relevant to base pages.

0 commit comments

Comments
 (0)