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,33 +33,18 @@ templ base(title, description, keywords, canonical string, head templ.Component)
<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>
</svg>
@navigation(title)
</header>
<main>
{ children... }
</main>
<footer>
<a href="/rss.xml" title="Stay up to date on what's going on.">RSS feed</a>
<br/>
&copy; 2017&mdash;2024 Alexander &quot;Arav&quot; Andreev &lt;<a href="mailto:me@arav.su">me@arav.su</a>&gt; <a href="/privacy">Privacy statements</a>
</footer>
</body>
</html>
}
templ navigation(title string) {
{{ sections := []string{"Stuff", "Mindflow", "About", "Guestbook"} }}
{{ links := []templ.SafeURL{"/stuff", "/mindflow", "/about", "/guestbook"} }}
{{ 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 sections {
for i, s := range mainNavSections {
if strings.HasSuffix(title, s) {
{{ continue }}
}
<li><a href={ links[i] }>{ s }</a></li>
<li><a href={ mainNavLinks[i] }>{ s }</a></li>
}
</ul>
if title != "" {
@ -72,4 +57,15 @@ templ navigation(title string) {
</h1>
}
</nav>
</header>
<main>
{ children... }
</main>
<footer>
<a href="/rss.xml" title="Stay up to date on what's going on.">RSS feed</a>
<br/>
&copy; 2017&mdash;2024 Alexander &quot;Arav&quot; Andreev &lt;<a href="mailto:me@arav.su">me@arav.su</a>&gt; <a href="/privacy">Privacy statements</a>
</footer>
</body>
</html>
}