1
0

Place navigation inside a base template.

This commit is contained in:
Alexander Andreev 2024-06-30 03:00:03 +04:00
parent c5418710e5
commit 46e5213b36
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -33,7 +33,30 @@ templ base(title, description, keywords, canonical string, head templ.Component)
<text y="7" textLength="360" lengthAdjust="spacingAndGlyphs">Arav's dwelling</text> <text y="7" textLength="360" lengthAdjust="spacingAndGlyphs">Arav's dwelling</text>
<text y="25" textLength="360" lengthAdjust="spacingAndGlyphs">Welcome to my sacred place, wanderer</text> <text y="25" textLength="360" lengthAdjust="spacingAndGlyphs">Welcome to my sacred place, wanderer</text>
</svg> </svg>
@navigation(title) {{ mainNavSections := []string{"Stuff", "Mindflow", "About", "Guestbook"} }}
{{ mainNavLinks := []templ.SafeURL{"/stuff", "/mindflow", "/about", "/guestbook"} }}
<nav>
<ul>
if title != "" {
<li><a href="/">Home</a></li>
}
for i, s := range mainNavSections {
if strings.HasSuffix(title, s) {
{{ continue }}
}
<li><a href={ mainNavLinks[i] }>{ s }</a></li>
}
</ul>
if title != "" {
<h1>
if strings.HasSuffix(title, "- Stuff") {
Stuff
} else {
{ title }
}
</h1>
}
</nav>
</header> </header>
<main> <main>
{ children... } { children... }
@ -45,31 +68,4 @@ templ base(title, description, keywords, canonical string, head templ.Component)
</footer> </footer>
</body> </body>
</html> </html>
} }
templ navigation(title string) {
{{ sections := []string{"Stuff", "Mindflow", "About", "Guestbook"} }}
{{ links := []templ.SafeURL{"/stuff", "/mindflow", "/about", "/guestbook"} }}
<nav>
<ul>
if title != "" {
<li><a href="/">Home</a></li>
}
for i, s := range sections {
if strings.HasSuffix(title, s) {
{{ continue }}
}
<li><a href={ links[i] }>{ s }</a></li>
}
</ul>
if title != "" {
<h1>
if strings.HasSuffix(title, "- Stuff") {
Stuff
} else {
{ title }
}
</h1>
}
</nav>
}