Blog/themes/blog/layouts/nav.gohtml

71 lines
3.4 KiB
Plaintext

{{define "nav"}}
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: var(--primary,#673ab7);">
<div class="container">
<a class="navbar-brand" href="/blog" style="font-size: 120%">{{ .Config.SiteName }}</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMain" aria-controls="navbarMain" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarMain">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/blog">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/categories">Categories</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
More
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
{{if ne .Config.MemosAlbumTag ""}}
<li><a class="dropdown-item" href="/memos?name=album">Album</a></li>
{{ end }}
{{if ne .Config.MemosTalkTag ""}}
<li><a class="dropdown-item" href="/memos?name=talk">Talk</a></li>
{{ end }}
<li><hr class="dropdown-divider"></li>
{{range $nav := .Navs }}
<li><a class="dropdown-item" href="/extra-nav?name={{ $nav.Title }}">{{ $nav.Title }}</a></li>
{{end}}
</ul>
</li>
<!-- <li class="nav-item">-->
<!-- <a class="nav-link disabled">Disabled</a>-->
<!-- </li>-->
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit"><img src="/public/img/search.svg" alt="Search" style=""></button>
</form>
</div>
</div>
</nav>
<script>
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault();
const searchQuery = document.querySelector('.form-control').value.trim();
if (searchQuery) {
const searchUrl = `/?search=${encodeURIComponent(searchQuery)}`;
window.location.href = searchUrl;
} else {
console.log('请输入搜索关键词');
}
});
const btn = document.querySelector('.btn-outline-success');
const observer = new MutationObserver((mutationsList, observer) => {
for (let mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
btn.style.borderColor= 'invert(100%)';
}
}
});
observer.observe(btn, { attributes: true });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
{{ end }}