mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 12:52:31 +02:00
feat(v2): theme config for Footer (#1461)
* feat(v2): theme config for Footer * fix: dont show footer if themeConfig.footer is undefined * Import fresh docusaurus.config.js for better hot reload
This commit is contained in:
parent
b91a0fd84a
commit
110126ab1d
4 changed files with 126 additions and 91 deletions
|
@ -8,6 +8,7 @@
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"classnames": "^2.2.6",
|
||||||
"docsearch.js": "^2.5.2"
|
"docsearch.js": "^2.5.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|
|
@ -6,98 +6,77 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
|
import Link from '@docusaurus/Link';
|
||||||
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
||||||
function Footer() {
|
function Footer() {
|
||||||
|
const context = useDocusaurusContext();
|
||||||
|
const {siteConfig = {}} = context;
|
||||||
|
|
||||||
|
const {
|
||||||
|
baseUrl,
|
||||||
|
themeConfig: {footer},
|
||||||
|
} = siteConfig;
|
||||||
|
|
||||||
|
if (!footer) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {copyright, links = [], logo} = footer;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<footer className="footer">
|
<footer
|
||||||
|
className={classnames('footer', {
|
||||||
|
'footer--dark': footer.style === 'dark',
|
||||||
|
})}>
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="row footer__links">
|
{links && links.length > 0 && (
|
||||||
<div className="col">
|
<div className="row footer__links">
|
||||||
<h4 className="footer__title">Docs</h4>
|
{links.map((linkItem, i) => (
|
||||||
<ul className="footer__items">
|
<div key={`linkItem-${i}`} className="col">
|
||||||
<li className="footer__item">
|
{linkItem.title != null ? (
|
||||||
<a className="footer__link-item" href="/">
|
<h4 className="footer__title">{linkItem.title}</h4>
|
||||||
Getting Started
|
) : null}
|
||||||
</a>
|
{linkItem.items != null &&
|
||||||
</li>
|
Array.isArray(linkItem.items) &&
|
||||||
<li className="footer__item">
|
linkItem.items.length > 0 ? (
|
||||||
<a className="footer__link-item" href="/">
|
<ul className="footer__items">
|
||||||
API
|
{linkItem.items.map(item => (
|
||||||
</a>
|
<li key={item.href || item.to} className="footer__item">
|
||||||
</li>
|
<Link
|
||||||
<li className="footer__item">
|
className="footer__link-item"
|
||||||
<a className="footer__link-item" href="/">
|
{...item}
|
||||||
FAQ
|
{...(item.href
|
||||||
</a>
|
? {
|
||||||
</li>
|
target: '_blank',
|
||||||
</ul>
|
rel: 'noopener noreferrer',
|
||||||
|
href: item.href,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
to: `${baseUrl}${item.to}`,
|
||||||
|
})}>
|
||||||
|
{item.label}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="col">
|
)}
|
||||||
<h4 className="footer__title">Community</h4>
|
{(logo || copyright) && (
|
||||||
<ul className="footer__items">
|
<div className="text--center">
|
||||||
<li className="footer__item">
|
{logo && logo.src && (
|
||||||
<a className="footer__link-item" href="/">
|
<div className="margin-bottom--sm">
|
||||||
Users
|
<img className="footer__logo" alt={logo.alt} src={logo.src} />
|
||||||
</a>
|
</div>
|
||||||
</li>
|
)}
|
||||||
<li className="footer__item">
|
{copyright}
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Contribute
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Stack Overflow
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="col">
|
)}
|
||||||
<h4 className="footer__title">Social</h4>
|
|
||||||
<ul className="footer__items">
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
GitHub
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Facebook
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Twitter
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div className="col">
|
|
||||||
<h4 className="footer__title">More</h4>
|
|
||||||
<ul className="footer__items">
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Tutorial
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li className="footer__item">
|
|
||||||
<a className="footer__link-item" href="/">
|
|
||||||
Blog
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="text--center">
|
|
||||||
<div className="margin-bottom--sm">
|
|
||||||
<img
|
|
||||||
className="footer__logo"
|
|
||||||
alt="Facebook Open Source Logo"
|
|
||||||
src="https://docusaurus.io/img/oss_logo.png"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
Copyright © 2019 Facebook, Inc.
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const importFresh = require('import-fresh');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {CONFIG_FILE_NAME} = require('../../constants');
|
const {CONFIG_FILE_NAME} = require('../../constants');
|
||||||
|
|
||||||
|
@ -37,14 +38,11 @@ function formatFields(fields) {
|
||||||
return fields.map(field => `'${field}'`).join(', ');
|
return fields.map(field => `'${field}'`).join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig(siteDir, deleteCache = true) {
|
function loadConfig(siteDir) {
|
||||||
const configPath = path.resolve(siteDir, CONFIG_FILE_NAME);
|
const configPath = path.resolve(siteDir, CONFIG_FILE_NAME);
|
||||||
if (deleteCache) {
|
|
||||||
delete require.cache[configPath];
|
|
||||||
}
|
|
||||||
let loadedConfig = {};
|
let loadedConfig = {};
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
loadedConfig = require(configPath); // eslint-disable-line
|
loadedConfig = importFresh(configPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const missingFields = REQUIRED_FIELDS.filter(
|
const missingFields = REQUIRED_FIELDS.filter(
|
||||||
|
|
|
@ -25,6 +25,63 @@ module.exports = {
|
||||||
{url: 'blog', label: 'Blog'},
|
{url: 'blog', label: 'Blog'},
|
||||||
{url: 'feedback/', label: 'Feedback'},
|
{url: 'feedback/', label: 'Feedback'},
|
||||||
],
|
],
|
||||||
|
footer: {
|
||||||
|
style: 'dark',
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
title: 'Docs',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: 'Introduction',
|
||||||
|
to: 'docs/introduction',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Themes',
|
||||||
|
to: 'docs/themes',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Community',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: 'Stack Overflow',
|
||||||
|
href: 'https://stackoverflow.com/questions/tagged/docusaurus',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Feedback',
|
||||||
|
to: 'feedback',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Discord',
|
||||||
|
href: 'https://discordapp.com/invite/docusaurus',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Social',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: 'Blog',
|
||||||
|
to: 'blog',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'GitHub',
|
||||||
|
href: 'https://github.com/facebook/docusaurus',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Twitter',
|
||||||
|
href: 'https://twitter.com/docusaurus',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
logo: {
|
||||||
|
alt: 'Facebook Open Source Logo',
|
||||||
|
src: 'https://docusaurus.io/img/oss_logo.png',
|
||||||
|
},
|
||||||
|
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue