diff --git a/.circleci/config.yml b/.circleci/config.yml index 94b29e9786e4..987f4b8674df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,22 +81,22 @@ jobs: if ! git diff-tree --no-commit-id --name-only -r HEAD | grep -E "(^docs\/.*)|(docusaurus-1\.x\/.*)|(website-1\.x\/.*)"; then echo "Skipping deploy. No relevant v1 website files have changed" elif [[ $CIRCLE_PROJECT_USERNAME == "facebook" && -z $CI_PULL_REQUEST && -z $CIRCLE_PR_USERNAME ]]; then - echo "Deploying website..." + echo "Deploying website v1..." + cd website-1.x + # install Docusaurus and generate file of English strings - cd website-1.x && yarn run write-translations - # install Crowdin - sudo apt-get update - sudo apt-get install default-jre rsync - wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb - sudo dpkg -i crowdin.deb - sleep 5 + yarn run write-translations + # upload translation strings and download translations - yarn run crowdin-upload + yarn crowdin-upload + # download only enabled languages - for lang in fr ko ru ro pt-BR zh-CN - do - yarn crowdin-download -l $lang - done + yarn crowdin-download + # for lang in fr ko ru ro pt-BR zh-CN + # do + # yarn crowdin-download -l $lang + # done + # publish GIT_USER=docusaurus-bot USE_SSH=false yarn run publish-gh-pages else @@ -119,4 +119,4 @@ workflows: - deploy-website: requires: - tests - filters: *filter-only-master \ No newline at end of file + filters: *filter-only-master diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000000..99227b6ce8aa --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "Docusaurus Dev Container", + "image": "mcr.microsoft.com/vscode/devcontainers/typescript-node:0-10-buster", + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + "extensions": ["dbaeumer.vscode-eslint"], + "forwardPorts": [3000], + "postCreateCommand": "yarn install" +} diff --git a/.eslintignore b/.eslintignore index c2a430de7e39..48ad73c29313 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ __fixtures__ dist node_modules +.yarn build coverage jest.config.js @@ -8,26 +9,15 @@ jest.transform.js website-1.x/ website/ scripts + +packages/docusaurus/lib/ +packages/docusaurus-*/lib/* +!packages/docusaurus-1.x/lib/* +packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js packages/docusaurus-1.x/lib/core/metadata.js packages/docusaurus-1.x/lib/core/MetadataBlog.js -packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js -packages/docusaurus-utils/lib/ -packages/docusaurus-utils-validation/lib/ -packages/docusaurus/lib/ -packages/docusaurus-init/lib/ -packages/docusaurus-plugin-client-redirects/lib/ -packages/docusaurus-plugin-content-blog/lib/ -packages/docusaurus-plugin-content-docs/lib/ -packages/docusaurus-plugin-content-pages/lib/ -packages/docusaurus-plugin-debug/lib/ -packages/docusaurus-plugin-sitemap/lib/ -packages/docusaurus-plugin-ideal-image/lib/ +packages/docusaurus-*/lib-next/ packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js -packages/docusaurus-theme-common/lib/ -packages/docusaurus-theme-classic/lib/ -packages/docusaurus-theme-classic/lib-next/ -packages/docusaurus-theme-bootstrap/lib/ -packages/docusaurus-migrate/lib/ packages/docusaurus-1.x/.eslintrc.js packages/docusaurus-init/templates/facebook/.eslintrc.js diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 762a7816f9f9..b668bf2cd9cb 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -4,6 +4,18 @@ about: Submit a bug report to help us improve labels: 'bug, needs triage' --- + + ## 🐛 Bug Report (A clear and concise description of what the bug is) @@ -14,6 +26,8 @@ labels: 'bug, needs triage' ## To Reproduce +If possible, use https://new.docusaurus.io to create a CodeSandbox reproducible demo of the bug. + (Write your steps here:) 1. Step 1... @@ -45,13 +59,17 @@ labels: 'bug, needs triage' +- Public source code: +- Public site url: - Docusaurus version used: - Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): - Operating system and version (desktop or mobile): ## Reproducible Demo -(Paste the link to an example repo, including a `siteConfig.js`, and exact instructions to reproduce the issue.) +If possible, use https://new.docusaurus.io to create a CodeSandbox reproducible demo of the bug. + +(Paste the link to an example repo, including a `docusaurus.config.js`, and exact instructions to reproduce the issue.) diff --git a/website-1.x/blog/2021-01-19-docusaurus-2020-recap.md b/website-1.x/blog/2021-01-19-docusaurus-2020-recap.md new file mode 100644 index 000000000000..aa27e5910086 --- /dev/null +++ b/website-1.x/blog/2021-01-19-docusaurus-2020-recap.md @@ -0,0 +1,139 @@ +--- +title: Docusaurus 2020 Recap +author: Sébastien Lorber +authorTitle: Docusaurus maintainer +authorURL: https://sebastienlorber.com +authorImageURL: https://github.com/slorber.png +authorTwitter: sebastienlorber +tags: [recap] +image: /img/docusaurus-2020-recap.png +--- + +**2020 was great for Docusaurus**, despite [a regrettable start](https://docusaurus.io/blog/2020/01/07/tribute-to-endi) and a tumultuous year for everyone. + +We continued to invest in [Docusaurus 2](https://v2.docusaurus.io/), and made it reach **full feature parity** with [Docusaurus 1](https://v1.docusaurus.io/). + +We now **recommend Docusaurus 2** as the **default choice** to start a new Docusaurus project and encourage v1 users to [migrate to Docusaurus 2](https://v2.docusaurus.io/docs/migration). + +We are **still in alpha**, but expect **some good news very soon**! + +![Docusaurus v1 vs v2 npm trends](/img/blog/2020-recap/docusaurus-plushie-banner.jpeg) + + + +## Docusaurus 2 highlights + +We have worked on many features this year, and would like to highlight the most significant ones: + +- **i18n**: easily translate your Docusaurus site, released soon! ([preview](https://github.com/facebook/docusaurus/pull/3325), [doc](https://v2.docusaurus.io/docs/next/i18n/introduction)) +- **Version dropdown**: enable contextual version switch +- **Versioning options**: solving the most common pain-points users had with versioning +- **Contextual search**: search in the current version, use the brand-new DocSearch 3 experience +- **Markdown pages**: use Markdown instead of React components to create standalone pages +- **Better theme**: various UI, UX and accessibility improvements +- **PWA**: add offline support to your site, and make it installable +- **Fail-fast**: strict config validation, detect broken links, and prevent bad production deployments +- **Multi-instance**: use the docs plugin twice on a single site (e.g. iOS/Android SDK docs) +- **Migration CLI**: automate the upgrade from Docusaurus 1 +- **CodeSandbox**: assess Docusaurus easily from your browser with [new.docusaurus.io](https://new.docusaurus.io/) +- **Canary releases**: use the `@canary` npm tag to use the upcoming release before anyone else +- **TypeScript**: progressive adoption for internal code, and improve usage for users +- **Publish Infima**: it is now [open-source](https://github.com/facebookincubator/infima) + +## Docusaurus 2 growth + +The plan to [rebuild Docusaurus from scratch in 2019](https://docusaurus.io/blog/2019/12/30/docusaurus-2019-recap) paid off: after a slow start, Docusaurus 2 has been widely adopted and has **already outgrown Docusaurus 1** usage. + +![Docusaurus v1 vs v2 npm trends](/img/blog/2020-recap/docusaurus-npm-trends.png) + +Notable **projects, startups, large companies, and individuals** adopted Docusaurus 2 ([showcase](https://v2.docusaurus.io/showcase)): + +- [Supabase](https://supabase.io) +- [React Navigation](https://reactnavigation.org) +- [React Redux](https://react-redux.js.org/) +- [Vector](https://vector.dev) +- [Algolia DocSearch](https://docsearch.algolia.com) +- [SAP Cloud SDK](https://sap.github.io/cloud-sdk) +- [Palo Alto Cortex XSOAR](https://xsoar.pan.dev) +- [Quddús George's website](https://portfoliosaurus.now.sh) + +We helped **large scale Docusaurus 1 sites to upgrade**, ensuring a proper **migration path** and **feature parity**. + +[React Native](https://reactnative.dev/) was successfully upgraded to Docusaurus 2 ([archived v1 site](http://archive.reactnative.dev/)): + +![React Native screenshot](/img/blog/2020-recap/react-native-screenshot.png) + +Localized Docusaurus 1 sites (like **Jest**) will be able to upgrade too: + +![Jest in Japanese screenshot](/img/blog/2020-recap/jest-screenshot.png) + +We also saw the **[first right-to-left](https://datagit.ir/)** Docusaurus 2 site published: + +![Datagit screenshot](/img/blog/2020-recap/datagit-rtl-screenshot.png) + +## GitHub Activity + +- **Stars**: 14632 -> 20946 (+43.2% y/y) +- **Total Contributors**: 303 -> 512 (+68.9% y/y). Most of which are non-Facebook contributors +- **Weekly npm Downloads**: 2356 -> 25592 (+986% y/y) +- **On GitHub**, Docusaurus 1 is used by 6311 projects (+62.9% y/y) while Docusaurus 2 is used by 5039 projects (+1940% y/y) + +## Collaboration with Major League Hacking + +We have welcomed [Major League Hacking](https://mlh.io/) (MLH) fellows for 2 seasons already. + +We are very thankful for the **various contributions** they made, such as: + +- Writing the foundations of the v1 to v2 migration CLI +- Help migrate the React Native website from v1 to v2 +- Making the config validation more strict and exhaustive, returning helpful error messages +- Adding CodeSandbox support +- Improving the CI pipelines: build size and Lighthouse bots + +We look forward to continuing this collaboration in 2021. + +## Media + +Dmitry Vinnik (Developer Advocate @ Facebook) explains Docusaurus in [60 seconds](https://www.youtube.com/watch?v=_An9EsKPhp0) or [15min](https://www.youtube.com/watch?v=Yhyx7otSksg) videos. + +Rachel Nabors (Documentation Engineer @ Facebook) talked a bit about Docusaurus in [React Native Radio 178 (podcast)](https://reactnativeradio.com/episodes/178-documenting-react-native-with-rachel-nabors-gWxwySPl), and William Candillon the [React Native website migration (video)](https://www.youtube.com/watch?v=-zhjq2ECKq4). + +Many blog posts have been published: + +- [To the Makers of Docusaurus](https://portfoliosaurus.now.sh/blog/toTheMakers) by Quddus George +- [Richer API documentation with Redoc and Docusaurus](https://davidgoss.co/blog/api-documentation-redoc-docusaurus/) by David Goss +- [How to Build a Plugin for Docusaurus v2](https://aknapen.nl/blog/how-to-build-a-plugin-for-docusaurus-v2/) by Adriaan Knapen +- [React Tracked Documentation Website with Docusaurus v2](https://blog.axlight.com/posts/react-tracked-documentation-website-with-docusaurus-v2/) by Daishi Kato +- [Easy documentation with Docusaurus](https://blog.logrocket.com/easy-documentation-with-docusaurus/) by Anshul Goyal (MLH fellow) +- [Build Beautiful Documentation Websites with Docusaurus](https://lo-victoria.com/build-beautiful-documentation-websites-with-docusaurus) by Victoria Lo + +## Community + +The Docusaurus community continues to grow, the [Discord](https://discord.gg/docusaurus) server is quite active, and [Stack Overflow questions](https://stackoverflow.com/questions/tagged/docusaurus) keep being posted. + +The **modular architecture** of Docusaurus 2 allowed the community to build and publish [third-party plugins](https://v2.docusaurus.io/community/resources#community-plugins-). As we would like to federate better our community, if you are building a plugin, please [let us know](https://github.com/facebook/docusaurus/discussions/4025). + +## What's next? + +As the **core features of Docusaurus 2** have finally been built, we will be able to dedicate more time to solve the pain points and bugs reported by the community, and make Docusaurus stable and convenient enough to enter the **beta and release-candidate phase**. + +With proper support for **i18n and versioning**, and **large scale migrations** such as **React Native** and **Jest**, we now have a clear migration path for all Docusaurus 1 sites. + +We still have a few **major features** that we would like to work on: + +- [Create a theme gallery](https://github.com/facebook/docusaurus/issues/3522), make it easy to switch from one another, and include **first-class Tailwind support** +- [Upgrade to Webpack 5](https://github.com/facebook/docusaurus/issues/4027), improve performances and build times +- [Better compatibility with CommonMark](https://github.com/facebook/docusaurus/issues/3018), as MDX and makes it harder for CommonMark-based sites to adopt Docusaurus +- [Upgrade to MDX 2.0](https://github.com/facebook/docusaurus/issues/4029) +- Other tasks that we might discover during 2021 + +Huge thanks to the community for [their contributions in 2020](https://github.com/facebook/docusaurus/graphs/contributors?from=2020-01-01&to=2021-01-01&type=c), especially: + +- [Joel Marcey](https://github.com/JoelMarcey) for creating Docusaurus and supporting the project all this time +- the core team - [Alexey Pyltsyn](https://github.com/lex111), [Sébastien Lorber](https://sebastienlorber.com), [Yangshun Tay](https://twitter.com/yangshunz) +- the Major League Hacking and Facebook interns for their significant impact +- the Algolia team for DocSearch 3 and their support +- [Bartosz Kaszubowski](https://github.com/Simek) for his investment in the React Native migration +- the whole community for their contributions, and providing support to each other + +Cheers to a great 2021! 🎉 diff --git a/website-1.x/core/Footer.js b/website-1.x/core/Footer.js index df1529f901ee..15566b28eed6 100644 --- a/website-1.x/core/Footer.js +++ b/website-1.x/core/Footer.js @@ -123,6 +123,18 @@ class Footer extends React.Component { rel="noreferrer noopener"> Terms + + Data Policy + + + Cookie Policy + diff --git a/website-1.x/docs/getting-started-docker.md b/website-1.x/docs/getting-started-docker.md index 3b0dd59d6bf0..61754da1f5c7 100644 --- a/website-1.x/docs/getting-started-docker.md +++ b/website-1.x/docs/getting-started-docker.md @@ -21,6 +21,8 @@ To run the local web server: This will start a docker container with the image `docusaurus-doc`. To see more detailed container info run `docker ps` . +To access Docusaurus from outside the docker container you must add the `--host` flag to the `docusaurus-start` command as described in: [API Commands](api-commands.md#docusaurus-start) + ## Use docker-compose We can also use `docker-compose` to configure our application. This feature of docker allows you to run the web server and any additional services with a single command. diff --git a/website-1.x/docs/getting-started-installation.md b/website-1.x/docs/getting-started-installation.md index 85ab673c64e0..9440a1b88b0e 100644 --- a/website-1.x/docs/getting-started-installation.md +++ b/website-1.x/docs/getting-started-installation.md @@ -6,7 +6,7 @@ description: Docusaurus was designed from the ground up to be easily installed a Docusaurus was designed from the ground up to be easily installed and used to get your website up and running quickly. -> **Important Note:** If you are setting up a new Docusaurus website for a Facebook Open Source project, we highly encourage you to use [Docusaurus 2](https://v2.docusaurus.io) instead. +> **Important Note:** we highly encourage you to use [Docusaurus 2](https://v2.docusaurus.io) instead. ## Installing Docusaurus diff --git a/website-1.x/languages.js b/website-1.x/languages.js index 866a5224347a..3229aa38a61d 100644 --- a/website-1.x/languages.js +++ b/website-1.x/languages.js @@ -183,15 +183,20 @@ const languages = [ }, ]; -const onlyEnglish = [ +const onlyEnglishAndFrench = [ { enabled: true, name: 'English', tag: 'en', }, + { + enabled: true, + name: 'Français', + tag: 'fr', + }, ]; // We want deploy previews to be fast module.exports = require('./netlifyUtils').isDeployPreview - ? onlyEnglish + ? onlyEnglishAndFrench : languages; diff --git a/website-1.x/package.json b/website-1.x/package.json index 99c5196f7061..5bf8aca3794a 100644 --- a/website-1.x/package.json +++ b/website-1.x/package.json @@ -1,6 +1,6 @@ { "name": "docusaurus-1-website", - "version": "2.0.0-alpha.69", + "version": "2.0.0-alpha.70", "private": true, "scripts": { "start": "docusaurus-start", @@ -10,10 +10,11 @@ "write-translations": "docusaurus-write-translations", "docusaurus-version": "docusaurus-version", "rename-version": "docusaurus-rename-version", - "crowdin-upload": "crowdin --config ../crowdin.yaml upload sources --auto-update -b master", - "crowdin-download": "crowdin --config ../crowdin.yaml download -b master" + "crowdin-upload": "cd .. && crowdin upload sources --auto-update -b master --config crowdin-v1.yml", + "crowdin-download": "cd .. && crowdin download -b master --config crowdin-v1.yml", + "netlify:build": "yarn crowdin-download && yarn build" }, "dependencies": { - "docusaurus": "2.0.0-alpha.69" + "docusaurus": "2.0.0-alpha.70" } } diff --git a/website-1.x/pages/en/versions.js b/website-1.x/pages/en/versions.js index ca5bc8b8b6b3..cd79db68bd09 100644 --- a/website-1.x/pages/en/versions.js +++ b/website-1.x/pages/en/versions.js @@ -26,8 +26,24 @@ function Versions(props) {

