Skip to content

Commit

Permalink
feat(v2): Improve the initial templates #4302 (#4320)
Browse files Browse the repository at this point in the history
* feat: add getting started doc at classic inital templates

* fix: improve the contents of getting started page

* fix: fix slug routing

* fix: rename gettingStarted to getting-started and re-adjust the content

* feat: add markdown-features docs

* feat: add a page on how to create a simple document

* feat: add a page on how to create pages

* feat: add create a post doc

* feat: add thank you page with whats next

* feat : update sidebar.js

* feat : add introduction content

* feat : add self hosting content

* feat : add GitHub pages content

* fix : remove automatically deploying with github actions content

* feat : add deploying to netlify

* feat : add Translate your site

* add : Manage versions

* fix : formatted docs with prettier

* Revert "fix : formatted docs with prettier"

This reverts commit af8c0b4

* run prettier to init templates with fixes

* complete new init template

* rename manage-docs-versions

* change wording

* refresh config file

* rework init template homepage

* minor changes

Co-authored-by: Lisa Chandra <52909743+lisa761@users.noreply.github.com>
Co-authored-by: Javid <singularity.javid@gmail.com>
Co-authored-by: ShinteiMai <stevenhanselgo@gmail.com>
Co-authored-by: slorber <lorber.sebastien@gmail.com>
  • Loading branch information
5 people authored Mar 17, 2021
1 parent d5cad5b commit b99a403
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 145 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ packages/docusaurus-*/lib/*
packages/docusaurus-1.x/lib/core/metadata.js
packages/docusaurus-1.x/lib/core/MetadataBlog.js
packages/docusaurus-*/lib-next/
packages/docusaurus-init/templates/**/*.md
__fixtures__
19 changes: 19 additions & 0 deletions packages/docusaurus-init/templates/classic/docs/congratulations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Congratulations!
---

Congratulations on making it this far!

You have 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)**.

## What's next?

