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

feat(v2): auto-generated sidebars, frontmatter-less sites #4582

Merged
merged 53 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
46fb9ca
POC of autogenerated sidebars
slorber Apr 6, 2021
749a251
use combine-promises utility lib
slorber Apr 7, 2021
c81da98
autogenerated sidebar poc working
slorber Apr 7, 2021
b39231f
Revert "autogenerated sidebar poc working"
slorber Apr 7, 2021
e4dd084
POC of auto-generated sidebars for community docs
slorber Apr 7, 2021
c285c65
update tests
slorber Apr 7, 2021
69da2a1
add initial test suite for autogenerated sidebars + fix some edge cases
slorber Apr 8, 2021
9a6904b
Improve autogen sidebars: strip more number prefixes in folder breadc…
slorber Apr 8, 2021
15e3f4b
fix typo!
slorber Apr 8, 2021
6034b64
Add tests for partially generated sidebars + fix edge cases + extract…
slorber Apr 8, 2021
5224653
Ability to read category metadatas file from a file in the category
slorber Apr 8, 2021
3175db0
Merge branch 'master' into slorber/autogen-sidebars
slorber Apr 9, 2021
1bd562b
fix tests
slorber Apr 10, 2021
abf9b0b
change position of API
slorber Apr 10, 2021
3d55863
ability to extract number prefix
slorber Apr 10, 2021
d49d2e3
stable system to enable position frontmatter
slorber Apr 10, 2021
5a4487d
fix tests for autogen sidebar position
slorber Apr 11, 2021
69c83ea
Merge branch 'master' into slorber/autogen-sidebars
slorber Apr 13, 2021
58fa9a2
renamings
slorber Apr 13, 2021
0f96a74
restore community sidebars
slorber Apr 13, 2021
e41b43f
rename frontmatter position -> sidebar_position
slorber Apr 13, 2021
732b25c
make sidebarItemsGenerator fn configurable
slorber Apr 13, 2021
e5e48ae
minor changes
slorber Apr 13, 2021
6d3ded3
rename dirPath => dirName
slorber Apr 13, 2021
56d2e75
Make the init template use autogenerated sidebars
slorber Apr 13, 2021
f3f3d12
fix options
slorber Apr 13, 2021
0f225d9
fix docusaurus site: remove test docs
slorber Apr 13, 2021
77e61da
add _category_ file to docs pathsToWatch
slorber Apr 13, 2021
eceb7ad
add _category_ file to docs pathsToWatch
slorber Apr 13, 2021
6c57520
tutorial: use sidebar_position instead of file number prefixes
slorber Apr 13, 2021
61bfa2e
Adapt Docusaurus tutorial for autogenerated sidebars
slorber Apr 13, 2021
117c528
remove slug: /
slorber Apr 13, 2021
6ef4a61
polish the homepage template
slorber Apr 13, 2021
8a11816
rename _category_ sidebar_position to just "position"
slorber Apr 13, 2021
cbfab8c
test for custom sidebarItemsGenerator fn
slorber Apr 13, 2021
1ace81e
fix category metadata + add link to report tutorial issues
slorber Apr 13, 2021
3a27c3e
Merge branch 'master' into slorber/autogen-sidebars
slorber Apr 14, 2021
177a41a
fix absolute path breaking tests
slorber Apr 14, 2021
35282fa
fix absolute path breaking tests
slorber Apr 14, 2021
db806b1
Add test for floating number sidebar_position
slorber Apr 14, 2021
1a48e23
add sidebarItemsGenerator unit tests
slorber Apr 14, 2021
c7d09e6
add processSidebars unit tests
slorber Apr 14, 2021
9705029
Fix init template broken links
slorber Apr 14, 2021
2f5fdd4
windows test
slorber Apr 14, 2021
727903d
increase code translations test timeout
slorber Apr 14, 2021
7ca2ff7
cleanup mockCategoryMetadataFiles after windows test fixed
slorber Apr 14, 2021
4662610
Merge branch 'master' into slorber/autogen-sidebars
slorber Apr 14, 2021
cee22a7
update init template positions
slorber Apr 14, 2021
5acb3d1
fix windows tests
slorber Apr 14, 2021
827a4cb
fix comment
slorber Apr 14, 2021
e240448
Add autogenerated sidebar items documentation + rewrite the full side…
slorber Apr 15, 2021
87102f6
add useful comment
slorber Apr 15, 2021
f23e823
fix code block title
slorber Apr 15, 2021
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
title: Getting Started
slug: /
sidebar_position: 1
---

