Skip to content

Commit

Permalink
Merge branch 'master' of github.com:facebook/docusaurus into lex111/d…
Browse files Browse the repository at this point in the history
…ocs-route
  • Loading branch information
lex111 committed Apr 24, 2020
2 parents eaf2d35 + 70f6023 commit 92d16c7
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 75 deletions.
10 changes: 2 additions & 8 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# https://help.github.com/articles/about-codeowners/

/packages/docusaurus-1.x/ @yangshun
/packages/docusaurus-plugin-content-docs/ @yangshun
/packages/docusaurus-plugin-content-blog/ @yangshun
/packages/docusaurus-mdx-loader/ @yangshun
/packages/docusaurus-theme-classic/ @yangshun @lex111 @wgao19
/packages/docusaurus-init-1.x/ @yangshun
/packages/docusaurus/ @yangshun
/packages/ @yangshun
/packages/docusaurus-theme-classic/ @lex111
/website/ @yangshun
/website/docs/ @wgao19
/website-1.x/ @yangshun
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"globby": "^10.0.1",
"loader-utils": "^1.2.3",
"lodash.kebabcase": "^4.1.1",
"reading-time": "^1.2.0"
"reading-time": "^1.2.0",
"remark-admonitions": "^1.2.1"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0",
Expand Down
19 changes: 19 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fs from 'fs-extra';
import kebabCase from 'lodash.kebabcase';
import path from 'path';
import admonitions from 'remark-admonitions';
import {normalizeUrl, docuHash, aliasedSitePath} from '@docusaurus/utils';

import {
Expand Down Expand Up @@ -45,6 +46,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
rehypePlugins: [],
editUrl: undefined,
truncateMarker: /<!--\s*(truncate)\s*-->/, // Regex.
admonitions: {},
};

