apps/posts/public.templ 4.6 K raw
1
package main
2
3
// Each public view has a meta component (kept in the layout's <head>) and a
4
// body component. The body can be replaced by a custom html/template from
5
// /admin/templates; the starters/*.html files mirror these defaults.
6
7
templ postItem(p Post, class string) {
8
	<a href={ templ.URL("/posts/" + p.Slug) } class={ class }>
9
		<div class="post-item-info">
10
			<span class="post-title">{ p.DisplayTitle() }</span>
11
		</div>
12
		if p.PublishedDate != nil {
13
			<time class="post-date">{ p.PublishedDateStr() }</time>
14
		}
15
	</a>
16
}
17
18
templ latestPosts(posts []Post) {
19
	<div class="post-list">
20
		for _, p := range posts {
21
			<a href={ templ.URL("/posts/" + p.Slug) } class="post-item">
22
				<div class="post-item-info">
23
					<span class="post-title">{ p.DisplayTitle() }</span>
24
					if tags := p.TagList(); len(tags) > 0 {
25
						<span class="post-tags">
26
							for _, t := range tags {
27
								<span class="tag">{ t }</span>
28
							}
29
						</span>
30
					}
31
				</div>
32
				if p.PublishedDate != nil {
33
					<time class="post-date">{ p.PublishedDateStr() }</time>
34
				}
35
			</a>
36
		}
37
	</div>
38
}
39
40
templ indexMeta(v indexView) {
41
	<meta name="description" content={ v.BlogDescription }/>
42
	<meta property="og:title" content={ v.BlogTitle }/>
43
	<meta property="og:description" content={ v.BlogDescription }/>
44
	<meta property="og:type" content="website"/>
45
	<meta property="og:url" content={ v.SiteURL }/>
46
	@ogImage(v.siteContext)
47
}
48
49
templ indexBody(v indexView) {
50
	if v.IntroHTML != "" {
51
		<article class="intro markdown-body">
52
			@templ.Raw(string(v.IntroHTML))
53
		</article>
54
	}
55
	if len(v.Posts) == 0 {
56
		<p class="empty">no posts yet</p>
57
	}
58
	<div class="post-list">
59
		for _, p := range v.Posts {
60
			@postItem(p, "post-item")
61
		}
62
	</div>
63
}
64
65
templ postsMeta(v postsView) {
66
	@ogImage(v.siteContext)
67
	<meta property="og:url" content={ v.SiteURL + "/posts" }/>
68
}
69
70
templ postsBody(v postsView) {
71
	<h1>Posts</h1>
72
	if len(v.Posts) == 0 {
73
		<p class="empty">no posts yet</p>
74
	}
75
	<div class="post-list">
76
		for _, p := range v.Posts {
77
			@postItem(p, "post-item post-item-enhanced")
78
		}
79
	</div>
80
}
81
82
templ pageMeta(v pageView) {
83
	@ogImage(v.siteContext)
84
	<meta property="og:url" content={ v.SiteURL + "/" + v.Page.Slug }/>
85
}
86
87
templ pageBody(v pageView) {
88
	<div class="page-header">
89
		<h1>{ v.Page.Title }</h1>
90
	</div>
91
	<article class="markdown-body">
92
		@templ.Raw(string(v.RenderedContent))
93
	</article>
94
}
95
96
templ postMeta(v postView) {
97
	if v.Post.MetaDescription != nil {
98
		<meta name="description" content={ v.Post.MetaDescriptionStr() }/>
99
		<meta property="og:description" content={ v.Post.MetaDescriptionStr() }/>
100
	}
101
	if v.Post.MetaImageStr() != "" {
102
		<meta property="og:image" content={ v.Post.MetaImageStr() }/>
103
	} else {
104
		@ogImage(v.siteContext)
105
	}
106
	if v.Post.CanonicalURL != nil {
107
		<link rel="canonical" href={ templ.URL(v.Post.CanonicalURLStr()) }/>
108
	}
109
	<meta property="og:title" content={ v.Post.DisplayTitle() }/>
110
	<meta property="og:type" content="article"/>
111
	<meta property="og:url" content={ v.SiteURL + "/posts/" + v.Post.Slug }/>
112
	<meta property="article:published_time" content={ v.Post.PublishedDateStr() }/>
113
}
114
115
// The location icon is from Phosphor Icons:
116
// https://github.com/phosphor-icons/core/blob/main/LICENSE
117
templ postBody(v postView) {
118
	<div class="post-header">
119
		if v.Post.HasTitle() {
120
			<h1>{ v.Post.TitleStr() }</h1>
121
		}
122
		if v.Post.MetaDescription != nil {
123
			<p class="post-description">{ v.Post.MetaDescriptionStr() }</p>
124
		}
125
		<div class="post-weather">
126
			if v.Post.PublishedDate != nil {
127
				<span>
128
					<time class="post-date">{ v.Post.PublishedDateStr() }</time>
129
				</span>
130
				<span>•</span>
131
			}
132
			if v.Post.Weather != nil {
133
				@templ.Raw(string(v.Weather.Icon))
134
				<p class="weather-conditions">{ v.Weather.Conditions }</p>
135
				<p class="weather-temp">{ v.Weather.Temperature }</p>
136
				•
137
				<div class="weather-location">
138
					<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path fill="currentColor" d="M128 68a36 36 0 1 0 36 36a36 36 0 0 0-36-36m0 64a28 28 0 1 1 28-28a28 28 0 0 1-28 28m0-112a84.09 84.09 0 0 0-84 84c0 30.42 14.17 62.79 41 93.62a250 250 0 0 0 40.73 37.66a4 4 0 0 0 4.58 0A250 250 0 0 0 171 197.62c26.81-30.83 41-63.2 41-93.62a84.09 84.09 0 0 0-84-84m37.1 172.23A254.6 254.6 0 0 1 128 227a254.6 254.6 0 0 1-37.1-34.81C73.15 171.8 52 139.9 52 104a76 76 0 0 1 152 0c0 35.9-21.15 67.8-38.9 88.23"></path></svg>
139
					<p>{ v.Weather.Location }</p>
140
				</div>
141
			}
142
		</div>
143
		if len(v.Post.TagList()) > 0 {
144
			<div class="post-tags">
145
				for _, t := range v.Post.TagList() {
146
					<span class="tag">{ t }</span>
147
				}
148
			</div>
149
		}
150
	</div>
151
	<article class="markdown-body">
152
		@templ.Raw(string(v.RenderedContent))
153
	</article>
154
}