Skip to content

Commit

Permalink
Merge github.com:facebook/docusaurus into lex111/decouple-admonitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Apr 22, 2020
2 parents fea31b3 + 510bec6 commit fdfa0e1
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 104 deletions.
12 changes: 2 additions & 10 deletions admin/scripts/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
set -euo pipefail

CUSTOM_REGISTRY_URL="http://localhost:4873"
npm_config_registry="$CUSTOM_REGISTRY_URL"
ORIGINAL_YARN_REGISTRY_URL=`yarn config get registry`
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version").NEW"
CONTAINER_NAME="verdaccio"

Expand All @@ -14,25 +12,19 @@ docker run -d --rm --name "$CONTAINER_NAME" -p 4873:4873 -v "$PWD/admin/verdacci
# Build packages
yarn tsc

# Set Yarn registry to own local registry
yarn config set registry "$CUSTOM_REGISTRY_URL"

# Publish the monorepo
npx --no-install lerna publish --yes --no-verify-access --no-git-reset --no-git-tag-version --no-push --registry "$CUSTOM_REGISTRY_URL" "$NEW_VERSION"

# Revert version changes
git diff --name-only -- '*.json' | sed 's, ,\\&,g' | xargs git checkout --

# Build skeleton website with new version
npx @docusaurus/init@latest init test-website classic

# Restore the original Yarn registry URL
yarn config set registry "$ORIGINAL_YARN_REGISTRY_URL"
npm_config_registry="$CUSTOM_REGISTRY_URL" npx @docusaurus/init@"$NEW_VERSION" init test-website classic

# Stop Docker container
if ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
# Remove Docker container
docker container stop $CONTAINER_NAME
docker container stop $CONTAINER_NAME > /dev/null
fi

