siteConfig.js
网站配置的很大一部分是通过编辑 siteConfig
文件来完成的。
用户展示
数组users
用于存储要在网站上显示的所有项目或用户信息。 当前提供的示例 pages/en/index.js
和 pages/en/users.js
文件中有用到这个属性。 每个user
对象都包含有 caption
、image
、infoLink
和 pinned
属性。 caption
是当有人悬停在该用户头像(image
) 上时显示的文本, 而 infoLink
是点击头像后将要跳转的用户信息链接。 pinned
表示是否在首页固定显示。
目前数组users只用于示例文件index.js
和 users.js
中。 如果你不想要用户展示页面或不想在首页展示用户,你可以删除它。
siteConfig 属性
siteConfig
对象包含了网站的大部分配置。
必填属性
baseUrl
- 网站的baseUrl。
colors
- 网站的颜色。
primaryColor
标题导航栏和侧边栏的颜色。secondaryColor
当网站窗口收缩 (包括手机) 时标题导航栏第二行中看到的颜色。- 还可以添加自定义颜色。 例如, 如果添加自定义样式时要用特定的
$myColor
颜色, 则将myColor
字段添加到colors
,就可以轻松完成配置。
copyright
- 网站页脚和信息流中的版权声明。
favicon
- 网站图标的url。
headerIcon
- 标题导航栏中使用的图标的 url。
headerLinks
- Links that will be used in the header navigation bar. The label
field of each object will be the link text and will also be translated for each language.
示例用法:
headerLinks: [
// Links to document with id doc1 for current language/version
{ doc: "doc1", label: "Getting Started" },
// Link to page found at pages/en/help.js or if that does not exist, pages/help.js, for current language
{ page: "help", label: "Help" },
// Links to href destination
{ href: "https://github.com/", label: "GitHub" },
// Links to blog generated by Docusaurus (${baseUrl}blog)
{ blog: true, label: "Blog" },
// Determines search bar position among links
{ search: true },
// Determines language drop down position among links
{ languages: true }
],
noIndex
- 真值。 如果为true, 这是通过header标签来完成的,因此只会影响文档和页面。 我们并不会尝试隐藏静态资源, 只能尽力而为, 因为恶意爬虫仍可以索引您的站点。
organizationName
- GitHub username of the organization or user hosting this project. This is used by the publishing script to determine where your GitHub pages website will be hosted.
projectName
- Project name. This must match your GitHub repo project name (case sensitive).
tagline
- 网站标语。
title
- 网站标题。
url
- url for your site.
可选属性
algolia
- Information for Algolia search integration. If this field is excluded, the search bar will not appear in the header. You must specify two values for this field, and one (appId
) is optional.
apiKey
- the Algolia provided API key for your search.indexName
- the Algolia provided index name for your search (usually this is the project name)appId
- Algolia provides a default scraper for your docs. If you provide your own, you will probably get this id from them.
blogSidebarCount
- Control the number of blog posts that show up in the sidebar. See the adding a blog docs for more information.
cname
- The CNAME for your website. It will go into a CNAME
file when your site it built.
customDocsPath
- By default, Docusaurus expects your documentation to be in a directory called docs
. This directory is at the same level as the website
directory (i.e., not inside the website
directory). You can specify a custom path to your documentation with this field. Note that all of your documentation *.md
files must still reside in a flat hierarchy. You cannot have your documents in nested directories.
customDocsPath: "docs/site"
customDocsPath: "website-docs"
disableHeaderTitle
- An option to disable showing the title in the header next to the header icon. Exclude this field to keep the header as normal, otherwise set to true
.
disableTitleTagline
- An option to disable showing the tagline in the title of main pages. Exclude this field to keep page titles as Title • Tagline
. Set to true
to make page titles just Title
.
editUrl
- url for editing docs, usage example: editUrl + 'en/doc1.md'
. If this field is omitted, there will be no "Edit this Doc" button for each document.
facebookAppId
- If you want Facebook Like/Share buttons at the bottom of your blog posts, provide a Facebook application id, and the buttons will show up on all blog posts.
facebookPixelId
- Facebook Pixel ID to track page views.
fonts
- Font-family css configuration for the site. If a font family is specified in siteConfig.js
as $myFont
, then adding a myFont
key to an array in fonts
will allow you to configure the font. Items appearing earlier in the array will take priority of later elements, so ordering of the fonts matter.
In the below example, we have two sets of font configurations, myFont
and myOtherFont
. Times New Roman
is the preferred font in myFont
. -apple-system
is the preferred in myOtherFont
.
fonts: {
myFont: [
"Times New Roman",
"Serif"
],
myOtherFont: [
"-apple-system",
"system-ui"
]
},
The above fonts would be represented in your CSS file(s) as variables $myFont
and $myOtherFont
.
h1 {
font-family: $myFont;
}
footerIcon
- URL for a footer icon. Currently used in the core/Footer.js
file provided as an example, but it can be removed from that file.
gaTrackingId
- Google Analytics tracking ID to track page views.
highlight
- Syntax highlighting options:
theme
is the name of the theme used by Highlight.js when highlighting code. You can find the list of supported themes here.version
specifies a particular version of Highlight.js to be used.hljs
provides an escape valve by passing an instance of Highlight.js to the function specified here, allowing additional languages to be registered for syntax highlighting.defaultLang
defines a default language. It will be used if one is not specified at the top of the code block. You can find the list of supported languages here.themeUrl
is the custom URL of CSS theme file that you want to use with Highlight.js. If this is provided, thetheme
andversion
fields will be ignored.
markdownPlugins
- An array of plugins to be loaded by Remarkable, the markdown parser and renderer used by Docusaurus. The plugin will receive a reference to the Remarkable instance, allowing custom parsing and rendering rules to be defined.
ogImage
- Local path to an Open Graph image (e.g., img/myImage.png
). This image will show up when your site is shared on Facebook and other websites/apps where the Open Graph protocol is supported.
onPageNav
- If you want a visible navigation option for representing topics on the current page. Currently, there is one accepted value for this option:
separate
- The secondary navigation is a separate pane defaulting on the right side of a document. See http://docusaurus.io/docs/en/translation.html for an example.
scripts
- Array of JavaScript sources to load. The script tag will be inserted in the HTML head.
separateCss
- Folders inside which any css
files will not be processed and concatenated to Docusaurus' styles. This is to support static html
pages that may be separate from Docusaurus with completely separate styles.
stylesheets
- Array of CSS sources to load. The link tag will be inserted in the HTML head.
translationRecruitingLink
- URL for the Help Translate
tab of language selection when languages besides English are enabled. This can be included you are using translations but does not have to be.
twitter
- Set this to true
if you want a Twitter social button to appear at the bottom of your blog posts.
twitterImage
- Local path to your Twitter card image (e.g., img/myImage.png
). This image will show up on the Twitter card when your site is shared on Twitter.
useEnglishUrl
- If you do not have translations enabled (e.g., by having a languages.js
file), but still want a link of the form /docs/en/doc.html
(with the en
), set this to true
.
users
- The users
array mentioned earlier.
wrapPagesHTML
- Boolean flag to indicate whether html
files in /pages
should be wrapped with Docusaurus site styles, header and footer. This feature is experimental and relies on the files being html
fragments instead of complete pages. It inserts the contents of your html
file with no extra processing. Defaults to false
.
Users can also add their own custom fields if they wish to provide some data across different files.
Example siteConfig.js with many available fields
const users = [
{
caption: "User1",
image: "/test-site/img/docusaurus.svg",
infoLink: "https://www.example.com",
pinned: true
}
];
const siteConfig = {
title: "Docusaurus",
tagline: "Generate websites!",
url: "https://docusaurus.io",
baseUrl: "/",
// For github.io type URLS, you would combine the url and baseUrl like:
// url: "https://reasonml.github.io",
// baseUrl: "/reason-react/",
organizationName: "facebook",
projectName: "docusaurus",
noIndex: false,
// For no header links in the top nav bar -> headerLinks: [],
headerLinks: [
{ doc: "doc1", label: "Docs" },
{ page: "help", label: "Help" },
{ search: true },
{ blog: true }
],
headerIcon: "img/docusaurus.svg",
favicon: "img/favicon.png",
colors: {
primaryColor: "#2E8555",
secondaryColor: "#205C3B"
},
editUrl: "https://github.com/facebook/docusaurus/edit/master/docs/",
// Users variable set above
users,
disableHeaderTitle: true,
disableTitleTagline: true,
separateCss: ["static/css/non-docusaurus", "static/assets/separate-css"],
footerIcon: "img/docusaurus.svg",
translationRecruitingLink:
"https://crowdin.com/project/docusaurus",
algolia: {
apiKey:
"0f9f28b9ab9efae89810921a351753b5",
indexName: "github"
},
gaTrackingId: "U-A2352",
highlight: {
theme: 'default'
},
markdownPlugins: [
function foo(md) {
md.renderer.rules.fence_custom.foo = function(tokens, idx, options, env, instance) {
return '<div class="foo">bar</div>';
}
}
],
scripts: [ "https://docusaurus.io/slash.js" ],
stylesheets: [ "https://docusaurus.io/style.css" ],
facebookAppId: "1615782811974223",
facebookPixelId: "352490515235776",
twitter: "true",
twitterImage: "img/docusaurus.png",
ogImage: "img/docusaurus.png",
};
module.exports = siteConfig;