Skip to content

Commit

Permalink
define page title in sidebar from frontMatter.title if page is not …
Browse files Browse the repository at this point in the history
…specified in `_meta.json` (#755)

* define page title in sidebar from `frontMatter.title` if page is not specified in `_meta.json`

* fix typecheck

* Update packages/nextra-theme-blog/src/utils/parent.ts

* remove sortDate

* `addPage` no longer need accept `frontMatter` (#789)

* update snapshots
  • Loading branch information
dimaMachina committed Sep 2, 2022
1 parent c3e6227 commit e4cfb83
Show file tree
Hide file tree
Showing 25 changed files with 1,381 additions and 420 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-keys-matter.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

`addPage` no longer need accept `frontMatter`
6 changes: 6 additions & 0 deletions .changeset/eighty-otters-build.md
@@ -0,0 +1,6 @@
---
'nextra': patch
'nextra-theme-docs': patch
---

define page title in sidebar from `frontMatter.title` if page is not specified in `_meta.json`
21 changes: 20 additions & 1 deletion packages/nextra-theme-blog/__test__/__fixture__/pageMap.ts
@@ -1,4 +1,5 @@
import { BlogPageOpts } from '../../src/types'
import { BlogPageOpts } from '../../src'

export const indexOpts: BlogPageOpts = {
filePath: 'index.mdx',
route: '/',
Expand All @@ -9,6 +10,7 @@ export const indexOpts: BlogPageOpts = {
},
pageMap: [
{
kind: 'MdxPage',
name: 'index',
route: '/',
locale: '',
Expand All @@ -19,9 +21,11 @@ export const indexOpts: BlogPageOpts = {
}
},
{
kind: 'Folder',
name: 'posts',
children: [
{
kind: 'MdxPage',
name: 'aaron-swartz-a-programmable-web',
route: '/posts/aaron-swartz-a-programmable-web',
locale: '',
Expand All @@ -35,6 +39,7 @@ export const indexOpts: BlogPageOpts = {
}
},
{
kind: 'MdxPage',
name: 'index',
route: '/posts',
locale: '',
Expand All @@ -48,9 +53,11 @@ export const indexOpts: BlogPageOpts = {
route: '/posts'
},
{
kind: 'Folder',
name: 'tags',
children: [
{
kind: 'MdxPage',
name: '[tag]',
route: '/tags/[tag]',
locale: '',
Expand Down Expand Up @@ -112,6 +119,7 @@ export const postsOpts: BlogPageOpts = {
},
pageMap: [
{
kind: 'MdxPage',
name: 'index',
route: '/',
locale: '',
Expand All @@ -122,9 +130,11 @@ export const postsOpts: BlogPageOpts = {
}
},
{
kind: 'Folder',
name: 'posts',
children: [
{
kind: 'MdxPage',
name: 'aaron-swartz-a-programmable-web',
route: '/posts/aaron-swartz-a-programmable-web',
locale: '',
Expand All @@ -138,6 +148,7 @@ export const postsOpts: BlogPageOpts = {
}
},
{
kind: 'MdxPage',
name: 'index',
route: '/posts',
locale: '',
Expand All @@ -151,9 +162,11 @@ export const postsOpts: BlogPageOpts = {
route: '/posts'
},
{
kind: 'Folder',
name: 'tags',
children: [
{
kind: 'MdxPage',
name: '[tag]',
route: '/tags/[tag]',
locale: '',
Expand Down Expand Up @@ -218,6 +231,7 @@ export const articleOpts: BlogPageOpts = {
},
pageMap: [
{
kind: 'MdxPage',
name: 'index',
route: '/',
locale: '',
Expand All @@ -228,9 +242,11 @@ export const articleOpts: BlogPageOpts = {
}
},
{
kind: 'Folder',
name: 'posts',
children: [
{
kind: 'MdxPage',
name: 'aaron-swartz-a-programmable-web',
route: '/posts/aaron-swartz-a-programmable-web',
locale: '',
Expand All @@ -244,6 +260,7 @@ export const articleOpts: BlogPageOpts = {
}
},
{
kind: 'MdxPage',
name: 'index',
route: '/posts',
locale: '',
Expand All @@ -257,9 +274,11 @@ export const articleOpts: BlogPageOpts = {
route: '/posts'
},
{
kind: 'Folder',
name: 'tags',
children: [
{
kind: 'MdxPage',
name: '[tag]',
route: '/tags/[tag]',
locale: '',
Expand Down
237 changes: 123 additions & 114 deletions packages/nextra-theme-blog/__test__/collect.spec.ts
Expand Up @@ -11,136 +11,145 @@ describe('collect', () => {
it('page', () => {
expect(collectPostsAndNavs({ opts: indexOpts, config }))
.toMatchInlineSnapshot(`
{
"navPages": [
{
"active": false,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
{
"navPages": [
{
"active": false,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/posts",
},
"locale": "",
"name": "index",
"route": "/posts",
},
{
"active": true,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
{
"active": true,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/",
},
"locale": "",
"name": "index",
"route": "/",
},
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
},
"kind": "MdxPage",
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
],
}
`)
],
}
`)
})
it('posts', () => {
expect(collectPostsAndNavs({ opts: postsOpts, config }))
.toMatchInlineSnapshot(`
{
"navPages": [
{
"active": true,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
{
"navPages": [
{
"active": true,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/posts",
},
"locale": "",
"name": "index",
"route": "/posts",
},
{
"active": false,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
{
"active": false,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/",
},
"locale": "",
"name": "index",
"route": "/",
},
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
},
"kind": "MdxPage",
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
],
}
`)
],
}
`)
})
it('article', () => {
expect(collectPostsAndNavs({ opts: articleOpts, config }))
.toMatchInlineSnapshot(`
{
"navPages": [
{
"active": false,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
{
"navPages": [
{
"active": false,
"frontMatter": {
"date": "2020-01-03T00:00:00.000Z",
"title": "Random Thoughts",
"type": "posts",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/posts",
},
"locale": "",
"name": "index",
"route": "/posts",
},
{
"active": false,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
{
"active": false,
"frontMatter": {
"date": "2020-01-01T00:00:00.000Z",
"title": "About",
"type": "page",
},
"kind": "MdxPage",
"locale": "",
"name": "index",
"route": "/",
},
"locale": "",
"name": "index",
"route": "/",
},
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
],
"posts": [
{
"frontMatter": {
"author": "Shu",
"date": "2016/5/21",
"description": "At the time when I was getting into web development, I had the chance to read one of the most inspiring book about the web, Aaron Swartz's A Programmable Web. And it completely changed my mind.",
"tag": "web development",
"title": "Notes on A Programmable Web by Aaron Swartz",
},
"kind": "MdxPage",
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
"locale": "",
"name": "aaron-swartz-a-programmable-web",
"route": "/posts/aaron-swartz-a-programmable-web",
},
],
}
`)
],
}
`)
})
})

0 comments on commit e4cfb83

Please sign in to comment.