Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): theme config for Footer #1461

Merged
merged 2 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"license": "MIT",
"dependencies": {
"classnames": "^2.2.6",
"docsearch.js": "^2.5.2"
},
"peerDependencies": {
Expand Down
151 changes: 65 additions & 86 deletions packages/docusaurus-theme-classic/src/theme/Footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,77 @@
*/

import React from 'react';
import classnames from 'classnames';

import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

function Footer() {
const context = useDocusaurusContext();
const {siteConfig = {}} = context;

const {
baseUrl,
themeConfig: {footer},
} = siteConfig;

if (!footer) {
return null;
}

const {copyright, links = [], logo} = footer;

return (
<footer className="footer">
<footer
className={classnames('footer', {
'footer--dark': footer.style === 'dark',
})}>
<div className="container">
<div className="row footer__links">
<div className="col">
<h4 className="footer__title">Docs</h4>
<ul className="footer__items">
<li className="footer__item">
<a className="footer__link-item" href="/">
Getting Started
</a>
</li>
<li className="footer__item">
<a className="footer__link-item" href="/">
API
</a>
</li>
<li className="footer__item">
<a className="footer__link-item" href="/">
FAQ
</a>
</li>
</ul>
</div>
<div className="col">
<h4 className="footer__title">Community</h4>
<ul className="footer__items">
<li className="footer__item">
<a className="footer__link-item" href="/">
Users
</a>
</li>
<li className="footer__item">
<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 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>
{links && links.length > 0 && (
<div className="row footer__links">
{links.map((linkItem, i) => (
<div key={`linkItem-${i}`} className="col">
{linkItem.title != null ? (
<h4 className="footer__title">{linkItem.title}</h4>
) : null}
{linkItem.items != null &&
Array.isArray(linkItem.items) &&
linkItem.items.length > 0 ? (
<ul className="footer__items">
{linkItem.items.map(item => (
<li key={item.href || item.to} className="footer__item">
<Link
className="footer__link-item"
{...item}
{...(item.href
? {
target: '_blank',
rel: 'noopener noreferrer',
href: item.href,
}
: {
to: `${baseUrl}${item.to}`,
})}>
{item.label}
</Link>
</li>
))}
</ul>
) : null}
</div>
))}
</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"
/>
)}
{(logo || copyright) && (
<div className="text--center">
{logo && logo.src && (
<div className="margin-bottom--sm">
<img className="footer__logo" alt={logo.alt} src={logo.src} />
</div>
)}
{copyright}
</div>
Copyright © 2019 Facebook, Inc.
</div>
)}
</div>
</footer>
);
Expand Down
8 changes: 3 additions & 5 deletions packages/docusaurus/src/server/load/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const fs = require('fs-extra');
const _ = require('lodash');
const importFresh = require('import-fresh');
const path = require('path');
const {CONFIG_FILE_NAME} = require('../../constants');

Expand Down Expand Up @@ -37,14 +38,11 @@ function formatFields(fields) {
return fields.map(field => `'${field}'`).join(', ');
}

function loadConfig(siteDir, deleteCache = true) {
function loadConfig(siteDir) {
const configPath = path.resolve(siteDir, CONFIG_FILE_NAME);
if (deleteCache) {
delete require.cache[configPath];
}
let loadedConfig = {};
if (fs.existsSync(configPath)) {
loadedConfig = require(configPath); // eslint-disable-line
loadedConfig = importFresh(configPath);
}

const missingFields = REQUIRED_FIELDS.filter(
Expand Down
57 changes: 57 additions & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,63 @@ module.exports = {
{url: 'blog', label: 'Blog'},
{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: [
[
Expand Down