- Read the [official documentation](https://v2.docusaurus.io/).
- Add a custom [Design and Layout](https://v2.docusaurus.io/docs/styling-layout)
- Add a [search bar](https://v2.docusaurus.io/docs/search)
- Find inspirations in the [Docusaurus showcase](https://v2.docusaurus.io/showcase)
- Get involved in the [Docusaurus Community](https://v2.docusaurus.io/community/support)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Create a Blog Post
---

This page will help you on how to create blog posts in Docusaurus.
Docusaurus creates a **page for each blog post**, but also a **blog index page**, a **tag system**, an **RSS** feed...

## Create a Blog Post

Expand All @@ -15,6 +15,7 @@ author: Steven Hansel
author_title: Docusaurus Contributor
author_url: https://github.com/ShinteiMai
author_image_url: https://github.com/ShinteiMai.png
tags: [greetings]
---

Congratulations, you have made your first post!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Create a Document
---

Documents are pages with a **sidebar**, a **previous/next navigation** and many other useful features.
Documents are a **group of pages** connected through a **sidebar**, a **previous/next navigation** and **versioning**.

## Create a Document

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Create a Page
---

Any React or Markdown file created under `src/pages` directory is converted into a website page:
Add **Markdown or React** files to `src/pages` to create **standalone pages**:

- `src/pages/index.js` -> `localhost:3000/`
- `src/pages/foo.md` -> `localhost:3000/foo`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Deploy your site
---

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

## Build your site

Build your site **for production**:

```bash
npm run build
```

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

## Deploy your site

Test your production build locally:

```bash
npm run serve
```

The `build` folder is now served at `http://localhost:3000/`.

You can now deploy the `build` folder **almost anywhere** easily, **for free** or very small cost (read the **[Deployment Guide](https://v2.docusaurus.io/docs/deployment)**).
18 changes: 10 additions & 8 deletions packages/docusaurus-init/templates/classic/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ title: Getting Started
slug: /
---

## Step 1: Generate a new Docusaurus site
Get started by **creating a new site**

If you haven't already, generate a new Docusaurus site using the classic template:
Or **try Docusaurus immediately** with **[new.docusaurus.io](https://new.docusaurus.io)** (CodeSandbox).

## Generate a new site

Generate a new Docusaurus site using the **classic template**:

```shell
npx @docusaurus/init@latest init my-website classic
```

## Step 2: Start your Docusaurus site
## Start your site

Run the development server in the newly created `my-website` folder:
Run the development server:

```shell
cd my-website

npx docusaurus start
```

Open `docs/getting-started.md` and edit some lines. The site reloads automatically and display your changes.

## That's it!
Your site starts at `http://localhost:3000`.

Congratulations! You've successfully run and modified your Docusaurus project.
Open `docs/getting-started.md` and edit some lines: the site **reloads automatically** and display your changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Manage Docs Versions
---

Docusaurus can manage multiple versions of your docs.

## Create a docs version

Release a version 1.0 of your project:

```bash
npm run docusaurus docs:version 1.0
```

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

Your docs now have 2 versions:

- `1.0` at `http://localhost:3000/docs/` for the version 1.0 docs
- `current` at `http://localhost:3000/docs/next/` for the **upcoming, unreleased docs**

## Add a Version Dropdown

To navigate seamlessly across versions, add a version dropdown.

Modify the `docusaurus.config.js` file:

```js title="docusaurus.config.js"
module.exports = {
themeConfig: {
navbar: {
items: [
// highlight-start
{
type: 'docsVersionDropdown',
},
// highlight-end
],
},
},
};
```

The docs version dropdown appears in your navbar:

![Docs Version Dropdown](/img/tutorial/docsVersionDropdown.png)

## Update an existing version

It is possible to edit versioned docs in their respective folder:

- `versioned_docs/version-1.0/hello.md` updates `http://localhost:3000/docs/hello`
- `docs/hello.md` updates `http://localhost:3000/docs/next/hello`
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: Markdown Features
---

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

## Front Matter

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

```md
---
Expand All @@ -16,12 +16,14 @@ description: My document description
sidebar_label: My doc
---

Markdown content
## Markdown heading

Markdown text with [links](./hello.md)
```

## Markdown links
## Links

Regular Markdown links are supported using url paths or relative file paths.
Regular Markdown links are supported, using url paths or relative file paths.

```md
Let's see how to [Create a page](/create-a-page).
Expand All @@ -31,13 +33,13 @@ Let's see how to [Create a page](/create-a-page).
Let's see how to [Create a page](./create-a-page.md).
```

Let's see how to [Create a page](./create-a-page.md).
**Result:** Let's see how to [Create a page](./create-a-page.md).

## Markdown images
## Images

Regular Markdown images are supported.

Add an image at `static/img/docusaurus.png` and use this Markdown declaration:
Add an image at `static/img/docusaurus.png` and display it in Markdown:

```md
![Docusaurus logo](/img/docusaurus.png)
Expand Down Expand Up @@ -91,38 +93,48 @@ This action is dangerous

:::

## React components
## MDX and React Components

Thanks to [MDX](https://mdxjs.com/), you can make your doc more interactive and use React components inside Markdown:
[MDX](https://mdxjs.com/) can make your documentation more **interactive** and allows using any **React components inside Markdown**:

```jsx
export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
color: 'red',
padding: '0.2rem',
borderRadius: '20px',
color: '#fff',
padding: '10px',
cursor: 'pointer',
}}
onClick={() => {
alert(`You clicked the color ${color} with label ${children}`)
}}>
{children}
</span>
);

<Highlight color="#25c2a0">Docusaurus green</Highlight> and <Highlight color="#1877F2">Facebook blue</Highlight> are my favorite colors.
This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !

This is <Highlight color="#1877F2">Facebook blue</Highlight> !
```

export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
borderRadius: '20px',
color: '#fff',
padding: '0.2rem',
padding: '10px',
cursor: 'pointer',
}}
onClick={() => {
alert(`You clicked the color ${color} with label ${children}`);
}}>
{children}
</span>
);

<Highlight color="#25c2a0">Docusaurus green</Highlight> and <Highlight color="#1877F2">
Facebook blue
</Highlight> are my favorite colors.
This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !

This is <Highlight color="#1877F2">Facebook blue</Highlight> !
17 changes: 0 additions & 17 deletions packages/docusaurus-init/templates/classic/docs/thank-you.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: Translate your site
---

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

## Configure i18n

Modify `docusaurus.config.js` to add support for the `fr` locale:

```js title="docusaurus.config.js"
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
},
};
```

## Translate a doc

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

```bash
mkdir -p i18n/fr/docusaurus-plugin-content-docs/current/

cp docs/getting-started.md i18n/fr/docusaurus-plugin-content-docs/current/getting-started.md
```

Translate `i18n/fr/docusaurus-plugin-content-docs/current/getting-started.md` in French.

## Start your localized site

Start your site on the French locale:

```bash
npm run start -- --locale fr
```

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

:::warning

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

:::

## Add a Locale Dropdown

To navigate seamlessly across languages, add a locale dropdown.

Modify the `docusaurus.config.js` file:

```js title="docusaurus.config.js"
module.exports = {
themeConfig: {
navbar: {
items: [
// highlight-start
{
type: 'localeDropdown',
},
// highlight-end
],
},
},
};
```

The locale dropdown now appears in your navbar:

![Locale Dropdown](/img/tutorial/localeDropdown.png)

## Build your localized site

Build your site for a specific locale:

```bash
npm run build -- --locale fr
```

Or build your site to include all the locales at once:

```bash
npm run build
```
Loading

0 comments on commit b99a403

Please sign in to comment.