Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clicking on folder should navigate to first children if index page doesn't exist #724

Merged
merged 20 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/poor-rivers-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'nextra': patch
'nextra-theme-docs': patch
---

rename `meta.json` to `_meta.json`
5 changes: 5 additions & 0 deletions .changeset/proud-phones-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra-theme-docs': patch
---

clicking on folder should navigate to first children if `index` page doesn't exist
7 changes: 7 additions & 0 deletions .changeset/tall-cows-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra': patch
'nextra-theme-blog': patch
'nextra-theme-docs': patch
---

rename `PageOpts.meta` to `PageOpts.frontMatter`
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/swr-site/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ const config: DocsThemeConfig = {
head() {
const config = useConfig();
const description =
config.meta.description ||
config.frontMatter.description ||
"SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.";
const image =
config.meta.image ||
config.frontMatter.image ||
"https://assets.vercel.com/image/upload/v1572282926/swr/twitter-card.jpg";
return (
<>
Expand Down
6 changes: 3 additions & 3 deletions packages/nextra-theme-blog/__test__/__fixture__/pageMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BlogPageOpts } from '../../src/types'
export const indexOpts: BlogPageOpts = {
filePath: 'index.mdx',
route: '/',
meta: {
frontMatter: {
type: 'page',
title: 'About',
date: '2020-01-01T00:00:00.000Z'
Expand Down Expand Up @@ -105,7 +105,7 @@ export const indexOpts: BlogPageOpts = {
export const postsOpts: BlogPageOpts = {
filePath: 'index.md',
route: '/posts',
meta: {
frontMatter: {
type: 'posts',
title: 'Random Thoughts',
date: '2020-01-03T00:00:00.000Z'
Expand Down Expand Up @@ -208,7 +208,7 @@ export const postsOpts: BlogPageOpts = {
export const articleOpts: BlogPageOpts = {
filePath: 'aaron-swartz-a-programmable-web.mdx',
route: '/posts/aaron-swartz-a-programmable-web',
meta: {
frontMatter: {
title: 'Notes on A Programmable Web by Aaron Swartz',
date: '2016/5/21',
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-blog/src/article-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ArticleLayout = ({ children }: { children: ReactNode }) => {
const { back } = getParent({ opts, config })
return (
<BasicLayout>
<Meta {...opts.meta} back={back} config={config} />
<Meta {...opts.frontMatter} back={back} config={config} />
<MDXTheme>
{children}
{config.postFooter}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-blog/src/basic-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const BasicLayout = ({ children }: { children: ReactNode }) => {
<article className="container prose prose-sm dark:prose-dark md:prose">
<Head>
<title>{title}</title>
{config.head?.({ title, meta: opts.meta })}
{config.head?.({ title, meta: opts.frontMatter })}
</Head>
<HeadingContext.Provider value={ref}>
{opts.hasJsxInH1 ? <h1 ref={ref} /> : null}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-blog/src/blog-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const BlogProvider = ({
children,
opts
}: LayoutProps & { children: ReactNode }): ReactElement => {
const { date } = opts.meta
const { date } = opts.frontMatter

if (date && !isValidDate(date)) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-blog/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BlogLayout = ({
children,
opts
}: LayoutProps & { children: ReactNode }): ReactElement => {
const type = opts.meta.type || 'post'
const type = opts.frontMatter.type || 'post'
const Layout = layoutMap[type]
if (!Layout) {
throw new Error(
Expand Down
4 changes: 1 addition & 3 deletions packages/nextra-theme-blog/src/posts-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export const PostsLayout = ({ children }: { children: ReactNode }) => {
const { config, opts } = useBlogContext()
const { posts } = collectPostsAndNavs({ config, opts })
const router = useRouter()
const {
meta: { type }
} = opts
const { type } = opts.frontMatter
const tagName = type === 'tag' ? router.query.tag : null
const postList = posts.map(post => {
if (tagName) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface NextraBlogTheme {
}

export interface BlogPageOpts extends PageOpts {
meta: Meta
frontMatter: Meta
}

type Meta = {
Expand Down
Loading