diff --git a/blog/2017/12/14/introducing-docusaurus.html b/blog/2017/12/14/introducing-docusaurus.html index ffdc581764..0f83c25408 100644 --- a/blog/2017/12/14/introducing-docusaurus.html +++ b/blog/2017/12/14/introducing-docusaurus.html @@ -24,7 +24,7 @@

Docusaurus is a tool designed to make it easy for teams to publish documentation websites without having to worry about the infrastructure and design details. At its core, all a user has to provide are documentation files written in markdown, customization of a provided home page written in React, and a few configuration modifications. Docusaurus handles the rest by providing default styles, site formatting, and simple document navigation. Getting started is easy, as users can install it using npm or yarn via a simple initialization script that creates a working example website out of the box.

Docusaurus also provides core website and documentation features out-of-the-box including blog support, internationalization, search, and versioning. While some projects may not require any of these features, enabling them is generally a matter of updating configuration options instead of having to add the infrastructure from the ground up. As more features get added to Docusaurus, users just can easily update to the latest version. This can be done by simply running npm or yarn update and updating configuration options. Users or teams will no longer need to manually rework their entire website infrastructure each time a new feature gets added.

-

The Birth of docusaurus

+

The Birth of docusaurus

Birth of Slash

When Facebook first started their open source program, many teams implemented a custom website for each of their open source projects. This approach presented challenges when the open source program team was asked to help the project teams improve their documentation. Since each site was unique, adding basic infrastructure such as a blog, consistent navigation, search, etc. became challenging undertakings.

The open source team tried to help mitigate this problem by coming up with a standard template, based on Jekyll, that could be used as a starting point for a project website. We asked our new projects to manually copy our template source to their repo, write their docs, and publish. This template approach was adopted by most of open source projects launched; some existing projects even converted their custom website implementations to the new template as well.

@@ -32,7 +32,7 @@

So we started thinking about what we could do to help mitigate the challenge of keeping sites updated and consistent across our entire portfolio. We also wanted multiple projects to share the same site generation software. We wanted them to start out with the same template, and yet have the flexibility to customize and adapt their site theme to suit their needs. They should be able to extend and customize their site, but when we update the underlying infrastructure with fixes and features, the project should be able update simply and without any breaking changes.

Docusaurus was born!

At Facebook, Docusaurus allows us to quickly get different projects up and running with documentation websites, especially for teams who don't have much experience with web development or primarily want a basic site to showcase their project. Docusaurus already supports sites needing more advanced features like internationalization for Jest and versioning for React Native. As different projects request new features for their sites, they are added to Docusaurus and simultaneously provided to all projects! All together, this ends up greatly reducing the work needed to maintain different sites for different projects. Our teams are able to focus on keeping their projects healthier by spending more time adding features, fixing bugs, and writing documentation.

-

Getting Up and Running

+

Getting Up and Running

Slash Up and Running

At its core, we wanted sites running Docusaurus to be simple to use. With one installation command and some simple configuration, you can actually have a default running website.

When you run docusaurus-init, you will see a structure similar to:

@@ -57,7 +57,7 @@ │ └── static

With the exception of node_modules and package.json, all the directories and files you see are where you customize and add content to your Docusaurus-based website. The docs folder is where you add your markdown that represents your documentation; the blog folder is where you add your markdown for your blog posts; siteConfig.js is where you make most of the customizations for your site; sidebars.json is where you maintain the layout and content of the sidebar for your documentation; the pages folder is where you add custom pages for your site; the static folder is where all of your static assets go (e.g., CSS stylesheets and images); and the core folder is where you can customize core components of the site, in this case the footer.

-

How does Docusaurus work?

+

How does Docusaurus work?

Docusaurus is written primarily in JavaScript and React, replacing Jekyll which we used in the old template. We use Remarkable for our markdown rendering and highlight.js for our code block syntax highlighting. The core of Docusaurus' functionality is in the lib directory of the Docusaurus repo. The general structure looks like:

root-of-Docusaurus
 ├── lib
@@ -105,10 +105,10 @@
 │   ├── sitemap.xml
 │   └── users.html # custom page
 
-

Community

+

Community

Docusaurus

We welcome your contributions to Docusaurus, whether you want to use it for your own site, you want to contribute to the Docusaurus core or just have questions. Follow us on GitHub and Twitter.

-

Acknowledgements

+

Acknowledgements

Docusaurus wouldn't exist without the work of the rest of the core Docusaurus team: Eric Nakagawa, Hector Ramos, Eric Vicenti and Frank Li — a former intern at Facebook who implemented the core technology and features.