Get started by **creating a new site**
# Tutorial Intro

Or **try Docusaurus immediately** with **[new.docusaurus.io](https://new.docusaurus.io)** (CodeSandbox).
Let's discover **Docusaurus in less than 5 minutes**.

## Getting Started

Get started by **creating a new site**.

Or **try Docusaurus immediately** with **[new.docusaurus.io](https://new.docusaurus.io)**.

## Generate a new site

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Tutorial - Basics",
"position": 2
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
title: Congratulations!
sidebar_position: 6
---

Congratulations on making it this far!
# Congratulations!

You have learned the **basics of Docusaurus** and made some changes to the **initial template**.
You have just learned the **basics of Docusaurus** and made some changes to the **initial template**.

Docusaurus has **much more to offer**!

Have 5 more minutes? Take a look at **[versioning](./manage-docs-versions.md)** and **[i18n](./translate-your-site.md)**.
Have **5 more minutes**? Take a look at **[versioning](../tutorial-extras/manage-docs-versions.md)** and **[i18n](../tutorial-extras/translate-your-site.md)**.

Anything **unclear** or **buggy** in this tutorial? [Please report it!](https://github.com/facebook/docusaurus/discussions/4610)

## What's next?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
title: Create a Blog Post
sidebar_position: 3
---

# Create a Blog Post

Docusaurus creates a **page for each blog post**, but also a **blog index page**, a **tag system**, an **RSS** feed...

## Create a Blog Post
## Create your first Post

Create a file at `blog/2021-02-28-greetings.md`:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
sidebar_position: 2
---

# Create a Document

Documents are **groups of pages** connected through:

- a **sidebar**
- **previous/next navigation**
- **versioning**

## Create your first Doc

Create a markdown file at `docs/hello.md`:

```md title="docs/hello.md"
# Hello

This is my **first Docusaurus document**!
```

A new document is now available at `http://localhost:3000/docs/hello`.

## Configure the Sidebar

Docusaurus automatically **creates a sidebar** from the `docs` folder.

Add metadatas to customize the sidebar label and position:

```diff title="docs/hello.md"
+ ---
+ sidebar_label: "Hi!"
+ sidebar_position: 3
+ ---


# Hello

This is my **first Docusaurus document**!
```

It is also possible to create your sidebar explicitly in `sidebars.js`:

```diff title="sidebars.js"
module.exports = {
tutorialSidebar: [
{
type: 'category',
label: 'Tutorial',
- items: [...],
+ items: ['hello'],
},
],
};
```
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
title: Create a Page
sidebar_position: 1
---

Add **Markdown or React** files to `src/pages` to create **standalone pages**:
# Create a Page

Add **Markdown or React** files to `src/pages` to create a **standalone page**:

- `src/pages/index.js` -> `localhost:3000/`
- `src/pages/foo.md` -> `localhost:3000/foo`
- `src/pages/foo/bar.js` -> `localhost:3000/foo/bar`

## Create a React Page
## Create your first React Page

Create a file at `src/pages/my-react-page.js`:

Expand All @@ -28,15 +30,11 @@ export default function MyReactPage() {

A new page is now available at `http://localhost:3000/my-react-page`.

## Create a Markdown Page
## Create your first Markdown Page

Create a file at `src/pages/my-markdown-page.md`:

```mdx title="src/pages/my-markdown-page.md"
---
title: My Markdown page
---

# My Markdown page

This is a Markdown page
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
title: Deploy your site
sidebar_position: 5
---

Docusaurus is a **static-site-generator** (also called [Jamstack](https://jamstack.org/)), and builds your site as **static HTML, JavaScript and CSS files**.
# Deploy your site

Docusaurus is a **static-site-generator** (also called **[Jamstack](https://jamstack.org/)**).

It builds your site as simple **static HTML, JavaScript and CSS files**.

## Build your site

Expand All @@ -12,7 +16,7 @@ Build your site **for production**:
npm run build
```

The static files are generated in the `build` directory.
The static files are generated in the `build` folder.

## Deploy your site

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---
title: Markdown Features
sidebar_position: 4
---

# Markdown Features

Docusaurus supports **[Markdown](https://daringfireball.net/projects/markdown/syntax)** and a few **additional features**.

## Front Matter

Markdown documents have metadata at the very top called [Front Matter](https://jekyllrb.com/docs/front-matter/):
Markdown documents have metadata at the top called [Front Matter](https://jekyllrb.com/docs/front-matter/):

```md
```text title="my-doc.md"
// highlight-start
---
id: my-doc
id: my-doc-id
title: My document title
description: My document description
sidebar_label: My doc
slug: /my-custom-url
---
// highlight-end

## Markdown heading

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Tutorial - Extras",
"position": 3
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
title: Manage Docs Versions
sidebar_position: 1
---

# Manage Docs Versions

Docusaurus can manage multiple versions of your docs.

## Create a docs version
Expand All @@ -12,7 +14,7 @@ Release a version 1.0 of your project:
npm run docusaurus docs:version 1.0
```

The `docs` directory is copied into `versioned_docs/version-1.0` and `versions.json` is created.
The `docs` folder is copied into `versioned_docs/version-1.0` and `versions.json` is created.

Your docs now have 2 versions:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
title: Translate your site
sidebar_position: 2
---

# Translate your site

Let's translate `docs/getting-started.md` to French.

## Configure i18n
Expand All @@ -19,7 +21,7 @@ module.exports = {

## Translate a doc

Copy the `docs/getting-started.md` file to the `i18n/fr` directory:
Copy the `docs/getting-started.md` file to the `i18n/fr` folder:

```bash
mkdir -p i18n/fr/docusaurus-plugin-content-docs/current/
Expand All @@ -39,7 +41,7 @@ npm run start -- --locale fr

Your localized site is accessible at `http://localhost:3000/fr/` and the `Getting Started` page is translated.

:::warning
:::caution

In development, you can only use one locale at a same time.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
items: [
{
type: 'doc',
docId: 'getting-started',
docId: 'intro',
position: 'left',
label: 'Tutorial',
},
Expand All @@ -38,8 +38,8 @@ module.exports = {
title: 'Docs',
items: [
{
label: 'Getting Started',
to: '/docs/',
label: 'Tutorial',
to: '/docs/intro',
},
],
},
Expand Down
36 changes: 20 additions & 16 deletions packages/docusaurus-init/templates/classic/sidebars.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/**
* Creating a sidebar enables you to:
- create an ordered group of docs
- render a sidebar for each doc of that group
- provide next/previous navigation

The sidebars can be generated from the filesystem, or explicitly defined here.

Create as many sidebars as you want.
*/

module.exports = {
tutorial: [
// By default, Docusaurus generates a sidebar from the docs folder structure
tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],

// But you can create a sidebar manually
/*
tutorialSidebar: [
{
type: 'category',
label: 'Tutorial - Basics',
items: [
'getting-started',
'create-a-page',
'create-a-document',
'create-a-blog-post',
'markdown-features',
'deploy-your-site',
'congratulations',
],
},
{
type: 'category',
label: 'Tutorial - Extras',
items: ['manage-docs-versions', 'translate-your-site'],
label: 'Tutorial',
items: ['hello'],
},
],
*/
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ function Feature({Svg, title, description}) {
<div className="text--center">
<Svg className={styles.featureSvg} alt={title} />
</div>
<h3>{title}</h3>
<p>{description}</p>
<div className="text--center padding-horiz--md">
<h3>{title}</h3>
<p>{description}</p>
</div>
</div>
);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/docusaurus-init/templates/classic/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ function HomepageHeader() {
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div className={styles.buttons}>
<Link className="button button--secondary button--lg" to="/docs">
Get Started - Docusaurus Tutorial
<Link
className="button button--secondary button--lg"
to="/docs/intro">
Docusaurus Tutorial - 5min ⏱️
</Link>
</div>
</div>
Expand Down
Loading