1
1
package goBuild
2
2
3
- templ page (title string , contents templ.Component , showSearchBar bool ) {
3
+ const (
4
+ GENERATED_PAGE = " gen"
5
+ CONTENT_PAGE = " content"
6
+ SEARCH_PAGE = " search"
7
+ )
8
+
9
+ templ page (title string , contents templ.Component , pageType string ) {
4
10
<!DOCTYPE html>
5
11
<html lang =" en" >
6
12
<head >
@@ -9,7 +15,7 @@ templ page(title string, contents templ.Component, showSearchBar bool) {
9
15
<link rel =" stylesheet" href =" /styles.css" />
10
16
<title >{ title }</title >
11
17
<meta name =" description" content =" Kyle and Alex's Personal Recipes" />
12
- if showSearchBar {
18
+ if pageType == SEARCH_PAGE {
13
19
<link href =" /pagefind/pagefind-ui.css" rel =" stylesheet" />
14
20
<script src =" /pagefind/pagefind-ui.js" ></script >
15
21
}
@@ -22,10 +28,10 @@ templ page(title string, contents templ.Component, showSearchBar bool) {
22
28
<a href =" /search.html" ><i ><strong >Search</strong ></i ></a >
23
29
</div >
24
30
</nav >
25
- <main data-pagefind-body ?={ !showSearchBar }>
31
+ <main data-pagefind-body ?={ pageType == CONTENT_PAGE }>
26
32
@ contents
27
33
</main >
28
- if showSearchBar {
34
+ if pageType == SEARCH_PAGE {
29
35
<script >
30
36
window .addEventListener (" DOMContentLoaded" , (event ) => {
31
37
new PagefindUI ({
@@ -41,15 +47,15 @@ templ page(title string, contents templ.Component, showSearchBar bool) {
41
47
}
42
48
43
49
templ recipePage (title string , content string ) {
44
- @ page (title, templ.Raw (content), false )
50
+ @ page (title, templ.Raw (content), CONTENT_PAGE )
45
51
}
46
52
47
53
templ searchContents () {
48
54
<div style =" margin-top: 10px" id =" search" ></div >
49
55
}
50
56
51
57
templ searchPage () {
52
- @ page (" Search Recipes" , searchContents (), true )
58
+ @ page (" Search Recipes" , searchContents (), SEARCH_PAGE )
53
59
}
54
60
55
61
templ notFoundContents () {
@@ -59,7 +65,7 @@ templ notFoundContents() {
59
65
}
60
66
61
67
templ notFoundPage () {
62
- @ page (" Page Not Found" , notFoundContents (), false )
68
+ @ page (" Page Not Found" , notFoundContents (), GENERATED_PAGE )
63
69
}
64
70
65
71
templ dirIndexContent (title string , recipes []Recipe ) {
@@ -79,7 +85,7 @@ templ dirIndexContent(title string, recipes []Recipe) {
79
85
}
80
86
81
87
templ dirIndexPage (title string , recipes []Recipe ) {
82
- @ page (title, dirIndexContent (title, recipes), false )
88
+ @ page (title, dirIndexContent (title, recipes), GENERATED_PAGE )
83
89
}
84
90
85
91
templ homeContent (subdirectories []Subdir ) {
@@ -93,5 +99,5 @@ templ homeContent(subdirectories []Subdir) {
93
99
}
94
100
95
101
templ homePage (subdirectories []Subdir ) {
96
- @ page (" Recipes" , homeContent (subdirectories), false )
102
+ @ page (" Recipes" , homeContent (subdirectories), GENERATED_PAGE )
97
103
}
0 commit comments