Special thanks also goes out to our earliest adopters of Docusaurus:

Without their dedication to creating or migrating their websites over to the platform, we would have not have been in the position where we are today.

-

Resources

+

Resources

-

Translating Your Existing Docs

+

Translating Your Existing Docs

Your documentation files (e.g., the .md files that live in your docs directory) do not need to be changed or moved to support translations. They will be uploaded to Crowdin to be translated directly.

-

Enabling Translations on Pages

+

Enabling Translations on Pages

Pages allow you to customize layout and specific content of pages like a custom index page or help page.

Pages with text that you want translated should be placed in website/pages/en folder.

Wrap strings you want translated in a <translate> tag, and add the following require statement to the top of the file:

@@ -57,7 +57,7 @@ const translate = require("../../server/translate.js").translate;

The <translate> tag generally works well on pure strings. If you have a string like "Docusaurus currently provides support to help your website use translations", wrapping the <translation> tag around that entire string will cause issues because of the markdown linking, etc. Your options are to not translate those strings, or spread a bunch of <translate> tags amongst the pure substrings of that string.

-

Gathering Strings to Translate

+

Gathering Strings to Translate

The strings within localized Pages must be extracted and provided to Crowdin.

Add the following script to your website/package.json file, if it does not exist already:

...
@@ -75,18 +75,18 @@ const translate = require("../../server/translate.js").translate;
 
  • header link label strings in siteConfig.js
  • strings wrapped in the <translate> tag in any .js files inside pages
  • -

    How Strings Get Translated

    +

    How Strings Get Translated

    Docusaurus itself does not do any translation from one language to another. Instead, it integrates Crowdin to upload translations and then downloads the appropriately translated files from Crowdin.

    -

    How Docusaurus Uses String Translations

    +

    How Docusaurus Uses String Translations

    This section provides context about how translations in Docusaurus works.

    -

    Strings

    +

    Strings

    A Docusaurus site has many strings used throughout it that require localization. However, maintaining a list of strings used through out a site can be laborious. Docusaurus simplifies this by centralizing strings.

    The header navigation, for example can have links to 'Home' or your 'Blog'. This and other strings found in the headers and sidebars of pages are extracted and placed into i18n/en.json. When your files are translated, say into Spanish, a i18n/es-ES.json file will be downloaded from Crowdin. Then, when the Spanish pages are generated, Docusaurus will replace the English version of corresponding strings with translated strings from the corresponding localized strings file (e.g. In a Spanish enabled site 'Help' will become 'Ayuda').

    -

    Markdown Files

    +

    Markdown Files

    For documentation files themselves, translated versions of these files are downloaded and then rendered through the proper layout template.

    -

    Other Pages

    +

    Other Pages

    For other pages, Docusaurus will automatically transform all <translate> tags it finds into function calls that return the translated strings from the corresponding localized file locale.json.

    -

    Crowdin

    +

    Crowdin

    Crowdin is a company that provides translation services. For Open Source projects, Crowdin provides free string translations.

    Create your translation project on Crowdin. You can use Crowdin's guides to learn more about the translations work flow. We suggest that you deselect and do not include "English" as a translatable language to prevent the creation of en-US localization files as this can lead to confusion.

    @@ -120,7 +120,7 @@ const translate = require("../../server/translate.js").translate; 'zh-TW': 'zh-TW'

    You can go here to learn more about customizing your crowdin.yaml file.

    -

    Setup the Crowdin Scripts

    +

    Setup the Crowdin Scripts

    You will want to manually sync your files to and from Crowdin. The sync process will upload any markdown files in /docs as well as translatable strings in website/i18n/en.json. (These strings can be generated by running yarn write-translations.)

    You can add the following to your package.json to manually trigger Crowdin.

    "scripts": {
    @@ -128,7 +128,7 @@ const translate = require("../../server/translate.js").translate;
       "crowdin-download": "crowdin --config ../crowdin.yaml download -b master"
     },
     
    -

    Manual File Sync

    +

    Manual File Sync

    You will always want to upload your markdown files and translatable strings first and the download the translations section. So run the commands in this order:

    CROWDIN_DOCUSAURUS_PROJECT_ID=YOUR_CROWDIN_PROJECT_ID CROWDIN_DOCUSAURUS_API_KEY=YOUR_CROWDIN_API_KEY yarn run crowdin-upload
     CROWDIN_DOCUSAURUS_PROJECT_ID=YOUR_CROWDIN_PROJECT_ID CROWDIN_DOCUSAURUS_API_KEY=YOUR_CROWDIN_API_KEY yarn run crowdin-download
    @@ -145,7 +145,7 @@ const translate = require("../../server/translate.js").translate;
     

    Since the files are generated, you do not need to have any files in your website/i18n or website/translated_docs directory as part of your repo. So you can can add website/i18n/* and website/translated_docs to your .gitignore file.

    -

    Automated File Sync Using CircleCI

    +

    Automated File Sync Using CircleCI

    You can automate pulling down and uploading translations for your files using the CircleCI web continuous integration service.

    First, update the circle.yml file in your project directory to include steps to upload English files to be translated and download translated files using the Crowdin CLI. Here is an example circle.yml file:

    machine:
    @@ -182,7 +182,7 @@ const translate = require("../../server/translate.js").translate;
     

    Note that in the crowdin.yaml file, CROWDIN_PROJECT_ID and CROWDIN_API_KEY are environment variables set-up in Circle for your Crowdin project. They can be found in your Crowdin project settings.

    Now, Circle will help you automatically get translations prior to building your website. The provided crowdin.yaml file will copy translated documents into website/translated_docs/, and translated versions of the i18n/en.json strings file will into i18n/${language}.json.

    If you wish to use Crowdin on your machine locally, you can install the Crowdin CLI tool and run the same commands found in the circle.yaml file. The only difference is that you must set project_identifier and api_key values in the crowdin.yaml file since you will not have Circle environment variables set up.

    -

    Versioned Translations

    +

    Versioned Translations

    If you wish to have translation and versioning for your documentation, add the following section to the end of your crowdin.yaml file:

      -
         source: '/website/versioned_docs/**/*.md'
    diff --git a/docs/en/versioning.html b/docs/en/versioning.html
    index d1ffa0f0df..8d4b67e1fb 100644
    --- a/docs/en/versioning.html
    +++ b/docs/en/versioning.html
    @@ -13,7 +13,7 @@
                 nav.classList.toggle('docsSliderActive');
               };
             
    Edit

    Versioning

    You can use the version script to cut a new documentation version based on the latest content in the docs folder. That specific set of documentation will then be preserved and accessible even as the documentation in the docs folder changes moving forward.

    -

    How to Create New Versions

    +

    How to Create New Versions

    Run the following script to generate a starter versions page listing all the site versions:

    yarn examples versions
     
    @@ -45,18 +45,18 @@ master branchnextdocs/next/doc1.html -

    Versioning Patterns

    +

    Versioning Patterns

    You can create version numbers in whatever format you wish, and a new version can be created with any version number as long as it does not match an existing version. Version ordering is determined by the order in which versions are created, independently of how they are numbered.

    -

    Storing Files for Each Version

    +

    Storing Files for Each Version

    Versioned documents are placed into website/versioned_docs/version-${version}, where ${version} is the version number you supplied the version script.

    The markdown header for each versioned doc is altered by renaming the id front matter field to original_id, then using "version-${version}-${original_id}" as the value for the actual id field.

    Versioned sidebars are copied into website/versioned_sidebars and are named as version-${version}-sidebars.json.

    A website/versions.json file is created the first time you cut a version and is used by Docusaurus to detect what versions exist. Each time a new version is added, it gets added to the versions.json file.

    If you wish to change the documentation for a past version, you can access the files for that respective version.

    -

    Fallback Functionality

    +

    Fallback Functionality

    Only files in the docs folder and sidebar files that differ from those of the latest version will get copied each time a new version is specified. If there is no change across versions, Docusaurus will use the file from the latest version with that file.

    For example, a document with the original id doc1 exists for the latest version, 1.0.0, and has the same content as the document with the id doc1 in the docs folder. When a new version 2.0.0 is created, the file for doc1 will not be copied into versioned_docs/version-2.0.0/. There will still be a page for docs/2.0.0/doc1.html, but it will use the file from version 1.0.0.

    -

    Renaming Existing Versions

    +

    Renaming Existing Versions

    To rename an existing version number to something else, first make sure the following script is in your package.json file:

    ...
     "scripts": {
    @@ -67,7 +67,7 @@
     

    Run the script with command line arguments of first, the current version name, then second, the new version name. e.g.,

    yarn run rename-version 1.0.0 1.0.1
     
    -

    Versioning and Translations

    +

    Versioning and Translations

    If you wish to use versioning and translations features, the crowdin.yaml file should be set up to upload and download versioned documents to and from Crowdin for translation. Translated, versioned files will go into the folder translated_docs/${language}/version-${version}/. For more information, check out the translations guide.