echo "The website with to-be published packages was successfully build to the $(tput setaf 2)test-website$(tput sgr 0) directory."
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ module.exports = {
label: 'Discord',
href: 'https://discordapp.com/invite/docusaurus',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
},
],
},
{
title: 'Social',
title: 'More',
items: [
{
label: 'GitHub',
href: 'https://github.com/facebook/docusaurus',
label: 'Blog',
to: 'blog',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
label: 'GitHub',
href: 'https://github.com/facebook/docusaurus',
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-init/templates/classic/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ module.exports = {
label: 'Discord',
href: 'https://discordapp.com/invite/docusaurus',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
},
],
},
{
title: 'Social',
title: 'More',
items: [
{
label: 'Blog',
Expand All @@ -68,10 +72,6 @@ module.exports = {
label: 'GitHub',
href: 'https://github.com/facebook/docusaurus',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
},
],
},
],
Expand Down
28 changes: 23 additions & 5 deletions packages/docusaurus-init/templates/facebook/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
style: 'dark',
links: [
{
title: 'Docs',
title: 'Learn',
items: [
{
label: 'Style Guide',
Expand All @@ -61,14 +61,18 @@ module.exports = {
label: 'Stack Overflow',
href: 'https://stackoverflow.com/questions/tagged/docusaurus',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
},
{
label: 'Discord',
href: 'https://discordapp.com/invite/docusaurus',
},
],
},
{
title: 'Social',
title: 'More',
items: [
{
label: 'Blog',
Expand All @@ -78,17 +82,31 @@ module.exports = {
label: 'GitHub',
href: 'https://github.com/facebook/docusaurus',
},
],
},
{
title: 'Legal',
// Please do not remove the privacy and terms, it's a legal requirement.
items: [
{
label: 'Privacy',
href: 'https://opensource.facebook.com/legal/privacy/',
target: '_blank',
rel: 'noreferrer noopener',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
label: 'Terms',
href: 'https://opensource.facebook.com/legal/terms/',
target: '_blank',
rel: 'noreferrer noopener',
},
],
},
],
logo: {
alt: 'Facebook Open Source Logo',
src: 'img/oss_logo.png',
href: 'https://opensource.facebook.com/',
href: 'https://opensource.facebook.com',
},
// Please do not remove the credits, help to publicize Docusaurus :)
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc. Built with Docusaurus.`,
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-module-type-aliases/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@docusaurus/module-type-aliases",
"version": "2.0.0-alpha.50",
"description": "Docusaurus module type aliases",
"types": "./src/index.d.ts",
"publishConfig": {
"access": "public"
},
"license": "MIT"
}
43 changes: 43 additions & 0 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

declare module '@generated/client-modules' {
const clientModules: readonly any[];
export default clientModules;
}

declare module '@generated/docusaurus.config' {
const config: any;
export default config;
}

declare module '@generated/registry' {
const registry: {
readonly [key: string]: [() => Promise<any>, string, string];
};
export default registry;
}

declare module '@generated/routes' {
type Route = {
readonly path: string;
readonly component: any;
readonly exact?: boolean;
};
const routes: Route[];
export default routes;
}

declare module '@generated/routesChunkNames' {
const routesChunkNames: any;
export default routesChunkNames;
}

declare module '@theme/*' {
const component: any;
export default component;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {useState, useCallback, useEffect} from 'react';
import {useLocation} from '@docusaurus/router';
import useLocationHash from '@theme/hooks/useLocationHash';
import useScrollPosition from '@theme/hooks/useScrollPosition';

const useHideableNavbar = (hideOnScroll) => {
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
Expand All @@ -22,47 +23,41 @@ const useHideableNavbar = (hideOnScroll) => {
const location = useLocation();
const [hash, setHash] = useLocationHash(location.hash);

const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
useScrollPosition(
({scrollY: scrollTop}) => {
if (!hideOnScroll) {
return;
}

if (scrollTop === 0) {
setIsNavbarVisible(true);
}

if (scrollTop < navbarHeight) {
return;
}

if (isFocusedAnchor) {
setIsFocusedAnchor(false);
setIsNavbarVisible(false);
setLastScrollTop(scrollTop);
return;
}

const documentHeight =
document.documentElement.scrollHeight - navbarHeight;
const windowHeight = window.innerHeight;

if (lastScrollTop && scrollTop >= lastScrollTop) {
setIsNavbarVisible(false);
} else if (scrollTop + windowHeight < documentHeight) {
setIsNavbarVisible(true);
}

if (scrollTop === 0) {
setIsNavbarVisible(true);
}

if (scrollTop < navbarHeight) {
return;
}

if (isFocusedAnchor) {
setIsFocusedAnchor(false);
setIsNavbarVisible(false);
setLastScrollTop(scrollTop);
return;
}

const documentHeight = document.documentElement.scrollHeight - navbarHeight;
const windowHeight = window.innerHeight;

if (lastScrollTop && scrollTop >= lastScrollTop) {
setIsNavbarVisible(false);
} else if (scrollTop + windowHeight < documentHeight) {
setIsNavbarVisible(true);
}

setLastScrollTop(scrollTop);
};

useEffect(() => {
if (!hideOnScroll) {
return undefined;
}

window.addEventListener('scroll', handleScroll);

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, [lastScrollTop, navbarHeight]);
},
[lastScrollTop, navbarHeight],
);

useEffect(() => {
if (!hideOnScroll) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {useState, useEffect} from 'react';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';

const getScrollPosition = () => ({
scrollX: ExecutionEnvironment.canUseDOM ? window.pageXOffset : 0,
scrollY: ExecutionEnvironment.canUseDOM ? window.pageYOffset : 0,
});

const useScrollPosition = (effect, deps = []) => {
const [scrollPosition, setScrollPosition] = useState(getScrollPosition());

const handleScroll = () => {
const currentScrollPosition = getScrollPosition();

setScrollPosition(currentScrollPosition);

if (effect) {
effect(currentScrollPosition);
}
};

useEffect(() => {
window.addEventListener('scroll', handleScroll);

return () =>
window.removeEventListener('scroll', handleScroll, {
passive: true,
});
}, deps);

return scrollPosition;
};

export default useScrollPosition;
16 changes: 15 additions & 1 deletion packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export function getSubFolder(file: string, refDir: string): string | null {
return match && match[1];
}

// Regex for an import statement.
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];';

export function parse(
fileString: string,
): {
Expand All @@ -193,7 +196,18 @@ export function parse(
} {
const options: {} = {
excerpt: (file: matter.GrayMatterFile<string>): void => {
file.excerpt = file.content.trim().split('\n', 1).shift();
let fileContent = file.content.trimLeft();

// Hacky way of stripping out import statements from the excerpt
// TODO: Find a better way to do so, possibly by compiling the Markdown content,
// stripping out HTML tags and obtaining the first line.
if (RegExp(importRegexString).test(fileContent)) {
fileContent = fileContent
.replace(RegExp(importRegexString, 'gm'), '')
.trimLeft();
}

file.excerpt = fileContent.split('\n', 1).shift();
},
};

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"url": "https://github.com/facebook/docusaurus/issues"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^2.0.0-alpha.50",
"@docusaurus/types": "^2.0.0-alpha.50"
},
"dependencies": {
Expand Down
Loading

0 comments on commit fdfa0e1

Please sign in to comment.