Skip to content

Commit

Permalink
Merge pull request #393 from shuding/shu/4747
Browse files Browse the repository at this point in the history
Options for hiding/adding a link
  • Loading branch information
shuding authored Mar 6, 2022
2 parents 7a7ba2a + 2923570 commit c21010b
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 140 deletions.
11 changes: 10 additions & 1 deletion examples/swr-site/pages/docs/meta.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
"options": "Options",
"global-configuration": "Global Configuration",
"data-fetching": "Data Fetching",
"error-handling": "Error Handling",
"error-handling": {
"title": "Error Handling",
"hidden": true
},
"github_link": {
"title": "GitHub 🐙 →",
"href": "https://github.com/shuding/nextra",
"type": "page",
"newWindow": true
},
"revalidation": "Auto Revalidation",
"conditional-fetching": "Conditional Data Fetching",
"arguments": "Arguments",
Expand Down
6 changes: 6 additions & 0 deletions examples/swr-site/pages/meta.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"sidebar": true
}
},
"nextra_link": {
"title": "Nextra ↗",
"href": "https://github.com/shuding/nextra",
"type": "page",
"newWindow": true
},
"examples": {
"title": "Examples",
"type": "page",
Expand Down
4 changes: 2 additions & 2 deletions packages/nextra-theme-docs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Layout: React.FC<LayoutProps> = ({
activeIndex,
activeThemeContext,
// pageDirectories,
flatPageDirectories,
topLevelPageItems,
docsDirectories,
flatDirectories,
flatDocsDirectories,
Expand Down Expand Up @@ -133,7 +133,7 @@ const Layout: React.FC<LayoutProps> = ({
<Navbar
isRTL={isRTL}
flatDirectories={flatDirectories}
flatPageDirectories={flatPageDirectories}
items={topLevelPageItems}
/>
) : null}
<ActiveAnchor>
Expand Down
16 changes: 8 additions & 8 deletions packages/nextra-theme-docs/src/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import { Item, PageItem } from './utils/normalize-pages'
interface NavBarProps {
isRTL?: boolean | null
flatDirectories: Item[]
flatPageDirectories: PageItem[]
items: PageItem[]
}

export default function Navbar({
flatDirectories,
flatPageDirectories
}: NavBarProps) {
export default function Navbar({ flatDirectories, items }: NavBarProps) {
const config = useConfig()
const { locale, asPath } = useRouter()
const activeRoute = getFSRoute(asPath, locale)
Expand All @@ -41,11 +38,11 @@ export default function Navbar({
</Link>
</div>

{flatPageDirectories
? flatPageDirectories.map(page => {
{items
? items.map(page => {
if (page.hidden) return null

let href = page.route
let href = page.href || page.route || '#'

// If it's a directory
if (page.children) {
Expand All @@ -64,6 +61,9 @@ export default function Navbar({
isActive ? 'text-current' : 'text-gray-500'
)}
aria-selected={isActive}
{...(page.newWindow
? { target: '_blank', rel: 'noopener noreferrer' }
: {})}
>
{page.title}
</a>
Expand Down
22 changes: 17 additions & 5 deletions packages/nextra-theme-docs/src/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ function File({ item, anchors }: FileProps) {
})
return (
<li className={active ? 'active' : ''}>
<Link href={item.route}>
<a>{title}</a>
<Link href={(item as PageItem).href || item.route}>
<a
{...((item as PageItem).newWindow
? { target: '_blank', rel: 'noopener noreferrer' }
: {})}
>
{title}
</a>
</Link>
<ul>
{anchors.map((_, i) => {
Expand Down Expand Up @@ -132,8 +138,15 @@ function File({ item, anchors }: FileProps) {

return (
<li className={active ? 'active' : ''}>
<Link href={item.route}>
<a onClick={() => setMenu(false)}>{title}</a>
<Link href={(item as PageItem).href || item.route}>
<a
onClick={() => setMenu(false)}
{...((item as PageItem).newWindow
? { target: '_blank', rel: 'noopener noreferrer' }
: {})}
>
{title}
</a>
</Link>
</li>
)
Expand All @@ -143,7 +156,6 @@ interface MenuProps {
anchors: string[]
base?: string
}
const emptyItem: any[] = []
function Menu({ directories, anchors }: MenuProps) {
return (
<ul>
Expand Down
Loading

0 comments on commit c21010b

Please sign in to comment.