-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Navbar Component with nav links generated from pages
- Loading branch information
Showing
11 changed files
with
126 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ | |
"prettier --write --ignore-unknown --plugin-search-dir=. ." | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
type NavLinkProp = { | ||
href: string | ||
label: string | ||
active?: boolean | ||
} | ||
const { label, href, active } = Astro.props as NavLinkProp | ||
--- | ||
|
||
<a | ||
class:list={['hover:text-juxt transition-colors', { 'text-juxt': active }]} | ||
href={href} | ||
> | ||
{label} | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
import logo from '../assets/images/logo.svg' | ||
import { removeLeadingSlash } from '../utils' | ||
import NavLink from './NavLink.astro' | ||
const url = new URL(Astro.request.url) | ||
const currentPage = url.pathname | ||
type PageProps = { | ||
metadata?: { navbar?: { weight?: number; label?: string } } | ||
url: string | ||
} | ||
const pages = await Astro.glob<PageProps>('../pages/**/*.astro') | ||
const pagesInNavbar = pages | ||
.filter((page) => page?.metadata?.navbar) | ||
.map((page) => ({ | ||
url: page.url, | ||
weight: page.metadata?.navbar?.weight, | ||
label: page.metadata?.navbar?.label || removeLeadingSlash(page.url), | ||
active: page.url === currentPage | ||
})) | ||
.sort((a, b) => a.weight - b.weight) | ||
--- | ||
|
||
<nav class='w-full bg-black h-14'> | ||
<div | ||
class='container mx-auto px-2 sm:px-12 2xl:px-0 max-w-6xl flex items-center justify-between h-full' | ||
> | ||
<a href='/' class='flex items-center'> | ||
<img src={logo} width='80px' alt='Juxt Logo' /> | ||
</a> | ||
<div | ||
class='flex items-center gap-8 uppercase tracking-widest text-xs text-white' | ||
> | ||
{pagesInNavbar.map((page) => ( | ||
<NavLink href={page.url} label={page.label} active={page.active} /> | ||
))} | ||
</div> | ||
</div> | ||
</nav> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import Layout from '../layouts/Layout.astro' | ||
export const metadata = { navbar: { weight: 1 } } | ||
--- | ||
|
||
<Layout navbar={true}> | ||
<main>about page here</main> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import Layout from '../layouts/Layout.astro' | ||
export const metadata = { navbar: { weight: 2 } } | ||
--- | ||
|
||
<Layout title='Technology' navbar={true}> | ||
<main>technolgoy page here</main> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** Remove \ and / from beginning of string */ | ||
export function removeLeadingSlash(path: string) { | ||
return path.replace(/^[/\\]+/, ""); | ||
} | ||
|
||
/** Remove \ and / from end of string */ | ||
export function removeTrailingSlash(path: string) { | ||
return path.replace(/[/\\]+$/, ""); | ||
} | ||
|
||
// capitalize first letter of string | ||
export function capitalizeFirstLetter(str: string) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters