fixed hamburger menu and edit link

This commit is contained in:
liyunze 2024-04-21 18:49:23 +08:00
parent e217e8ed92
commit 17e69a533d
4 changed files with 27 additions and 23 deletions

View file

@ -1,11 +1,11 @@
--- ---
const currentUrl = Astro.url.pathname; const currentUrl = Astro.url.pathname.slice(0, -1) + ".md";
--- ---
<ul class="list-none text-sm"> <ul class="list-none text-sm">
<li class="ml-[0.5rem] my-2"> <li class="ml-[0.5rem] my-2">
<a <a
href={`https://github.com/liyunze-coding/coworking-website/edit/main/src/pages${currentUrl}.md`} href={`https://github.com/liyunze-coding/coworking-website/edit/main/src/pages${currentUrl}`}
class="inline-flex gap-2 transition-colors duration-150 text-white hover:no-underline hover:text-blue-400" class="inline-flex gap-2 transition-colors duration-150 text-white hover:no-underline hover:text-blue-400"
> >
<svg <svg

View file

@ -14,6 +14,7 @@ import SearchModal from "../ui/SearchModal.astro";
<label <label
class="hamburger-menu flex lg:hidden top-2 left-5" class="hamburger-menu flex lg:hidden top-2 left-5"
aria-label="Menu" aria-label="Menu"
transition:persist="hamburger-menu"
> >
<input type="checkbox" aria-controls="navigation" /> <input type="checkbox" aria-controls="navigation" />
</label> </label>
@ -174,20 +175,22 @@ import SearchModal from "../ui/SearchModal.astro";
</style> </style>
<script is:inline> <script is:inline>
const verticalNavBar = document.getElementById("vertical-navbar");
const hamburgerMenu = document.querySelector(".hamburger-menu input");
// JavaScript for toggling the menu // JavaScript for toggling the menu
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
// Close the menu when a link is clicked // Close the menu when a link is clicked
const navbarLinks = document.querySelectorAll("#vertical-navbar a"); const navbarLinks = document.querySelectorAll("#vertical-navbar a");
navbarLinks.forEach((link) => { navbarLinks.forEach((link) => {
link.addEventListener("click", function () { link.addEventListener("click", function () {
if (verticalNavBar) if (verticalNavBar) hamburgerMenu.checked = false;
verticalNavBar.classList.add("-translate-x-[200%]");
}); });
}); });
}); });
// comment this out if you don't want the search modal document.addEventListener("astro:page-load", () => {
window.addEventListener("DOMContentLoaded", (event) => {
// @ts-ignore // @ts-ignore
new PagefindUI({ new PagefindUI({
element: "#searchModal-search", element: "#searchModal-search",
@ -197,5 +200,7 @@ import SearchModal from "../ui/SearchModal.astro";
showImages: false, showImages: false,
autofocus: false, autofocus: false,
}); });
if (hamburgerMenu) hamburgerMenu.checked = false;
}); });
</script> </script>

View file

@ -164,17 +164,22 @@ const { showHome } = Astro.props;
link.classList.add("text-gray-400"); link.classList.add("text-gray-400");
} }
}); });
// close dialog
const dialog = document.querySelector("dialog");
if (dialog) {
dialog.close();
}
}); });
window.addEventListener("DOMContentLoaded", (event) => { // @ts-ignore
// @ts-ignore new PagefindUI({
new PagefindUI({ element: "#vertical-search",
element: "#vertical-search", showSubResults: false,
showSubResults: false, showEmptyFilters: false,
showEmptyFilters: false, debounceTimeoutMs: 0,
debounceTimeoutMs: 0, showImages: false,
showImages: false, autofocus: false,
autofocus: false,
});
}); });
</script> </script>

View file

@ -50,11 +50,5 @@ const { id } = Astro.props;
</svg> </svg>
</button> </button>
</form> </form>
<div <div id=`${id}-search` class="mt-2"></div>
id=`${id}-search`
class="mt-2"
transition:name="search"
transition:persist
>
</div>
</dialog> </dialog>