{siteConfig.title} Versions

-

Current version (Stable)

-

Latest version of Docusaurus.

+

Docusaurus v2

+

+ We now recommend using{' '} + Docusaurus v2. +

+ + + + + + + +
2.x + Documentation +
+

Docusaurus v1

+

Current v1 version (Stable)

+

Latest version of Docusaurus v1.

@@ -47,11 +63,11 @@ function Versions(props) {

Latest Version

- Here you can find the latest documentation and unreleased code. +

Unreleased Docusaurus v1 code.

- +
masterv1 master @@ -66,7 +82,8 @@ function Versions(props) {

Past Versions

- Here you can find documentation for previous versions of Docusaurus. + Here you can find documentation for previous versions of Docusaurus + v1.

diff --git a/website-1.x/static/img/blog/2020-recap/datagit-rtl-screenshot.png b/website-1.x/static/img/blog/2020-recap/datagit-rtl-screenshot.png new file mode 100644 index 000000000000..fb7204f188b2 Binary files /dev/null and b/website-1.x/static/img/blog/2020-recap/datagit-rtl-screenshot.png differ diff --git a/website-1.x/static/img/blog/2020-recap/docusaurus-npm-trends.png b/website-1.x/static/img/blog/2020-recap/docusaurus-npm-trends.png new file mode 100644 index 000000000000..51457bc8a10b Binary files /dev/null and b/website-1.x/static/img/blog/2020-recap/docusaurus-npm-trends.png differ diff --git a/website-1.x/static/img/blog/2020-recap/docusaurus-plushie-banner.jpeg b/website-1.x/static/img/blog/2020-recap/docusaurus-plushie-banner.jpeg new file mode 100644 index 000000000000..11bda0928456 Binary files /dev/null and b/website-1.x/static/img/blog/2020-recap/docusaurus-plushie-banner.jpeg differ diff --git a/website-1.x/static/img/blog/2020-recap/jest-screenshot.png b/website-1.x/static/img/blog/2020-recap/jest-screenshot.png new file mode 100644 index 000000000000..bccdca273af4 Binary files /dev/null and b/website-1.x/static/img/blog/2020-recap/jest-screenshot.png differ diff --git a/website-1.x/static/img/blog/2020-recap/react-native-screenshot.png b/website-1.x/static/img/blog/2020-recap/react-native-screenshot.png new file mode 100644 index 000000000000..1932b8dd4396 Binary files /dev/null and b/website-1.x/static/img/blog/2020-recap/react-native-screenshot.png differ diff --git a/website-1.x/static/img/docusaurus-2020-recap.png b/website-1.x/static/img/docusaurus-2020-recap.png new file mode 100644 index 000000000000..2e4d675f90ba Binary files /dev/null and b/website-1.x/static/img/docusaurus-2020-recap.png differ diff --git a/website/community/resources.md b/website/community/resources.md index b688e1452e4e..8932c1348289 100644 --- a/website/community/resources.md +++ b/website/community/resources.md @@ -12,7 +12,7 @@ A curated list of interesting Docusaurus community projects. ## Articles -- [Live code editing in Docusaurus](https://dev.to/mrmuhammadali/live-code-editing-in-docusaurus-28k) +- [Live code editing in Docusaurus](https://dev.to/mrmuhammadali/live-code-editing-in-docusaurus-ux-at-its-best-2hj1) ## Showcase @@ -20,14 +20,25 @@ See the showcase ## Community plugins +### Search + - [docusaurus-plugin-lunr](https://github.com/daldridge/docusaurus-plugin-lunr) - Docusaurus v2 plugin to create a local search index for use with Lunr.js - [docusaurus-lunr-search](https://github.com/lelouch77/docusurus-lunr-search) - Offline Search for Docusaurus v2 - [docusaurus-search-local](https://github.com/cmfcmf/docusaurus-search-local) - Offline/local search for Docusaurus v2 - [@easyops-cn/docusaurus-search-local](https://github.com/easyops-cn/docusaurus-search-local) - Offline/local search for Docusaurus v2 (language of zh supported) -- [docusaurus-pdf](https://github.com/KohheePeace/docusaurus-pdf) - Generate documentation into PDF format -- [docusaurus-plugin-sass](https://github.com/rlamana/docusaurus-plugin-sass) - Sass/SCSS stylesheets support + +### Integrations + - [docusaurus2-dotenv](https://github.com/jonnynabors/docusaurus2-dotenv) - A Docusaurus 2 plugin that supports dotenv and other environment variables - [posthog-docusaurus](https://github.com/PostHog/posthog-docusaurus) - Integrate [PostHog](https://posthog.com/) product analytics with Docusaurus v2 +- [docusaurus-plugin-moesif](https://github.com/Moesif/docusaurus-plugin-moesif) - Adds [Moesif API Analytics](https://www.moesif.com/) to track user behavior and pinpoint where developers drop off in your activation funnel. + +### Features + +- [docusaurus-theme-github-codeblock](https://github.com/saucelabs/docusaurus-theme-github-codeblock). A Docusaurus v2 plugin that supports referencing code examples from public GitHub repositories +- [docusaurus-pdf](https://github.com/KohheePeace/docusaurus-pdf) - Generate documentation into PDF format +- [docusaurus-plugin-sass](https://github.com/rlamana/docusaurus-plugin-sass) - Sass/SCSS stylesheets support +- [docusaurus-plugin-remote-content](https://github.com/rdilweb/docusaurus-plugin-remote-content) - A Docusaurus v2 plugin that allows you to fetch content from remote sources ## Enterprise usage @@ -36,3 +47,4 @@ See the showcase - Stripe - Algolia - Callstack +- Sauce Labs diff --git a/website/docs/api/docusaurus.config.js.md b/website/docs/api/docusaurus.config.js.md index d5829bed584c..2dbd9e3585d8 100644 --- a/website/docs/api/docusaurus.config.js.md +++ b/website/docs/api/docusaurus.config.js.md @@ -80,6 +80,36 @@ module.exports = { ## Optional fields +### `i18n` + +- Type: `Object` + +The i18n configuration object to [localize your site](../i18n/i18n-introduction.md). + +Example: + +```js title="docusaurus.config.js" +module.exports = { + i18n: { + defaultLocale: 'en', + locales: ['en', 'fr'], + localeConfigs: { + en: { + label: 'English', + direction: 'ltr', + }, + fr: { + label: 'Français', + direction: 'ltr', + }, + }, + }, +}; +``` + +- `label`: the label to use for this locale +- `direction`: `ltr` (default) or `rtl` (for [right-to-left languages](https://developer.mozilla.org/en-US/docs/Glossary/rtl) like Araric, Hebrew...) + ### `noIndex` - Type: `boolean` @@ -178,17 +208,14 @@ module.exports = { - Type: `Object` - - -An object containing data needed by the theme you use. - -For Docusaurus' default theme _classic_, we use `themeConfig` to customize your navbar and footer links: +The [theme configuration](./themes/theme-configuration.md) object, to customize your site UI: navbar, footer... Example: ```js title="docusaurus.config.js" module.exports = { themeConfig: { + hideableSidebar: false, colorMode: { defaultMode: 'light', disableSwitch: false, diff --git a/website/docs/api/plugins/plugin-content-blog.md b/website/docs/api/plugins/plugin-content-blog.md index 2c6d2b347425..89c56444e226 100644 --- a/website/docs/api/plugins/plugin-content-blog.md +++ b/website/docs/api/plugins/plugin-content-blog.md @@ -31,11 +31,23 @@ module.exports = { */ path: 'blog', /** - * URL for editing a blog post. - * Example: 'https://github.com/facebook/docusaurus/edit/master/website/blog/' + * Base url to edit your site. + * Docusaurus will compute the final editUrl with "editUrl + relativeDocPath" */ - editUrl: - 'https://github.com/facebook/docusaurus/edit/master/website/blog/', + editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/', + /** + * For advanced cases, compute the edit url for each markdown file yourself. + */ + editUrl: ({locale, blogDirPath, blogPath}) => { + return `https://github.com/facebook/docusaurus/edit/master/website/${blogDirPath}/${blogPath}`; + }, + /** + * Useful if you commit localized files to git. + * When markdown files are localized, the edit url will target the localized file, + * instead of the original unlocalized file. + * Note: this option is ignored when editUrl is a function + */ + editLocalizedFiles: false, /** * Blog page title for better SEO */ @@ -105,3 +117,24 @@ module.exports = { ], }; ``` + +## i18n + +Read the [i18n introduction](../../i18n/i18n-introduction.md) first. + +### Translation files location + +- **Base path**: `website/i18n//docusaurus-plugin-content-blog` +- **Multi-instance path**: `website/i18n//docusaurus-plugin-content-blog-` +- **JSON files**: N/A +- **Markdown files**: `website/i18n//docusaurus-plugin-content-blog` + +### Example file-system structure + +```bash +website/i18n//docusaurus-plugin-content-blog +│ +│ # translations for website/blog +├── first-blog-post.md +└── second-blog-post.md +``` diff --git a/website/docs/api/plugins/plugin-content-docs.md b/website/docs/api/plugins/plugin-content-docs.md index 7ecc423fe77e..5b8bc7634e1f 100644 --- a/website/docs/api/plugins/plugin-content-docs.md +++ b/website/docs/api/plugins/plugin-content-docs.md @@ -4,7 +4,7 @@ title: '📦 plugin-content-docs' slug: '/api/plugins/@docusaurus/plugin-content-docs' --- -Provides the [Docs](markdown-features.mdx) functionality and is the default docs plugin for Docusaurus. +Provides the [Docs](../../guides/docs/docs-introduction.md) functionality and is the default docs plugin for Docusaurus. ## Installation @@ -31,13 +31,34 @@ module.exports = { */ path: 'docs', /** - * URL for editing a doc in the website repo. - * Example: 'https://github.com/facebook/docusaurus/edit/master/website/' + * Base url to edit your site. + * Docusaurus will compute the final editUrl with "editUrl + relativeDocPath" */ editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/', + /** + * For advanced cases, compute the edit url for each markdown file yourself. + */ + editUrl: function ({locale, version, versionDocsDirPath, docPath}) { + return `https://github.com/facebook/docusaurus/edit/master/website/${versionDocsDirPath}/${docPath}`; + }, + /** + * Useful if you commit localized files to git. + * When markdown files are localized, the edit url will target the localized file, + * instead of the original unlocalized file. + * Note: this option is ignored when editUrl is a function + */ + editLocalizedFiles: false, + /** + * Useful if you don't want users to submit doc pull-requests to older versions. + * When docs are versioned, the edit url will link to the doc + * in current version, instead of the versioned doc. + * Note: this option is ignored when editUrl is a function + */ + editCurrentVersion: false, /** * URL route for the docs section of your site. * *DO NOT* include a trailing slash. + * INFO: It is possible to set just `/` for shipping docs without base path. */ routeBasePath: 'docs', include: ['**/*.md', '**/*.mdx'], // Extensions to include. @@ -95,7 +116,7 @@ module.exports = { /** * The docusaurus versioning defaults don't make sense for all projects * This gives the ability customize the label and path of each version - * You may not like that default versin + * You may not like that default version */ versions: { /* @@ -120,3 +141,69 @@ module.exports = { ], }; ``` + +## Markdown Frontmatter + +Markdown documents can use the following markdown frontmmatter metadata fields, enclosed by a line `---` on either side: + +- `id`: A unique document id. If this field is not present, the document's `id` will default to its file name (without the extension). +- `title`: The title of your document. If this field is not present, the document's `title` will default to its `id`. +- `hide_title`: Whether to hide the title at the top of the doc. By default it is `false`. +- `hide_table_of_contents`: Whether to hide the table of contents to the right. By default it is `false`. +- `sidebar_label`: The text shown in the document sidebar and in the next/previous button for this document. If this field is not present, the document's `sidebar_label` will default to its `title`. +- `custom_edit_url`: The URL for editing this document. If this field is not present, the document's edit URL will fall back to `editUrl` from options fields passed to `docusaurus-plugin-content-docs`. +- `keywords`: Keywords meta tag for the document page, for search engines. +- `description`: The description of your document, which will become the `` and `` in ``, used by search engines. If this field is not present, it will default to the first line of the contents. +- `image`: Cover or thumbnail image that will be used when displaying the link to your post. +- `slug`: Allows to customize the document url + +Example: + +```yml +--- +id: doc-markdown +title: Markdown Features +hide_title: false +hide_table_of_contents: false +sidebar_label: Markdown :) +custom_edit_url: https://github.com/facebook/docusaurus/edit/master/docs/api-doc-markdown.md +description: How do I find you when I cannot solve this problem +keywords: + - docs + - docusaurus +image: https://i.imgur.com/mErPwqL.png +slug: /myDoc +--- +My Document Markdown content +``` + +## i18n + +Read the [i18n introduction](../../i18n/i18n-introduction.md) first. + +### Translation files location + +- **Base path**: `website/i18n//docusaurus-plugin-content-docs` +- **Multi-instance path**: `website/i18n//docusaurus-plugin-content-docs-` +- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.md#docusaurus-write-translations) +- **Markdown files**: `website/i18n//docusaurus-plugin-content-docs/` + +### Example file-system structure + +```bash +website/i18n//docusaurus-plugin-content-docs +│ +│ # translations for website/docs +├── current +│   ├── api +│   │   └── config.md +│   └── getting-started.md +├── current.json +│ +│ # translations for website/versioned_docs/version-1.0.0 +├── version-1.0.0 +│   ├── api +│   │   └── config.md +│   └── getting-started.md +└── version-1.0.0.json +``` diff --git a/website/docs/api/plugins/plugin-content-pages.md b/website/docs/api/plugins/plugin-content-pages.md index 2e07f42f19b8..b63ba654d174 100644 --- a/website/docs/api/plugins/plugin-content-pages.md +++ b/website/docs/api/plugins/plugin-content-pages.md @@ -66,3 +66,24 @@ module.exports = { ], }; ``` + +## i18n + +Read the [i18n introduction](../../i18n/i18n-introduction.md) first. + +### Translation files location + +- **Base path**: `website/i18n//docusaurus-plugin-content-pages` +- **Multi-instance path**: `website/i18n//docusaurus-plugin-content-pages-` +- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.md#docusaurus-write-translations) +- **Markdown files**: `website/i18n//docusaurus-plugin-content-pages` + +### Example file-system structure + +```bash +website/i18n//docusaurus-plugin-content-pages +│ +│ # translations for website/src/pages +├── first-markdown-page.md +└── second-markdown-page.md +``` diff --git a/website/docs/api/themes/theme-configuration.md b/website/docs/api/themes/theme-configuration.md index 369a974d5d80..f64dc799fb62 100644 --- a/website/docs/api/themes/theme-configuration.md +++ b/website/docs/api/themes/theme-configuration.md @@ -117,6 +117,27 @@ module.exports = { }; ``` +## i18n + +Read the [i18n introduction](../../i18n/i18n-introduction.md) first. + +### Translation files location + +- **Base path**: `website/i18n//docusaurus-theme-` +- **Multi-instance path**: N/A +- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.md#docusaurus-write-translations) +- **Markdown files**: `N/A + +### Example file-system structure + +```bash +website/i18n//docusaurus-theme-classic +│ +│ # translations for the theme +├── navbar.json +└── footer.json +``` + ## Hooks ### `useThemeContext` @@ -273,10 +294,13 @@ module.exports = { // highlight-start { type: 'doc', - position: 'left', docId: 'introduction', + + //// Optional + position: 'left', label: 'Docs', activeSidebarClassName: 'navbar__link--active', + docsPluginId: 'default', }, // highlight-end ], @@ -287,7 +311,9 @@ module.exports = { ### Navbar docs version dropdown -If you use docs with versioning, this special navbar item type that will render a dropdown with all your site's available versions. The user will be able to switch from one version to another, while staying on the same doc (as long as the doc id is constant across versions). +If you use docs with versioning, this special navbar item type that will render a dropdown with all your site's available versions. + +The user will be able to switch from one version to another, while staying on the same doc (as long as the doc id is constant across versions). ```js {5-8} title="docusaurus.config.js" module.exports = { @@ -296,14 +322,15 @@ module.exports = { items: [ { type: 'docsVersionDropdown', - position: 'left', + //// Optional + position: 'left', // Add additional dropdown items at the beginning/end of the dropdown. dropdownItemsBefore: [], dropdownItemsAfter: [{to: '/versions', label: 'All versions'}], - // Do not add the link active class when browsing docs. dropdownActiveClassDisabled: true, + docsPluginId: 'default', }, ], }, @@ -323,9 +350,12 @@ module.exports = { // highlight-start { type: 'docsVersion', + + //// Optional position: 'left', - // to: "/path // by default, link to active/latest version - // label: "label" // by default, show active/latest version label + to: '/path', // by default, link to active/latest version + label: 'label', // by default, show active/latest version label + docsPluginId: 'default', }, // highlight-end ], @@ -334,6 +364,58 @@ module.exports = { }; ``` +### Navbar locale dropdown + +If you use the [i18n feature](../../i18n/i18n-introduction.md), this special navbar item type will render a dropdown with all your site's available locales. + +The user will be able to switch from one locale to another, while staying on the same page. + +```js {5-8} title="docusaurus.config.js" +module.exports = { + themeConfig: { + navbar: { + items: [ + { + type: 'localeDropdown', + + //// Optional + position: 'left', + // Add additional dropdown items at the beginning/end of the dropdown. + dropdownItemsBefore: [], + dropdownItemsAfter: [ + { + to: 'https://my-site.com/help-us-translate', + label: 'Help us translate', + }, + ], + }, + ], + }, + }, +}; +``` + +### Navbar search + +If you use the [search](../../search.md), the search bar will be the rightmost element in the navbar. + +However, with this special navbar item type, you can change the default location. + +```js {5-8} title="docusaurus.config.js" +module.exports = { + themeConfig: { + navbar: { + items: [ + { + type: 'search', + position: 'right', + }, + ], + }, + }, +}; +``` + ### Auto-hide sticky navbar You can enable this cool UI feature that automatically hides the navbar when a user starts scrolling down the page, and show it again when the user scrolls up. @@ -399,7 +481,7 @@ module.exports = { :::note -If you use the line highlighting Markdown syntax, you might need to specify a different highlight background color for the dark mode syntax highlighting theme. Refer to the [docs for guidance](markdown-features.mdx#line-highlighting). +If you use the line highlighting Markdown syntax, you might need to specify a different highlight background color for the dark mode syntax highlighting theme. Refer to the [docs for guidance](../../guides/markdown-features/markdown-features-code-blocks.mdx#line-highlighting). ::: diff --git a/website/docs/api/themes/theme-live-codeblock.md b/website/docs/api/themes/theme-live-codeblock.md index 2f24c0ea3813..9ee615cec084 100644 --- a/website/docs/api/themes/theme-live-codeblock.md +++ b/website/docs/api/themes/theme-live-codeblock.md @@ -4,7 +4,7 @@ title: '📦 theme-live-codeblock' slug: '/api/themes/@docusaurus/theme-live-codeblock' --- -This theme provides a `@theme/CodeBlock` component that is powered by react-live. You can read more on [interactive code editor](markdown-features.mdx#interactive-code-editor) documentation. +This theme provides a `@theme/CodeBlock` component that is powered by react-live. You can read more on [interactive code editor](../../guides/markdown-features/markdown-features-code-blocks.mdx#interactive-code-editor) documentation. ```bash npm2yarn npm install --save @docusaurus/theme-live-codeblock diff --git a/website/docs/blog.md b/website/docs/blog.md index bdca2a9f0b60..635a35c31b4b 100644 --- a/website/docs/blog.md +++ b/website/docs/blog.md @@ -89,11 +89,11 @@ Or this. ## Feed -You can generate RSS/ Atom feed by passing feedOptions. +You can generate RSS/Atom feed by passing feedOptions. By default, RSS and Atom feeds are generated. To disable feed generation, set `feedOptions.type` to `null`. ```ts feedOptions?: { - type: 'rss' | 'atom' | 'all'; + type?: 'rss' | 'atom' | 'all' | null; title?: string; description?: string; copyright: string; @@ -149,6 +149,7 @@ module.exports = { [ '@docusaurus/preset-classic', { + docs: false, blog: { path: './blog', routeBasePath: '/', // Set this value to '/'. diff --git a/website/docs/cli.md b/website/docs/cli.md index a65052ba3400..bc53f24ed028 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -20,6 +20,12 @@ Once your website is bootstrapped, the website source will contain the Docusauru } ``` +## Index + +import TOCInline from "@theme/TOCInline" + + + ## Docusaurus CLI commands Below is a list of Docusaurus CLI commands and their usages: @@ -142,3 +148,15 @@ Serve your built website locally. Clear a Docusaurus site's generated assets, caches, build artifacts. We recommend running this command before reporting bugs, after upgrading versions, or anytime you have issues with your Docusaurus site. + +### `docusaurus write-translations` + +Write the JSON translation files that you will have to translate. + +By default, the files are written in `website/i18n//...`. + +| Name | Default | Description | +| --- | --- | --- | +| `--locale` | `` | Define which locale folder you want to write translations the JSON files in | +| `--override` | `false` | Override existing translation messages | +| `--messagePrefix` | `''` | Allows to add a prefix to each translation message, to help you highlight untranslated strings | diff --git a/website/docs/configuration.md b/website/docs/configuration.md index 4bf77438b401..d59769af1818 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -3,6 +3,8 @@ id: configuration title: Configuration --- +import TOCInline from '@theme/TOCInline'; + Docusaurus has a unique take on configurations. We encourage you to congregate information of your site into one place. We guard the fields of this file, and facilitate making this data object accessible across your site. Keeping a well-maintained `docusaurus.config.js` helps you, your collaborators, and your open source contributors be able to focus on documentation while still being able to customize the site. @@ -15,12 +17,7 @@ However, it can be helpful if you have a high-level understanding of how the con The high-level overview of Docusaurus configuration can be categorized into: -- [What goes into a `docusaurus.config.js`?](#what-goes-into-a-docusaurusconfigjs) - - [Site metadata](#site-metadata) - - [Deployment configurations](#deployment-configurations) - - [Theme, plugin, and preset configurations](#theme-plugin-and-preset-configurations) - - [Custom configurations](#custom-configurations) -- [Customizing Babel Configuration](#customizing-babel-configuration) + For exact reference to each of the configurable fields, you may refer to [**`docusaurus.config.js` API reference**](api/docusaurus.config.js.md). @@ -34,7 +31,7 @@ They are used in a number of places such as your site's title and headings, brow Deployment configurations such as `projectName` and `organizationName` are used when you deploy your site with the `deploy` command. -It is recommended to check the [deployment docs](deployment.mdx)) for more information. +It is recommended to check the [deployment docs](deployment.mdx) for more information. ### Theme, plugin, and preset configurations diff --git a/website/docs/deployment.mdx b/website/docs/deployment.mdx index bfdcfa02f813..c15c261da895 100644 --- a/website/docs/deployment.mdx +++ b/website/docs/deployment.mdx @@ -32,7 +32,7 @@ It is not the most performant solution Docusaurus can be self hosted using [`docusaurus serve`](cli.md#docusaurus-serve). Change port using `--port` and `--host` to change host. ```bash npm2yarn -npm run serve --build --port 80 --host 0.0.0.0 +npm run serve -- --build --port 80 --host 0.0.0.0 ``` ## Deploying to GitHub Pages @@ -50,10 +50,14 @@ First, modify your `docusaurus.config.js` and add the required params: | `url` | URL for your GitHub Page's user/organization page. This is commonly https://_username_.github.io. | | `baseUrl` | Base URL for your project. For projects hosted on GitHub pages, it follows the format "/_projectName_/". For https://github.com/facebook/docusaurus, `baseUrl` is `/docusaurus/`. | +:::info + In case you want to use your custom domain for GitHub Pages, create a `CNAME` file in the `static` directory. Anything within the `static` directory will be copied to the root of the `build` directory for deployment. You may refer to GitHub Pages' documentation [User, Organization, and Project Pages](https://help.github.com/en/articles/user-organization-and-project-pages) for more details. +::: + Example: ```jsx {3-6} title="docusaurus.config.js" @@ -90,16 +94,22 @@ Optional parameters, also set as environment variables: | `CURRENT_BRANCH` | The branch that contains the latest docs changes that will be deployed. Usually, the branch will be `master`, but it could be any branch (default or otherwise) except for `gh-pages`. If nothing is set for this variable, then the current branch will be used. | | `GIT_PASS` | Password (or token) of the `git` user (specified by `GIT_USER`). For example, to facilitate non-interactive deployment (e.g. continuous deployment) | +GitHub enterprise installations should work in the same manner as github.com; you only need to set the organization's GitHub Enterprise host as an environment veriable: + +| Name | Description | +| ------------- | ----------------------------------------------- | +| `GITHUB_HOST` | The domain name of your GitHub enterprise site. | + ### Deploy Finally, to deploy your site to GitHub Pages, run: - diff --git a/website/docs/docs.md b/website/docs/docs.md deleted file mode 100644 index adda552d0378..000000000000 --- a/website/docs/docs.md +++ /dev/null @@ -1,341 +0,0 @@ ---- -id: docs-introduction -title: Docs Introduction -sidebar_label: Introduction ---- - -The docs feature provides users with a way to organize Markdown files in a hierarchical format. - -## Document ID - -Every document has a unique `id`. By default, a document `id` is the name of the document (without the extension) relative to the root docs directory. - -For example, `greeting.md` id is `greeting` and `guide/hello.md` id is `guide/hello`. - -```bash -website # Root directory of your site -└── docs -   ├── greeting.md - └── guide - └── hello.md -``` - -However, the **last part** of the `id` can be defined by user in the front matter. For example, if `guide/hello.md`'s content is defined as below, its final `id` is `guide/part1`. - -```yml ---- -id: part1 ---- -Lorem ipsum -``` - -If you want more control over the last part of the document URL, it is possible to add a `slug` (defaults to the `id`). - -```yml ---- -id: part1 -slug: part1.html ---- -Lorem ipsum -``` - -:::note - -It is possible to use: - -- absolute slugs: `slug: /mySlug`, `slug: /`... -- relative slugs: `slug: mySlug`, `slug: ./../mySlug`... - -::: - -## Home page docs - -If you want a document to be available at the root, and have a path like `https://v2.docusaurus.io/docs/`, you can use the slug frontmatter: - -```yml ---- -id: my-home-doc -slug: / ---- -Lorem ipsum -``` - -## Sidebar - -To generate a sidebar to your Docusaurus site, you need to define a file that exports a sidebar object and pass that into the `@docusaurus/plugin-docs` plugin directly or via `@docusaurus/preset-classic`. - -```js {8-9} title="docusaurus.config.js" -module.exports = { - // ... - presets: [ - [ - '@docusaurus/preset-classic', - { - docs: { - // Sidebars filepath relative to the site dir. - sidebarPath: require.resolve('./sidebars.js'), - }, - // ... - }, - ], - ], -}; -``` - -### Hideable sidebar - -Using the enabled `themeConfig.hideableSidebar` option, you can make the entire sidebar hided, allowing you to better focus your users on the content. This is especially useful when content consumption on medium screens (e.g. on tablets). - -```js {4} title="docusaurus.config.js" -module.exports = { - // ... - themeConfig: { - hideableSidebar: true, - // ... - }, -}; -``` - -### Sidebar object - -A sidebar object is defined like this: - -```typescript -type Sidebar = { - [sidebarId: string]: - | { - [sidebarCategory: string]: SidebarItem[]; - } - | SidebarItem[]; -}; -``` - -Below is an example of a sidebar object. The key `docs` is the id of the sidebar (can be renamed to something else) and `Getting Started` is a category within the sidebar. `greeting` and `doc1` are both [sidebar item](#sidebar-item). - -```js title="sidebars.js" -module.exports = { - docs: { - 'Getting started': ['greeting'], - Docusaurus: ['doc1'], - }, -}; -``` - -Keep in mind that EcmaScript does not guarantee `Object.keys({a,b}) === ['a','b']` (yet, this is generally true). If you don't want to rely on iteration order of JavaScript object keys for the category name, the following sidebar object is also equivalent of the above shorthand syntax. - -```js title="sidebars.js" -module.exports = { - docs: [ - { - type: 'category', - label: 'Getting Started', - items: ['greeting'], - }, - { - type: 'category', - label: 'Docusaurus', - items: ['doc1'], - }, - ], -}; -``` - -You can also have multiple sidebars for different Markdown files by adding more top-level keys to the exported object. - -Example: - -```js title="sidebars.js" -module.exports = { - firstSidebar: { - 'Category A': ['doc1'], - }, - secondSidebar: { - 'Category A': ['doc2'], - 'Category B': ['doc3'], - }, -}; -``` - -#### Sidebar item - -As the name implies, `SidebarItem` is an item defined in a Sidebar. There are a few types we support: - -- [Doc](#doc) -- [Link](#link) -- [Ref](#ref) -- [Category](#category) - -#### Doc - -```typescript -type SidebarItemDoc = - | string - | { - type: 'doc'; - id: string; - }; -``` - -Sidebar item type that links to a doc page. Example: - -```js -{ - type: 'doc', - id: 'doc1', // string - document id -} -``` - -Using just the [Document ID](#document-id) is perfectly valid as well, the following is equivalent to the above: - -```js -'doc1'; // string - document id -``` - -Note that using this type will bind the linked doc to current sidebar, this means that if you access `doc1` page, the sidebar displayed will be the sidebar this item is on. For below case, `doc1` is bounded to `firstSidebar`. - -```js title="sidebars.js" -module.exports = { - firstSidebar: { - 'Category A': ['doc1'], - }, - secondSidebar: { - 'Category A': ['doc2'], - 'Category B': ['doc3'], - }, -}; -``` - -#### Link - -```typescript -type SidebarItemLink = { - type: 'link'; - label: string; - href: string; -}; -``` - -Sidebar item type that links to a non-document page. Example: - -```js -{ - type: 'link', - label: 'Custom Label', // The label that should be displayed (string). - href: 'https://example.com' // The target URL (string). -} -``` - -#### Ref - -```typescript -type SidebarItemRef = { - type: 'ref'; - id: string; -}; -``` - -Sidebar item type that links to doc without bounding it to the sidebar. Example: - -```js -{ - type: 'ref', - id: 'doc1', // Document id (string). -} -``` - -#### Category - -This is used to add hierarchies to the sidebar: - -```typescript -type SidebarItemCategory = { - type: 'category'; - label: string; // Sidebar label text. - items: SidebarItem[]; // Array of sidebar items. - collapsed: boolean; // Set the category to be collapsed or open by default -}; -``` - -As an example, here's how we created the subcategory for "Docs" under "Guides" in this site: - -```js title="sidebars.js" -module.exports = { - docs: { - Guides: [ - 'creating-pages', - { - type: 'category', - label: 'Docs', - items: ['markdown-features', 'sidebar', 'versioning'], - }, - ], - }, -}; -``` - -**Note**: it's possible to use the shorthand syntax to create nested categories: - -```js title="sidebars.js" -module.exports = { - docs: { - Guides: [ - 'creating-pages', - { - Docs: ['markdown-features', 'sidebar', 'versioning'], - }, - ], - }, -}; -``` - -#### Collapsible categories - -For sites with a sizable amount of content, we support the option to expand/collapse a category to toggle the display of its contents. Categories are collapsible by default. If you want them to be always expanded, set `themeConfig.sidebarCollapsible` to `false`: - -```js {4} title="docusaurus.config.js" -module.exports = { - // ... - themeConfig: { - sidebarCollapsible: false, - // ... - }, -}; -``` - -#### Expanded categories by default - -For docs that have collapsible categories, you may want more fine-grain control over certain categories. If you want specific categories to be always expanded, you can set `collapsed` to `false`: - -```js title="sidebars.js" -module.exports = { - docs: { - Guides: [ - 'creating-pages', - { - type: 'category', - label: 'Docs', - collapsed: false, - items: ['markdown-features', 'sidebar', 'versioning'], - }, - ], - }, -}; -``` - -## Docs-only mode - -If you only want the documentation feature, you can run your Docusaurus 2 site without a landing page and display your documentation page as the index page instead. - -To enable docs-only mode, set the docs plugin `routeBasePath: '/'`, and use the frontmatter `slug: /` on the document that should be the index page ([more infos](#home-page-docs)). - -:::caution - -You should delete the existing homepage at `./src/pages/index.js`, or else there will be two files mapping to the same route! - -::: - -:::tip - -There's also a "blog-only mode" for those who only want to use the blog feature of Docusaurus 2. You can use the same method detailed above. Follow the setup instructions on [Blog-only mode](blog.md#blog-only-mode). - -::: diff --git a/website/docs/docusaurus-core.md b/website/docs/docusaurus-core.md index 66a4f2986bd1..50ffe6deb4b1 100644 --- a/website/docs/docusaurus-core.md +++ b/website/docs/docusaurus-core.md @@ -125,6 +125,58 @@ const MyComponent = () => { }; ``` +### `` + +When [localizing your site](./i18n/i18n-introduction.md), the `` component will allow providing **translation support to React components**, such as your homepage. + +The translation strings will be extracted from your code with the [`docusaurus write-translations`](./cli.md#docusaurus-write-translations) CLI and create a `code.json` translation file in `website/i18n/`. + +:::note + +The `` props **must be hardcoded strings**. + +It is **not possible to use variables**, or the extraction wouldn't work. + +::: + +#### Props + +- `children`: untranslated string in the default site locale` +- `id`: optional value to use as key in JSON translation files +- `description`: optional text to help the translator + +#### Example + +```jsx title="src/index.js" +import React from 'react'; +import Layout from '@theme/Layout'; + +// highlight-start +import Translate from '@docusaurus/Translate'; +// highlight-end + +export default function Home() { + return ( + +

+ {/* highlight-start */} + + Welcome to my website + + {/* highlight-end */} +

+
+ {/* highlight-start */} + My website content + {/* highlight-end */} +
+
+ ); +} +``` + ## Hooks ### `useDocusaurusContext` @@ -170,7 +222,20 @@ const MyComponent = () => { ### `useBaseUrl` -React hook to automatically prepend `baseUrl` to a string automatically. This is particularly useful if you don't want to hardcode your config's `baseUrl`. We highly recommend you to use this. +React hook to prepend your site `baseUrl` to a string. + +:::caution + +**Don't use it for regular links!** + +The `/baseUrl/` prefix is automatically added to all **absolute paths** by default: + +- Markdown: `[link](/my/path)` will link to `/baseUrl/my/path` +- React: `link` will link to `/baseUrl/my/path` + +::: + +#### Options ```ts type BaseUrlOptions = { @@ -179,41 +244,49 @@ type BaseUrlOptions = { }; ``` -Example usage: +#### Example usage: -```jsx {3,11} +```jsx import React from 'react'; -import Link from '@docusaurus/Link'; import useBaseUrl from '@docusaurus/useBaseUrl'; -const Help = () => { - return ( -
-

Browse the docs

-

- Learn more about Docusaurus using the{' '} - official documentation -

-
- ); +const SomeImage = () => { + // highlight-start + const imgSrc = useBaseUrl('/img/myImage.png'); + // highlight-end + return ; }; ``` +:::tip + +In most cases, you don't need `useBaseUrl`. + +Prefer a `require()` call for [assets](./guides/markdown-features/markdown-features-assets.mdx): + +```jsx + +``` + +::: + ### `useBaseUrlUtils` Sometimes `useBaseUrl` is not good enough. This hook return additional utils related to your site's base url. -- `withBaseUrl`: useful if you need to add base urls to multiple urls at once +- `withBaseUrl`: useful if you need to add base urls to multiple urls at once. -```jsx {2,5-7} +```jsx import React from 'react'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; const Component = () => { const urls = ['/a', '/b']; + // highlight-start const {withBaseUrl} = useBaseUrlUtils(); const urlsWithBaseUrl = urls.map(withBaseUrl); - return
{/* ... */}
; + // highlight-end + return
{/* ... */}
; }; ``` @@ -303,6 +376,54 @@ const MyComponent = () => { }; ``` +## Functions + +### `translate` + +The imperative counterpart of the [``](#translate) component. + +:::tip + +Use the imperative API for the **rare cases** when a **component cannot be used**, such as: + +- the `placeholder` props of form input +- the page `title` metadata + +::: + +```jsx title="src/index.js" +import React from 'react'; +import Layout from '@theme/Layout'; + +// highlight-start +import {translate} from '@docusaurus/Translate'; +// highlight-end + +export default function Home() { + return ( + + + + ); +} +``` + ## Modules ### `ExecutionEnvironment` diff --git a/website/docs/guides/docs/docs-create-doc.mdx b/website/docs/guides/docs/docs-create-doc.mdx new file mode 100644 index 000000000000..b1856efcd46c --- /dev/null +++ b/website/docs/guides/docs/docs-create-doc.mdx @@ -0,0 +1,75 @@ +--- +id: create-doc +title: Create a doc +description: Create a Markdown Document +slug: /create-doc +--- + +Create a markdown file, `greeting.md`, and place it under the `docs` directory. + +```bash +website # root directory of your site +├── docs +│   └── greeting.md +├── src +│   └── pages +├── docusaurus.config.js +├── ... +``` + +At the top of the file, specify `id` and `title` in the front matter, so that Docusaurus will pick them up correctly when generating your site. + +```yml +--- +id: greeting +title: Hello +--- + +## Hello from Docusaurus + +Are you ready to create the documentation site for your open source project? + +### Headers + +will show up on the table of contents on the upper right + +So that your users will know what this page is all about without scrolling down or even without reading too much. + +### Only h2 and h3 will be in the toc + +The headers are well-spaced so that the hierarchy is clear. + +- lists will help you +- present the key points +- that you want your users to remember + - and you may nest them + - multiple times +``` + +This will render in the browser as follows: + +import BrowserWindow from '@site/src/components/BrowserWindow'; + + + +

Hello from Docusaurus

+ +Are you ready to create the documentation site for your open source project? + +

Headers

+ +will show up on the table of contents on the upper right + +So that your users will know what this page is all about without scrolling down or even without reading too much. + +

Only h2 and h3 will be in the toc

+ +The headers are well-spaced so that the hierarchy is clear. + +- lists will help you +- present the key points +- that you want your users to remember + - and you may nest them + - multiple times + +
diff --git a/website/docs/guides/docs/docs-introduction.md b/website/docs/guides/docs/docs-introduction.md new file mode 100644 index 000000000000..b56c7a561c1e --- /dev/null +++ b/website/docs/guides/docs/docs-introduction.md @@ -0,0 +1,80 @@ +--- +id: introduction +title: Docs Introduction +sidebar_label: Introduction +slug: /docs-introduction +--- + +The docs feature provides users with a way to organize Markdown files in a hierarchical format. + +## Document ID + +Every document has a unique `id`. By default, a document `id` is the name of the document (without the extension) relative to the root docs directory. + +For example, `greeting.md` id is `greeting` and `guide/hello.md` id is `guide/hello`. + +```bash +website # Root directory of your site +└── docs +   ├── greeting.md + └── guide + └── hello.md +``` + +However, the **last part** of the `id` can be defined by user in the front matter. For example, if `guide/hello.md`'s content is defined as below, its final `id` is `guide/part1`. + +```yml +--- +id: part1 +--- +Lorem ipsum +``` + +If you want more control over the last part of the document URL, it is possible to add a `slug` (defaults to the `id`). + +```yml +--- +id: part1 +slug: part1.html +--- +Lorem ipsum +``` + +:::note + +It is possible to use: + +- absolute slugs: `slug: /mySlug`, `slug: /`... +- relative slugs: `slug: mySlug`, `slug: ./../mySlug`... + +::: + +## Home page docs + +If you want a document to be available at the root, and have a path like `https://v2.docusaurus.io/docs/`, you can use the slug frontmatter: + +```yml +--- +id: my-home-doc +slug: / +--- +Lorem ipsum +``` + +## Docs-only mode + +If you only want the documentation feature, you can run your Docusaurus 2 site without a landing page and display your documentation page as the index page instead. + +To enable docs-only mode, set the docs plugin `routeBasePath: '/'`, and use the frontmatter `slug: /` on the document that should be the index page ([more infos](#home-page-docs)). + +:::caution + +You should delete the existing homepage at `./src/pages/index.js`, or else there will be two files mapping to the same route! + +::: + +:::tip + +There's also a "blog-only mode" for those who only want to use the blog feature of Docusaurus 2. You can use the same method detailed above. Follow the setup instructions on [Blog-only mode](../../blog.md#blog-only-mode). + +::: diff --git a/website/docs/guides/docs/docs-markdown-features.mdx b/website/docs/guides/docs/docs-markdown-features.mdx new file mode 100644 index 000000000000..0035a655f29b --- /dev/null +++ b/website/docs/guides/docs/docs-markdown-features.mdx @@ -0,0 +1,28 @@ +--- +id: markdown-features +title: Docs Markdown Features +description: Docusaurus Markdown features that are specific to the docs plugin +slug: /docs-markdown-features +--- + +Docs can use any [Markdown feature](../markdown-features/markdown-features-intro.mdx), and have a few additional Docs-specific markdown features. + +## Markdown frontmatter + +Markdown docs have their own [Markdown frontmatter](../../api/plugins/plugin-content-docs.md#markdown-frontmatter) + +## Referencing other documents + +If you want to reference another document file, you could use the name of the document you want to reference. Docusaurus will convert the file path to be the final website path (and remove the `.md`). + +For example, if you are in `doc2.md` and you want to reference `doc1.md` and `folder/doc3.md`: + +```md +I am referencing a [document](doc1.md). Reference to another [document in a folder](folder/doc3.md). + +[Relative document](../doc2.md) referencing works as well. +``` + +One benefit of this approach is that the links to external files will still work if you are viewing the file on GitHub. + +Another benefit, for versioned docs, is that one versioned doc will link to another doc of the exact same version. diff --git a/website/docs/guides/docs/docs-multi-instance.mdx b/website/docs/guides/docs/docs-multi-instance.mdx new file mode 100644 index 000000000000..a49895247422 --- /dev/null +++ b/website/docs/guides/docs/docs-multi-instance.mdx @@ -0,0 +1,212 @@ +--- +id: multi-instance +title: Docs Multi-instance +description: Use multiple docs plugin instances on a single Docusaurus site. +slug: /docs-multi-instance +--- + +The `@docusaurus/plugin-content-docs` plugin can support [multi-instance](../../using-plugins.md#multi-instance-plugins-and-plugin-ids). + +:::note + +This feature is only useful for [versioned documentations](./versioning.md). It is recommended to be familiar with docs versioning before reading this page. + +::: + +## Use-cases + +Sometimes you want a Docusaurus site to host 2 distinct sets of documentation (or more). + +These documentations may even have different versioning/release lifecycles. + +### Mobile SDKs documentation + +If you build a cross-platform mobile SDK, you may have 2 documentations: + +- Android SDK documentation (`v1.0`, `v1.1`) +- iOS SDK documentation (`v1.0`, `v2.0`) + +In such case, you can use a distinct docs plugin instance per mobile SDK documentation. + +:::caution + +If each documentation instance is very large, you should rather create 2 distinct Docusaurus sites. + +If someone edits the iOS documentation, is it really useful to rebuild everything, including the whole Android documentation that did not change? + +::: + +### Versioned and unversioned doc + +Sometimes, you want some documents to be versioned, while other documents are more "global", and it feels useless to version them. + +We use this pattern on the Docusaurus website itself: + +- The [/docs/\*](/docs) section is versioned +- The [/community/\*](/community/support) section is unversioned + +## Setup + +Let's consider we 2 documentations: + +- Product: some versioned doc about your product +- Community: some unversioned doc about the community around your product + +You have to use twice the same plugin in your site configuration. + +:::caution + +`@docusaurus/preset-classic` already includes a docs plugin instance for you! + +::: + +When using the preset: + +```js title="docusaurus.config.js" +module.exports = { + presets: [ + [ + '@docusaurus/preset-classic', + { + docs: { + // highlight-start + // id: 'product', // omitted => default instance + // highlight-end + path: 'product', + routeBasePath: 'product', + sidebarPath: require.resolve('./sidebarsProduct.js'), + // ... other options + }, + }, + ], + ], + plugins: [ + [ + '@docusaurus/plugin-content-docs', + { + // highlight-start + id: 'community', + // highlight-end + path: 'community', + routeBasePath: 'community', + sidebarPath: require.resolve('./sidebarsCommunity.js'), + // ... other options + }, + ], + ], +}; +``` + +When not using the preset: + +```js title="docusaurus.config.js" +module.exports = { + plugins: [ + [ + '@docusaurus/plugin-content-docs', + { + // highlight-start + // id: 'product', // omitted => default instance + // highlight-end + path: 'product', + routeBasePath: 'product', + sidebarPath: require.resolve('./sidebarsProduct.js'), + // ... other options + }, + ], + [ + '@docusaurus/plugin-content-docs', + { + // highlight-start + id: 'community', + // highlight-end + path: 'community', + routeBasePath: 'community', + sidebarPath: require.resolve('./sidebarsCommunity.js'), + // ... other options + }, + ], + ], +}; +``` + +Don't forget to assign a unique `id` attribute to plugin instances. + +:::note + +We consider that the `product` instance is the most important one, and make it the "default" instance by not assigning any id. + +::: + +## Versioned paths + +Each instance will store versioned docs in a distinct folder. + +The default plugin instance will use these paths: + +- `website/versions.json` +- `website/versioned_docs` +- `website/versioned_sidebars` + +The other plugin instances (with an `id` attribute) will use these paths: + +- `website/_versions.json` +- `website/_versioned_docs` +- `website/_versioned_sidebars` + +:::tip + +You can omit the `id` attribute (defaults to `default`) for one of the docs plugin instances. + +The instance paths will be simpler, and retro-compatible with a single-instance setup. + +::: + +## Tagging new versions + +Each plugin instance will have its own cli command to tag a new version. They will be displayed if you run: + +```bash npm2yarn +npm run docusaurus -- --help +``` + +To version the product/default docs plugin instance: + +```bash npm2yarn +npm run docusaurus docs:version 1.0.0 +``` + +To version the non-default/community docs plugin instance: + +```bash npm2yarn +npm run docusaurus docs:version:community 1.0.0 +``` + +## Docs navbar items + +Each docs-related [theme navbar items](../../api/themes/theme-configuration.md#navbar) take an optional `docsPluginId` attribute. + +For example, if you want to have one version dropdown for each mobile SDK (iOS and Android), you could do: + +```js title="docusaurus.config.js" +module.exports = { + themeConfig: { + navbar: { + items: [ + { + type: 'docsVersionDropdown', + // highlight-start + docsPluginId: 'ios', + // highlight-end + }, + { + type: 'docsVersionDropdown', + // highlight-start + docsPluginId: 'android', + // highlight-end + }, + ], + }, + }, +}; +``` diff --git a/website/docs/guides/docs/sidebar.md b/website/docs/guides/docs/sidebar.md new file mode 100644 index 000000000000..f7267581f5c0 --- /dev/null +++ b/website/docs/guides/docs/sidebar.md @@ -0,0 +1,323 @@ +--- +id: sidebar +title: Sidebar +slug: /sidebar +--- + +To generate a sidebar to your Docusaurus site: + +1. Define a file that exports a [sidebar object](#sidebar-object). +1. Pass this object into the `@docusaurus/plugin-docs` plugin directly or via `@docusaurus/preset-classic`. + +```js {8-9} title="docusaurus.config.js" +module.exports = { + // ... + presets: [ + [ + '@docusaurus/preset-classic', + { + docs: { + // Sidebars filepath relative to the site dir. + sidebarPath: require.resolve('./sidebars.js'), + }, + // ... + }, + ], + ], +}; +``` + +## Sidebar object + +A sidebar object contains [sidebar items](#understanding-sidebar-items) and it is defined like this: + +```typescript +type Sidebar = { + [sidebarId: string]: + | { + [sidebarCategory: string]: SidebarItem[]; + } + | SidebarItem[]; +}; +``` + +For example: + +```js title="sidebars.js" +module.exports = { + docs: [ + { + type: 'category', + label: 'Getting Started', + items: ['greeting'], + }, + { + type: 'category', + label: 'Docusaurus', + items: ['doc1'], + }, + ], +}; +``` + +In this example, notice the following: + +- The key `docs` is the id of the sidebar. The id can be any value, not necessarily `docs`. +- `Getting Started` is a category within the sidebar. +- `greeting` and `doc1` are both [sidebar item](#sidebar-item). + +Shorthand notation can also be used: + +```js title="sidebars.js" +module.exports = { + docs: { + 'Getting started': ['greeting'], + Docusaurus: ['doc1'], + }, +}; +``` + +:::note + +Shorthand notation relies on the iteration order of JavaScript object keys for the category name. When using this notation, keep in mind that EcmaScript does not guarantee `Object.keys({a,b}) === ['a','b']`, yet this is generally true. + +::: + +## Using multiple sidebars + +You can have multiple sidebars for different Markdown files by adding more top-level keys to the exported object. + +Example: + +```js title="sidebars.js" +module.exports = { + firstSidebar: { + 'Category A': ['doc1'], + }, + secondSidebar: { + 'Category A': ['doc2'], + 'Category B': ['doc3'], + }, +}; +``` + +By default, the doc page the user is reading will display the sidebar that it is part of. This can be customized with the [sidebar type](#understanding-sidebar-items). + +For example, with the above example, when displaying the `doc2` page, the sidebar will contain the items of `secondSidebar` only. Another example of multiple sidebars is the `API` and `Docs` sections on the Docusaurus website. + +For more information about sidebars and how they relate to doc pages, see [Navbar doc link](../../api/themes/theme-configuration.md#navbar-doc-link). + +## Understanding sidebar items + +As the name implies, `SidebarItem` is an item defined in a Sidebar. A SidebarItem as a `type` that defines what the item links to. + +`type` supports the following values + +- [Doc](#linking-to-a-doc-page) +- [Link](#creating-a-generic-link) +- [Ref](#creating-a-link-to-page-without-sidebar) +- [Category](#creating-a-hierarchy) + +### Linking to a doc page + +Set `type` to `doc` to link to a documentation page. This is the default type. + +```typescript +type SidebarItemDoc = + | string + | { + type: 'doc'; + id: string; + }; +``` + +Example: + +```js +{ + type: 'doc', + id: 'doc1', // string - document id +} +``` + +Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above: + +```js +'doc1'; // string - document id + +``` + +Using this type will bind the linked doc to current sidebar. This means that if you access the `doc1` page, the sidebar displayed will be the sidebar that contains this doc page. + +In the example below, `doc1` is bound to `firstSidebar`. + +```js title="sidebars.js" +module.exports = { + firstSidebar: { + 'Category A': ['doc1'], + }, + secondSidebar: { + 'Category A': ['doc2'], + 'Category B': ['doc3'], + }, +}; +``` + +### Creating a generic link + +Set `type` to `link` to link to a non-documentation page. For example, to create an external link. + +```typescript +type SidebarItemLink = { + type: 'link'; + label: string; + href: string; +}; +``` + +Example: + +```js +{ + type: 'link', + label: 'Custom Label', // The label that should be displayed (string). + href: 'https://example.com' // The target URL (string). +} +``` + +### Creating a link to page without sidebar + +Set `type` to `ref` to link to a documentation page without binding it to a sidebar. This means the sidebar disappears when the user displays the linked page. + +```typescript +type SidebarItemRef = { + type: 'ref'; + id: string; +}; +``` + +Example: + +```js +{ + type: 'ref', + id: 'doc1', // Document id (string). +} +``` + +### Creating a hierarchy + +The Sidebar item type that creates a hierarchy in the sidebar. Set `type` to `category`. + +```typescript +type SidebarItemCategory = { + type: 'category'; + label: string; // Sidebar label text. + items: SidebarItem[]; // Array of sidebar items. + collapsed: boolean; // Set the category to be collapsed or open by default +}; +``` + +Example: + +```js title="sidebars.js" +module.exports = { + docs: [ + { + ... + }, + { + type: 'category', + label: 'Guides', + items: [ + 'guides/creating-pages', + { + Docs: ['docs-introduction', 'docs-sidebar', 'markdown-features', 'versioning'], + }, + ], + }, + ], +}; +``` + +**Note**: it's possible to use the shorthand syntax to create nested categories: + +```js title="sidebars.js" +module.exports = { + docs: { + Guides: [ + 'creating-pages', + { + Docs: [ + 'docs-introduction', + 'docs-sidebar', + 'markdown-features', + 'versioning', + ], + }, + ], + }, +}; +``` + +#### Collapsible categories + +For sites with a sizable amount of content, we support the option to expand/collapse a category to toggle the display of its contents. Categories are collapsible by default. If you want them to be always expanded, set `themeConfig.sidebarCollapsible` to `false`: + +```js {4} title="docusaurus.config.js" +module.exports = { + // ... + themeConfig: { + sidebarCollapsible: false, + // ... + }, +}; +``` + +#### Expanded categories by default + +For docs that have collapsible categories, you may want more fine-grain control over certain categories. If you want specific categories to be always expanded, you can set `collapsed` to `false`: + +```js title="sidebars.js" +module.exports = { + docs: { + Guides: [ + 'creating-pages', + { + type: 'category', + label: 'Docs', + collapsed: false, + items: ['markdown-features', 'sidebar', 'versioning'], + }, + ], + }, +}; +``` + +## Hideable sidebar + +Using the enabled `themeConfig.hideableSidebar` option, you can make the entire sidebar hidden, allowing you to better focus your users on the content. This is especially useful when content consumption on medium screens (e.g. on tablets). + +```js {4} title="docusaurus.config.js" +module.exports = { + // ... + themeConfig: { + hideableSidebar: true, + // ... + }, +}; +``` + +## Passing custom props + +To pass in custom props to a swizzled sidebar item, add the optional `customProps` object to any of the items: + +```js +{ + type: 'doc'; + id: 'doc1'; + customProps: { + /* props */ + } +} +``` diff --git a/website/versioned_docs/version-2.0.0-alpha.66/versioning.md b/website/docs/guides/docs/versioning.md similarity index 96% rename from website/versioned_docs/version-2.0.0-alpha.66/versioning.md rename to website/docs/guides/docs/versioning.md index 1d382d47eee2..d61e383c57fe 100644 --- a/website/versioned_docs/version-2.0.0-alpha.66/versioning.md +++ b/website/docs/guides/docs/versioning.md @@ -1,6 +1,7 @@ --- id: versioning title: Versioning +slug: /versioning --- You can use the version script to create a new documentation version based on the latest content in the `docs` directory. That specific set of documentation will then be preserved and accessible even as the documentation in the `docs` directory changes moving forward. @@ -61,7 +62,7 @@ npm run docusaurus docs:version 1.1.0 When tagging a new version, the document versioning mechanism will: - Copy the full `docs/` folder contents into a new `versioned_docs/version-/` folder. -- Create a versioned sidebars file based from your current [sidebar](docs.md#sidebar) configuration (if it exists) - saved as `versioned_sidebars/version--sidebars.json`. +- Create a versioned sidebars file based from your current [sidebar](docs-introduction.md#sidebar) configuration (if it exists) - saved as `versioned_sidebars/version--sidebars.json`. - Append the new version number to `versions.json`. ## Docs @@ -165,7 +166,7 @@ Docusaurus defaults work great for the first usecase. The docs in `./docs` will be served at `/docs/1.0.0` instead of `/docs/next`, and `1.0.0` will become the default version we link to in the navbar dropdown, and you will only need to maintain a single `./docs` folder. -See [docs plugin configuration](using-plugins#docusaurusplugin-content-docs) for more details. +See [docs plugin configuration](../../api/plugins/plugin-content-docs.md) for more details. ### Version your documentation only when needed diff --git a/website/docs/guides/markdown-features/markdown-features-admonitions.mdx b/website/docs/guides/markdown-features/markdown-features-admonitions.mdx new file mode 100644 index 000000000000..c692e1dda2b8 --- /dev/null +++ b/website/docs/guides/markdown-features/markdown-features-admonitions.mdx @@ -0,0 +1,86 @@ +--- +id: admonitions +title: Admonitions +description: Handling admonitions/callouts in Docusaurus Markdown +slug: /markdown-features/admonitions +--- + +In addition to the basic Markdown syntax, we use [remark-admonitions](https://github.com/elviswolcott/remark-admonitions) alongside MDX to add support for admonitions. Admonitions are wrapped by a set of 3 colons. + +Example: + + :::note + + The content and title *can* include markdown. + + ::: + + :::tip You can specify an optional title + + Heads up! Here's a pro-tip. + + ::: + + :::info + + Useful information. + + ::: + + :::caution + + Warning! You better pay attention! + + ::: + + :::danger + + Danger danger, mayday! + + ::: + +:::note + +The content and title _can_ include markdown. + +::: + +:::tip You can specify an optional title + +Heads up! Here's a pro-tip. + +::: + +:::info + +Useful information. + +::: + +:::caution + +Warning! You better pay attention! + +::: + +:::danger + +Danger danger, mayday! + +::: + +## Specifying title + +You may also specify an optional title + + :::note Your Title + + The content and title *can* include markdown. + + ::: + +:::note Your Title + +The content and title _can_ include Markdown. + +::: diff --git a/website/docs/guides/markdown-features/markdown-features-assets.mdx b/website/docs/guides/markdown-features/markdown-features-assets.mdx new file mode 100644 index 000000000000..baa1c1ea2721 --- /dev/null +++ b/website/docs/guides/markdown-features/markdown-features-assets.mdx @@ -0,0 +1,145 @@ +--- +id: assets +title: Assets +description: Handling assets in Docusaurus Markdown +slug: /markdown-features/assets +--- + +Sometimes you want to link to static assets directly from Markdown files, and it is convenient to co-locate the asset next to the markdown file using it. + +We have setup Webpack loaders to handle most common file types, so that when you import a file, you get its url, and the asset is automatically copied to the output folder. + +Let's imagine the following file structure: + +``` +# Your doc +/website/docs/myFeature.mdx + +# Some assets you want to use +/website/docs/assets/docusaurus-asset-example-banner.png +/website/docs/assets/docusaurus-asset-example-pdf.pdf +``` + +## Images + +You can use images in Markdown, or by requiring them and using a JSX image tag: + +```mdx +# My Markdown page + +Example banner + +or + +![Example banner](./assets/docusaurus-asset-example-banner.png) +``` + +The ES imports syntax also works: + +```mdx +# My Markdown page + +import myImageUrl from './assets/docusaurus-asset-example-banner.png'; + +My image alternative text +``` + +This results in displaying the image: + +![My image alternative text](../../assets/docusaurus-asset-example-banner.png) + +:::note + +If you are using [@docusaurus/plugin-ideal-image](../../using-plugins.md#docusaurusplugin-ideal-image), you need to use the dedicated image component, as documented. + +::: + +## Files + +In the same way, you can link to existing assets by requiring them and using the returned url in videos, links etc. + +```mdx +# My Markdown page + +
+ Download this PDF + + +or + +[Download this PDF using Markdown](./assets/docusaurus-asset-example-pdf.pdf) +``` + + + Download this PDF + + +[Download this PDF using Markdown](../../assets/docusaurus-asset-example-pdf.pdf) + +## Inline SVGs + +Docusaurus supports inlining SVGs out of the box. + +```jsx +import DocusaurusSvg from './docusaurus.svg'; + +; +``` + +import DocusaurusSvg from '@site/static/img/docusaurus.svg'; + + + +This can be useful, if you want to alter the part of the SVG image via CSS. For example, you can change one of the SVG colors based on the current theme. + +```jsx +import DocusaurusSvg from './docusaurus.svg'; + +; +``` + +```css +html[data-theme='light'] .themedDocusaurus [fill='#FFFF50'] { + fill: greenyellow; +} + +html[data-theme='dark'] .themedDocusaurus [fill='#FFFF50'] { + fill: seagreen; +} +``` + + + +## Themed Images + +Docusaurus supports themed images: the `ThemedImage` component (included in the classic/bootstrap themes) allows you to switch the image source based on the current theme. + +```jsx {5-8} +import ThemedImage from '@theme/ThemedImage'; + +; +``` + +import useBaseUrl from '@docusaurus/useBaseUrl'; +import ThemedImage from '@theme/ThemedImage'; + + diff --git a/website/docs/guides/markdown-features/markdown-features-code-blocks.mdx b/website/docs/guides/markdown-features/markdown-features-code-blocks.mdx new file mode 100644 index 000000000000..3510a73c454a --- /dev/null +++ b/website/docs/guides/markdown-features/markdown-features-code-blocks.mdx @@ -0,0 +1,439 @@ +--- +id: code-blocks +title: Code blocks +description: Handling code blocks in Docusaurus Markdown +slug: /markdown-features/code-blocks +--- + +Code blocks within documentation are super-powered 💪. + +## Code title + +You can add a title to the code block by adding `title` key after the language (leave a space between them). + + ```jsx title="/src/components/HelloCodeTitle.js" + function HelloCodeTitle(props) { + return

Hello, {props.name}

; + } + ``` + +```jsx title="/src/components/HelloCodeTitle.js" +function HelloCodeTitle(props) { + return

Hello, {props.name}

; +} +``` + +## Syntax highlighting + +Code blocks are text blocks wrapped around by strings of 3 backticks. You may check out [this reference](https://github.com/mdx-js/specification) for specifications of MDX. + + ```jsx + console.log('Every repo must come with a mascot.'); + ``` + + + +Use the matching language meta string for your code block, and Docusaurus will pick up syntax highlighting automatically, powered by [Prism React Renderer](https://github.com/FormidableLabs/prism-react-renderer). + +```jsx +console.log('Every repo must come with a mascot.'); +``` + +By default, the Prism [syntax highlighting theme](https://github.com/FormidableLabs/prism-react-renderer#theming) we use is [Palenight](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/themes/palenight.js). You can change this to another theme by passing `theme` field in `prism` as `themeConfig` in your docusaurus.config.js. + +For example, if you prefer to use the `dracula` highlighting theme: + +```js {4} title="docusaurus.config.js" +module.exports = { + themeConfig: { + prism: { + theme: require('prism-react-renderer/themes/dracula'), + }, + }, +}; +``` + +By default, Docusaurus comes with this subset of [commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js). + +To add syntax highlighting for any of the other [Prism supported languages](https://prismjs.com/#supported-languages), define it in an array of additional languages. + +For example, if you want to add highlighting for the `powershell` language: + +```js {5} title="docusaurus.config.js" +module.exports = { + // ... + themeConfig: { + prism: { + additionalLanguages: ['powershell'], + }, + // ... + }, +}; +``` + +If you want to add highlighting for languages not yet supported by Prism, you can swizzle `prism-include-languages`: + +```bash npm2yarn +npm run swizzle @docusaurus/theme-classic prism-include-languages +``` + +It will produce `prism-include-languages.js` in your `src/theme` folder. You can add highlighting support for custom languages by editing `prism-include-languages.js`: + +```js {8} title="src/theme/prism-include-languages.js" +const prismIncludeLanguages = (Prism) => { + // ... + + additionalLanguages.forEach((lang) => { + require(`prismjs/components/prism-${lang}`); // eslint-disable-line + }); + + require('/path/to/your/prism-language-definition'); + + // ... +}; +``` + +You can refer to [Prism's official language definitions](https://github.com/PrismJS/prism/tree/master/components) when you are writing your own language definitions. + +## Line highlighting + +You can bring emphasis to certain lines of code by specifying line ranges after the language meta string (leave a space after the language). + + ```jsx {3} + function HighlightSomeText(highlight) { + if (highlight) { + return 'This text is highlighted!'; + } + + return 'Nothing highlighted'; + } + ``` + +```jsx {3} +function HighlightSomeText(highlight) { + if (highlight) { + return 'This text is highlighted!'; + } + + return 'Nothing highlighted'; +} +``` + +To accomplish this, Docusaurus adds the `docusaurus-highlight-code-line` class to the highlighted lines. You will need to define your own styling for this CSS, possibly in your `src/css/custom.css` with a custom background color which is dependent on your selected syntax highlighting theme. The color given below works for the default highlighting theme (Palenight), so if you are using another theme, you will have to tweak the color accordingly. + +```css title="/src/css/custom.css" +.docusaurus-highlight-code-line { + background-color: rgb(72, 77, 91); + display: block; + margin: 0 calc(-1 * var(--ifm-pre-padding)); + padding: 0 var(--ifm-pre-padding); +} + +/* If you have a different syntax highlighting theme for dark mode. */ +html[data-theme='dark'] .docusaurus-highlight-code-line { + background-color: ; /* Color which works with dark mode syntax highlighting theme */ +} +``` + +To highlight multiple lines, separate the line numbers by commas or use the range syntax to select a chunk of lines. This feature uses the `parse-number-range` library and you can find [more syntax](https://www.npmjs.com/package/parse-numeric-range) on their project details. + + ```jsx {1,4-6,11} + import React from 'react'; + + function MyComponent(props) { + if (props.isBar) { + return
Bar
; + } + + return
Foo
; + } + + export default MyComponent; + ``` + +```jsx {1,4-6,11} +import React from 'react'; + +function MyComponent(props) { + if (props.isBar) { + return
Bar
; + } + + return
Foo
; +} + +export default MyComponent; +``` + +You can also use comments with `highlight-next-line`, `highlight-start`, and `highlight-end` to select which lines are highlighted. + + ```jsx + function HighlightSomeText(highlight) { + if (highlight) { + // highlight-next-line + return 'This text is highlighted!'; + } + + return 'Nothing highlighted'; + } + + function HighlightMoreText(highlight) { + // highlight-start + if (highlight) { + return 'This range is highlighted!'; + } + // highlight-end + + return 'Nothing highlighted'; + } + ``` + +```jsx +function HighlightSomeText(highlight) { + if (highlight) { + // highlight-next-line + return 'This text is highlighted!'; + } + + return 'Nothing highlighted'; +} + +function HighlightMoreText(highlight) { + // highlight-start + if (highlight) { + return 'This range is highlighted!'; + } + // highlight-end + + return 'Nothing highlighted'; +} +``` + +Supported commenting syntax: + +| Language | Syntax | +| ---------- | ------------------------ | +| JavaScript | `/* ... */` and `// ...` | +| JSX | `{/* ... */}` | +| Python | `# ...` | +| HTML | `` | + +If there's a syntax that is not currently supported, we are open to adding them! Pull requests welcome. + +## Interactive code editor + +(Powered by [React Live](https://github.com/FormidableLabs/react-live)) + +You can create an interactive coding editor with the `@docusaurus/theme-live-codeblock` plugin. + +First, add the plugin to your package. + +```bash npm2yarn +npm install --save @docusaurus/theme-live-codeblock +``` + +You will also need to add the plugin to your `docusaurus.config.js`. + +```js {3} +module.exports = { + // ... + themes: ['@docusaurus/theme-live-codeblock'], + // ... +}; +``` + +To use the plugin, create a code block with `live` attached to the language meta string. + + ```jsx live + function Clock(props) { + const [date, setDate] = useState(new Date()); + useEffect(() => { + var timerID = setInterval(() => tick(), 1000); + + return function cleanup() { + clearInterval(timerID); + }; + }); + + function tick() { + setDate(new Date()); + } + + return ( +
+

It is {date.toLocaleTimeString()}.

+
+ ); + } + ``` + +The code block will be rendered as an interactive editor. Changes to the code will reflect on the result panel live. + +```jsx live +function Clock(props) { + const [date, setDate] = useState(new Date()); + useEffect(() => { + var timerID = setInterval(() => tick(), 1000); + + return function cleanup() { + clearInterval(timerID); + }; + }); + + function tick() { + setDate(new Date()); + } + + return ( +
+

It is {date.toLocaleTimeString()}.

+
+ ); +} +``` + +:::caution react-live and imports + +It is not possible to import components directly from the react-live code editor, you have to define available imports upfront. + +::: + +By default, all React imports are available. If you need more imports available, swizzle the react-live scope: + +```bash npm2yarn +npm run swizzle @docusaurus/theme-live-codeblock ReactLiveScope +``` + +```jsx {3-15,21} title="src/theme/ReactLiveScope/index.js" +import React from 'react'; + +const ButtonExample = (props) => ( +