docusaurus/docs/en/publishing.html
2017-10-04 16:19:06 +00:00

25 lines
No EOL
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/><title>Publishing your site · Docusaurus</title><meta name="viewport" content="width=device-width"/><meta property="og:title" content="Publishing your site · Docusaurus"/><meta property="og:type" content="website"/><meta property="og:url" content="https://docusaurus.io/index.html"/><meta property="og:description" content="You should now have a site up and running locally. Once you have customized it to your liking, it&#x27;s time to publish it. Docusaurus generates a static HTML website that is ready to be served by your favorite web server or online hosting solution."/><meta name="robots" content="noindex"/><link rel="shortcut icon" href="/img/docusaurus.ico"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"/><link rel="stylesheet" href="/css/main.css"/><link rel="alternate" type="application/atom+xml" href="https://docusaurus.io/blog/atom.xml" title="Docusaurus Blog ATOM Feed"/> <link rel="alternate" type="application/rss+xml" href="https://docusaurus.io/blog/feed.xml" title="Docusaurus Blog RSS Feed"/><script async="" defer="" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/js/webplayer.js"></script><script type="text/javascript" src="https://snack.expo.io/embed.js"></script></head><body class="sideNavVisible"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/"><img class="logo" src="/img/docusaurus.svg"/><h2 class="headerTitle">Docusaurus</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li><a href="/docs/en/installation.html" target="_self">Docs</a></li><li><a href="/en/help.html" target="_self">Help</a></li><li><a href="/blog" target="_self">Blog</a></li><li><a target="_self"></a></li><li><a href="https://github.com/facebookexperimental/docusaurus" target="_self">GitHub</a></li><li class="navSearchWrapper reactNavSearchWrapper"><input type="text" id="search_input_react" placeholder="Search"/></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><i></i></div><h2><i></i><span>Getting Started</span></h2></div><div class="navGroups"><div class="navGroup navGroupActive"><h3>Getting Started</h3><ul><li class="navListItem"><a class="navItem" href="/docs/en/installation.html#content">Installation</a></li><li class="navListItem"><a class="navItem" href="/docs/en/site-preparation.html#content">Site Preparation</a></li><li class="navListItem"><a class="navItem" href="/docs/en/site-creation.html#content">Creating your site</a></li><li class="navListItem navListItemActive"><a class="navItem navItemActive" href="/docs/en/publishing.html#content">Publishing your site</a></li></ul></div><div class="navGroup navGroupActive"><h3>Guides</h3><ul><li class="navListItem"><a class="navItem" href="/docs/en/custom-pages.html#content">Custom Pages</a></li><li class="navListItem"><a class="navItem" href="/docs/en/navigation.html#content">Navigation and Sidebars</a></li><li class="navListItem"><a class="navItem" href="/docs/en/blog.html#content">Adding a Blog</a></li><li class="navListItem"><a class="navItem" href="/docs/en/translation.html#content">Translations &amp; Localization</a></li><li class="navListItem"><a class="navItem" href="/docs/en/search.html#content">Enabling Search</a></li><li class="navListItem"><a class="navItem" href="/docs/en/versioning.html#content">Versioning</a></li></ul></div><div class="navGroup navGroupActive"><h3>API</h3><ul><li class="navListItem"><a class="navItem" href="/docs/en/commands.html#content">CLI Commands</a></li><li class="navListItem"><a class="navItem" href="/docs/en/api-pages.html#content">Pages and Styles</a></li><li class="navListItem"><a class="navItem" href="/docs/en/site-config.html#content">siteConfig.js</a></li><li class="navListItem"><a class="navItem" href="/docs/en/doc-markdown.html#content">Markdown Features</a></li></ul></div></div></section></div><script>
var toggler = document.getElementById('navToggler');
var nav = document.getElementById('docsNav');
toggler.onclick = function() {
nav.classList.toggle('docsSliderActive');
};
</script></nav></div><div class="container mainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/facebookexperimental/docusaurus/edit/master/docs/getting-started-publishing.md" target="_blank">Edit this Doc</a><h1>Publishing your site</h1></header><article><div><p>You should now have a site up and running locally. Once you have customized it to your liking, it&#x27;s time to publish it. Docusaurus generates a static HTML website that is ready to be served by your favorite web server or online hosting solution.</p><h2><a class="anchor" name="building-static-html-pages"></a>Building Static HTML Pages <a class="hash-link" href="#building-static-html-pages">#</a></h2><p>To create a static build of your website, run the script:</p><pre class="prism language-javascript">npm run build</pre><p>or</p><pre class="prism language-javascript">yarn run build</pre><p>This will generate <code>.html</code> files from all of your docs and other pages included in <code>pages</code>. The build folder is inside Docusaurus&#x27;s directory inside <code>node_modules</code>.</p><h2><a class="anchor" name="hosting-static-html-pages"></a>Hosting Static HTML Pages <a class="hash-link" href="#hosting-static-html-pages">#</a></h2><p>At this point, you can grab all of the files inside the <code>node_modules/docusaurus/build</code> folder and copy them over to your favorite web server&#x27;s &quot;html&quot; directory. For example, both Apache and nginx serve content from <code>/var/www/html</code> by default. You&#x27;ll still need to host the web server somewhere, and as it happens, choosing a web hosting provider is out of scope for this guide. Don&#x27;t fret, as Docusaurus was designed to work really well with one of the most popular hosting solutions for open source projects: GitHub Pages.</p><h3><a class="anchor" name="using-github-pages"></a>Using GitHub Pages <a class="hash-link" href="#using-github-pages">#</a></h3><p>Deploying your Docusaurus site to GitHub Pages is straightforward if you are already using GitHub to host your project. Your code repository does not even need to be public. Most of the work is done for you automatically through the <a href="./commands.md#docusaurus-publish" target="_blank"><code>publish-gh-pages</code></a> script.</p><p>Before you go ahead and do that, you need to determine the values for a few parameters required by the script. They are:</p><ul><li><code>CIRCLE_PROJECT_REPONAME</code>: The name of the GitHub repository for your project. For example, Docusaurus is hosted at <a href="https://github.com/facebookexperimental/docusaurus">https://github.com/facebookexperimental/docusaurus</a>, so our repo name in this case would be &quot;docusaurus&quot;. </li><li><code>CIRCLE_PROJECT_USERNAME</code>: The GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the &quot;facebookexperimental&quot; GitHub organization.</li><li><code>GITHUB_USERNAME</code>: The username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your own GitHub username.</li><li><code>CIRCLE_BRANCH</code>: The branch that contains the latest docs changes that will be deployed. Usually, &quot;master&quot;.</li></ul><p>Once you have this information, you can go ahead and run the <code>publish-gh-pages</code> script like so (making sure to insert your own values inside the <code>&lt;placeholders&gt;</code>):</p><pre class="prism language-javascript">GIT_USER<span class="token operator">=</span><span class="token operator">&lt;</span>GIT_USER<span class="token operator">&gt;</span> CIRCLE_PROJECT_USERNAME<span class="token operator">=</span><span class="token operator">&lt;</span>CIRCLE_PROJECT_REPONAME<span class="token operator">&gt;</span> CIRCLE_PROJECT_REPONAME<span class="token operator">=</span><span class="token operator">&lt;</span>CIRCLE_PROJECT_USERNAME<span class="token operator">&gt;</span> CIRCLE_BRANCH<span class="token operator">=</span>master yarn run publish<span class="token operator">-</span>gh<span class="token operator">-</span>pages</pre><p>You should now be able to load your website by visiting its GitHub Pages URL, which should be something along the lines of <a href="https://CIRCLE_PROJECT_USERNAME.github.io/CIRCLE_PROJECT_REPONAME">https://CIRCLE_PROJECT_USERNAME.github.io/CIRCLE_PROJECT_REPONAME</a>. For example, Docusaurus&#x27;s own GitHub Pages URL is <a href="https://facebookexperimental.github.io/docusaurus">https://facebookexperimental.github.io/docusaurus</a>, because it is served from the <code>gh-pages</code> branch of the <a href="https://github.com/facebookexperimental/docusaurus">https://github.com/facebookexperimental/docusaurus</a> GitHub repo. We highly encourage reading through the <a href="https://pages.github.com" target="_blank">GitHub Pages documentation</a> to learn more about how this hosting solution works. </p><p>You can run the command above any time you update the docs and wish to deploy the changes to your site. That&#x27;s usually fine for sites where the documentation rarely changes, where it&#x27;s not too much of an inconvenience to remember to manually deploy changes. Now, if you&#x27;re wondering if this process can be automated in any way, keep reading...</p><h2><a class="anchor" name="automating-deployments-using-continuous-integration"></a>Automating Deployments Using Continuous Integration <a class="hash-link" href="#automating-deployments-using-continuous-integration">#</a></h2><p>Continuous integration services are typically used to perform routine tasks whenever new commits are checked in to source control. These tasks can be any combination of running unit tests and integration tests, automating builds, publishing packages to NPM, and yes, deploying changes to your website. All you need to do to automate deployment of your website is to invoke the <code>publish-gh-pages</code> script whenever your docs get updated. In the following section we&#x27;ll be covering how to do just that using Circle CI, a popular continuous integration service provider.</p><h3><a class="anchor" name="using-circle-ci"></a>Using Circle CI <a class="hash-link" href="#using-circle-ci">#</a></h3><p>If you&#x27;re already using Circle CI for your project, all you need to do to enable automatic deployments is to configure Circle to run the <code>publish-gh-pages</code> script as part of the deployment step.</p><ol><li>Go to <a href="https://github.com/settings/tokens">https://github.com/settings/tokens</a> and generate a new token, granting it full control of private repositories through the <code>repo</code> access scope. Store this token in a safe place, making sure to not share it with anyone. This token can be used to authenticate GitHub actions on your behalf in place of your GitHub password.</li><li>Open your Circle CI dashboard, and navigate to the Settings page for your repository, then select &quot;Environment variables&quot;. The URL looks like <a href="https://circleci.com/gh/facebookexperimental/docusaurus/edit#env-vars">https://circleci.com/gh/facebookexperimental/docusaurus/edit#env-vars</a>, where &quot;facebookexperimental/docusaurus&quot; should be replaced with your own GitHub user/repo.</li><li>Create a new environment variable named &quot;GITHUB_TOKEN&quot;, using your newly generated access token as the value.</li><li><p>Open your <code>circle.yml</code> file and add the following under the <code>machine:</code> section to tell Circle to use relatively recent versions of node and npm, replacing npm with yarn if applicable:</p><pre class="prism language-javascript">machine<span class="token punctuation">:</span>
node<span class="token punctuation">:</span>
version<span class="token punctuation">:</span> <span class="token number">6.11</span><span class="token punctuation">.</span><span class="token number">2</span>
npm<span class="token punctuation">:</span>
version<span class="token punctuation">:</span> <span class="token number">3.10</span><span class="token punctuation">.</span><span class="token number">10</span></pre></li><li><p>Then, add the following lines to the <code>deployment:</code> section. If you don&#x27;t have a <code>deployment:</code> section, you can add it at the end of the file.</p><pre class="prism language-javascript">deployment<span class="token punctuation">:</span>
website<span class="token punctuation">:</span>
branch<span class="token punctuation">:</span> master
commands<span class="token punctuation">:</span>
<span class="token operator">-</span> git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>email <span class="token string">&quot;&lt;GITHUB_USERNAME&gt;@users.noreply.github.com&quot;</span>
<span class="token operator">-</span> git config <span class="token operator">--</span>global user<span class="token punctuation">.</span>name <span class="token string">&quot;&lt;YOUR_NAME&gt;&quot;</span>
<span class="token operator">-</span> echo <span class="token string">&quot;machine github.com login &lt;GITHUB_USERNAME&gt; password $GITHUB_TOKEN&quot;</span> <span class="token operator">&gt;</span> <span class="token operator">~</span><span class="token operator">/</span><span class="token punctuation">.</span>netrc
<span class="token operator">-</span> cd website <span class="token operator">&amp;&amp;</span> npm install <span class="token operator">&amp;&amp;</span> GIT_USER<span class="token operator">=</span><span class="token operator">&lt;</span>GITHUB_USERNAME<span class="token operator">&gt;</span> npm run publish<span class="token operator">-</span>gh<span class="token operator">-</span>pages</pre></li></ol><p>Make sure to replace <code>&lt;GITHUB_USERNAME&gt;</code> with your actual GitHub username. <strong>DO NOT</strong> place the actual value of $GITHUB_TOKEN in <code>circle.yml</code>. We already configured that as an environment variable back in Step 3. Since the script will run within the Circle environment, the values of <code>CIRCLE_PROJECT_USERNAME</code>, <code>CIRCLE_PROJECT_REPONAME</code>, and <code>CIRCLE_BRANCH</code> are already defined as environment variables and will be picked up by the script automatically.</p><p>Now, whenever a new commit lands in <code>master</code>, Circle will run your suite of tests and, if everything passes, your website will be deployed via the <code>publish-gh-pages</code> script.</p></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="site-creation.html#content">← Previous</a><a class="docs-next button" href="custom-pages.html#content">Next →</a></div></div></div></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/docusaurus_monochrome.svg" alt="Docusaurus" width="66" height="58"/></a><div><h5>Docs</h5><a href="
/docs/installation.html">Getting Started</a></div><div><h5>Community</h5><a href="/en/users.html">User Showcase</a></div><div><h5>More</h5><a href="https://github.com/facebookexperimental/docusaurus">GitHub</a><a class="github-button" href="https://github.com/facebookexperimental/docusaurus" data-icon="octicon-star" data-count-href="/facebookexperimental/docusaurus/stargazers" data-count-api="/repos/facebookexperimental/docusaurus#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright"><span>Copyright © 2017 Facebook Inc.</span></section></footer></div><script type="text/javascript" src="//cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
var search = docsearch({
apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c',
indexName: 'docusaurus',
inputSelector: '#search_input_react'
});
</script></body></html>