function assertFeedTypes(val: any): asserts val is FeedType {
Expand Down Expand Up @@ -72,6 +74,13 @@ export default function pluginContentBlog(
opts: Partial<PluginOptions>,
): Plugin<BlogContent | null> {
const options: PluginOptions = {...DEFAULT_OPTIONS, ...opts};

if (options.admonitions) {
options.remarkPlugins = options.remarkPlugins.concat([
[admonitions, opts.admonitions || {}],
]);
}

const {siteDir, generatedFilesDir} = context;
const contentPath = path.resolve(siteDir, options.path);
const dataDir = path.join(
Expand All @@ -89,6 +98,16 @@ export default function pluginContentBlog(
return [...globPattern];
},

getClientModules() {
const modules = [];

if (options.admonitions) {
modules.push('remark-admonitions/styles/infima.css');
}

return modules;
},

// Fetches blog contents and returns metadata for the necessary routes.
async loadContent() {
const {postsPerPage, routeBasePath} = options;
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface PluginOptions {
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
remarkPlugins: string[];
remarkPlugins: ([Function, object] | Function)[];
rehypePlugins: string[];
truncateMarker: RegExp;
showReadingTime: boolean;
Expand All @@ -40,6 +40,7 @@ export interface PluginOptions {
language?: string;
};
editUrl?: string;
admonitions: any;
}

export interface BlogTags {
Expand Down
13 changes: 13 additions & 0 deletions packages/docusaurus-plugin-content-blog/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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 'remark-admonitions' {
type Options = any;

const plugin: (options?: Options) => void;
export = plugin;
}
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"lodash.groupby": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.pickby": "^4.6.0",
"remark-admonitions": "^1.2.1",
"shelljs": "^0.8.3"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`simple website content 1 1`] = `
exports[`simple website content 1`] = `
Object {
"docs": Array [
Object {
Expand Down Expand Up @@ -50,7 +50,7 @@ Object {
}
`;

exports[`simple website content 1 2`] = `
exports[`simple website content 2`] = `
Array [
Object {
"component": "@theme/DocPage",
Expand Down Expand Up @@ -114,7 +114,7 @@ Array [
]
`;

exports[`versioned website content 2 1`] = `
exports[`versioned website content 1`] = `
Array [
Object {
"component": "@theme/DocPage",
Expand Down Expand Up @@ -232,7 +232,7 @@ Array [
]
`;

exports[`versioned website content 2: all sidebars 1`] = `
exports[`versioned website content: all sidebars 1`] = `
Object {
"docs": Array [
Object {
Expand Down Expand Up @@ -314,7 +314,7 @@ Object {
}
`;

exports[`versioned website content 2: base metadata for first version 1`] = `
exports[`versioned website content: base metadata for first version 1`] = `
Object {
"docsSidebars": Object {
"version-1.0.0/docs": Array [
Expand Down Expand Up @@ -356,7 +356,7 @@ Object {
}
`;

exports[`versioned website content 2: base metadata for latest version 1`] = `
exports[`versioned website content: base metadata for latest version 1`] = `
Object {
"docsSidebars": Object {
"version-1.0.1/docs": Array [
Expand Down Expand Up @@ -392,7 +392,7 @@ Object {
}
`;

exports[`versioned website content 2: base metadata for next version 1`] = `
exports[`versioned website content: base metadata for next version 1`] = `
Object {
"docsSidebars": Object {
"docs": Array [
Expand Down Expand Up @@ -428,7 +428,7 @@ Object {
}
`;

exports[`versioned website content 2: sidebars needed for each version 1`] = `
exports[`versioned website content: sidebars needed for each version 1`] = `
Object {
"1.0.0": Set {
"version-1.0.0/docs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('simple website', () => {
expect(errors.length).toBe(0);
});

test('content 1', async () => {
test('content', async () => {
const content = await plugin.loadContent();
const {
docsMetadata,
Expand Down Expand Up @@ -204,9 +204,6 @@ describe('simple website', () => {
expect(baseMetadata.docsSidebars).toEqual(docsSidebars);
expect(baseMetadata.permalinkToSidebar).toEqual(permalinkToSidebar);

// // Sort the route config like in src/server/plugins/index.ts for consistent snapshot ordering
// sortConfig(routeConfigs);

expect(routeConfigs).not.toEqual([]);
expect(routeConfigs).toMatchSnapshot();
});
Expand Down Expand Up @@ -286,7 +283,7 @@ describe('versioned website', () => {
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
});

test('content 2', async () => {
test('content', async () => {
const content = await plugin.loadContent();
const {
docsMetadata,
Expand Down
19 changes: 19 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import pickBy from 'lodash.pickby';
import globby from 'globby';
import fs from 'fs-extra';
import path from 'path';
import admonitions from 'remark-admonitions';
import {
normalizeUrl,
docuHash,
Expand Down Expand Up @@ -60,13 +61,21 @@ const DEFAULT_OPTIONS: PluginOptions = {
rehypePlugins: [],
showLastUpdateTime: false,
showLastUpdateAuthor: false,
admonitions: {},
};

export default function pluginContentDocs(
context: LoadContext,
opts: Partial<PluginOptions>,
): Plugin<LoadedContent | null> {
const options = {...DEFAULT_OPTIONS, ...opts};

if (options.admonitions) {
options.remarkPlugins = options.remarkPlugins.concat([
[admonitions, options.admonitions],
]);
}

const {siteDir, generatedFilesDir, baseUrl} = context;
const docsDir = path.resolve(siteDir, options.path);
const sourceToPermalink: SourceToPermalink = {};
Expand Down Expand Up @@ -122,6 +131,16 @@ export default function pluginContentDocs(
return [...globPattern, options.sidebarPath];
},

getClientModules() {
const modules = [];

if (options.admonitions) {
modules.push('remark-admonitions/styles/infima.css');
}

return modules;
},

// Fetches blog contents and returns metadata for the contents.
async loadContent() {
const {include, sidebarPath} = options;
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export interface PluginOptions extends MetadataOptions, PathOptions {
include: string[];
docLayoutComponent: string;
docItemComponent: string;
remarkPlugins: string[];
remarkPlugins: ([Function, object] | Function)[];
rehypePlugins: string[];
admonitions: any;
homePageId: string;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/docusaurus-plugin-content-docs/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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 'remark-admonitions' {
type Options = any;

const plugin: (options?: Options) => void;
export = plugin;
}
3 changes: 1 addition & 2 deletions packages/docusaurus-preset-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@docusaurus/plugin-google-gtag": "^2.0.0-alpha.50",
"@docusaurus/plugin-sitemap": "^2.0.0-alpha.50",
"@docusaurus/theme-classic": "^2.0.0-alpha.50",
"@docusaurus/theme-search-algolia": "^2.0.0-alpha.50",
"remark-admonitions": "^1.2.1"
"@docusaurus/theme-search-algolia": "^2.0.0-alpha.50"
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0"
Expand Down
34 changes: 3 additions & 31 deletions packages/docusaurus-preset-classic/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,21 @@
* LICENSE file in the root directory of this source tree.
*/

const admonitions = require('remark-admonitions');

const addAdmonitions = (pluginOptions) => {
if (pluginOptions == null) {
return {
remarkPlugins: [admonitions],
};
}

if (pluginOptions.admonitions === false) {
return pluginOptions;
}

const admonitionsOptions = {
remarkPlugins: (pluginOptions.remarkPlugins || []).concat([
[admonitions, pluginOptions.admonitions || {}],
]),
};

return {
...pluginOptions,
...admonitionsOptions,
};
};

module.exports = function preset(context, opts = {}) {
const {siteConfig = {}} = context;
const {themeConfig} = siteConfig;
const {algolia, googleAnalytics, gtag} = themeConfig;

const docs = addAdmonitions(opts.docs);
const blog = addAdmonitions(opts.blog);

const isProd = process.env.NODE_ENV === 'production';

return {
themes: [
['@docusaurus/theme-classic', opts.theme],
// Don't add this if algolia config is not defined.
algolia && '@docusaurus/theme-search-algolia',
],
plugins: [
['@docusaurus/plugin-content-docs', docs],
['@docusaurus/plugin-content-blog', blog],
['@docusaurus/plugin-content-docs', opts.docs],
['@docusaurus/plugin-content-blog', opts.blog],
['@docusaurus/plugin-content-pages', opts.pages],
isProd && googleAnalytics && '@docusaurus/plugin-google-analytics',
isProd && gtag && '@docusaurus/plugin-google-gtag',
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-theme-classic/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ module.exports = function (context, options) {
getClientModules() {
return [
'infima/dist/css/default/default.css',
'remark-admonitions/styles/infima.css',
customCss,
path.resolve(__dirname, './prism-include-languages'),
];
Expand Down
7 changes: 7 additions & 0 deletions website-1.x/data/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ module.exports = [
fbOpenSource: false,
pinned: false,
},
{
caption: 'Quicksi',
image: '/img/users/quicksi.png',
infoLink: 'https://quicksi-bot.now.sh/',
fbOpenSource: false,
pinned: false,
},
{
caption: 'Rawsec Inventory',
image: '/img/users/rawsec.png',
Expand Down
Binary file added website-1.x/static/img/users/quicksi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions website/docs/using-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ import thumbnail from './path/to/img.png';

#### Options

| Option | Type | Default | Description |
|-----------|-----------|-----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name` | `string` | `ideal-img/[name].[hash:hex:7].[width].[ext]` | Filename template for output files. |
| `sizes` | `array` | _original size_ | Specify all widths you want to use. If a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up). |
| `size` | `integer` | _original size_ | Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up) |
| `min` | `integer` | | As an alternative to manually specifying `sizes`, you can specify `min`, `max` and `steps`, and the sizes will be generated for you. |
| `max` | `integer` | | See `min` above |
| `steps` | `integer` | `4` | Configure the number of images generated between `min` and `max` (inclusive) |
| `quality` | `integer` | `85` | JPEG compression quality |
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` | `ideal-img/[name].[hash:hex:7].[width].[ext]` | Filename template for output files. |
| `sizes` | `array` | _original size_ | Specify all widths you want to use. If a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up). |
| `size` | `integer` | _original size_ | Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up) |
| `min` | `integer` | | As an alternative to manually specifying `sizes`, you can specify `min`, `max` and `steps`, and the sizes will be generated for you. |
| `max` | `integer` | | See `min` above |
| `steps` | `integer` | `4` | Configure the number of images generated between `min` and `max` (inclusive) |
| `quality` | `integer` | `85` | JPEG compression quality |
Loading

0 comments on commit 92d16c7

Please sign in to comment.