Skip to content

Commit

Permalink
Merge branch 'main' into pranabdas/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jan 23, 2022
2 parents 40d3b6f + 3d7ba33 commit 302487d
Show file tree
Hide file tree
Showing 49 changed files with 246 additions and 208 deletions.
7 changes: 6 additions & 1 deletion .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

module.exports = {
extends: ['stylelint-config-recommended', 'stylelint-config-prettier'],
extends: ['stylelint-config-standard', 'stylelint-config-prettier'],
plugins: ['stylelint-copyright'],
rules: {
'docusaurus/copyright-header': [
Expand All @@ -26,5 +26,10 @@ module.exports = {
ignorePseudoClasses: ['global'],
},
],
'selector-class-pattern': null,
'custom-property-empty-line-before': null,
'selector-id-pattern': null,
'declaration-empty-line-before': null,
'comment-empty-line-before': null,
},
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"@types/express": "^4.17.2",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/loader-utils": "^2.0.3",
"@types/lodash": "^4.14.168",
"@types/node": "^17.0.8",
"@types/prismjs": "^1.16.2",
Expand Down Expand Up @@ -112,7 +111,7 @@
"sharp": "^0.29.1",
"stylelint": "^14.2.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^6.0.0",
"stylelint-config-standard": "^24.0.0",
"tslib": "^2.3.1",
"typescript": "^4.5.2"
},
Expand All @@ -121,7 +120,7 @@
"eslint --fix"
],
"*.css": [
"stylelint --fix"
"stylelint --allow-empty-input --fix"
],
"*": [
"prettier --ignore-unknown --write"
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
"@docusaurus/logger": "2.0.0-beta.14",
"@docusaurus/utils": "2.0.0-beta.14",
"@mdx-js/mdx": "^1.6.21",
"@mdx-js/react": "^1.6.21",
"escape-html": "^1.0.3",
"file-loader": "^6.2.0",
"fs-extra": "^10.0.0",
"gray-matter": "^4.0.3",
"image-size": "^1.0.1",
"mdast-util-to-string": "^2.0.0",
"remark-emoji": "^2.1.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-mdx-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ export default async function mdxLoader(
transformImage,
{
staticDirs: reqOptions.staticDirs,
filePath,
siteDir: reqOptions.siteDir,
},
],
[
transformLinks,
{
staticDirs: reqOptions.staticDirs,
filePath,
siteDir: reqOptions.siteDir,
},
],
Expand Down
25 changes: 15 additions & 10 deletions packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ const {
loaders: {inlineMarkdownImageFileLoader},
} = getFileLoaderUtils();

interface PluginOptions {
filePath: string;
type PluginOptions = {
staticDirs: string[];
siteDir: string;
}
};

type Context = PluginOptions & {
filePath: string;
};

async function toImageRequireNode(
node: Image,
Expand Down Expand Up @@ -89,7 +92,7 @@ async function ensureImageFileExist(imagePath: string, sourceFilePath: string) {

async function getImageAbsolutePath(
imagePath: string,
{siteDir, filePath, staticDirs}: PluginOptions,
{siteDir, filePath, staticDirs}: Context,
) {
if (imagePath.startsWith('@site/')) {
const imageFilePath = path.join(siteDir, imagePath.replace('@site/', ''));
Expand Down Expand Up @@ -123,11 +126,11 @@ async function getImageAbsolutePath(
}
}

async function processImageNode(node: Image, options: PluginOptions) {
async function processImageNode(node: Image, context: Context) {
if (!node.url) {
throw new Error(
`Markdown image URL is mandatory in "${toMessageRelativeFilePath(
options.filePath,
context.filePath,
)}" file`,
);
}
Expand All @@ -144,15 +147,17 @@ async function processImageNode(node: Image, options: PluginOptions) {
return;
}

const imagePath = await getImageAbsolutePath(parsedUrl.pathname, options);
await toImageRequireNode(node, imagePath, options.filePath);
const imagePath = await getImageAbsolutePath(parsedUrl.pathname, context);
await toImageRequireNode(node, imagePath, context.filePath);
}

const plugin: Plugin<[PluginOptions]> = (options) => {
const transformer: Transformer = async (root) => {
const transformer: Transformer = async (root, vfile) => {
const promises: Promise<void>[] = [];
visit(root, 'image', (node: Image) => {
promises.push(processImageNode(node, options));
promises.push(
processImageNode(node, {...options, filePath: vfile.path!}),
);
});
await Promise.all(promises);
};
Expand Down
23 changes: 13 additions & 10 deletions packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ const {
loaders: {inlineMarkdownLinkFileLoader},
} = getFileLoaderUtils();

interface PluginOptions {
filePath: string;
type PluginOptions = {
staticDirs: string[];
siteDir: string;
}
};

type Context = PluginOptions & {
filePath: string;
};

// transform the link node to a jsx link with a require() call
function toAssetRequireNode(node: Link, assetPath: string, filePath: string) {
Expand Down Expand Up @@ -71,7 +74,7 @@ async function ensureAssetFileExist(assetPath: string, sourceFilePath: string) {

async function getAssetAbsolutePath(
assetPath: string,
{siteDir, filePath, staticDirs}: PluginOptions,
{siteDir, filePath, staticDirs}: Context,
) {
if (assetPath.startsWith('@site/')) {
const assetFilePath = path.join(siteDir, assetPath.replace('@site/', ''));
Expand All @@ -96,15 +99,15 @@ async function getAssetAbsolutePath(
return null;
}

async function processLinkNode(node: Link, options: PluginOptions) {
async function processLinkNode(node: Link, context: Context) {
if (!node.url) {
// try to improve error feedback
// see https://github.com/facebook/docusaurus/issues/3309#issuecomment-690371675
const title = node.title || (node.children[0] as Literal)?.value || '?';
const line = node?.position?.start?.line || '?';
throw new Error(
`Markdown link URL is mandatory in "${toMessageRelativeFilePath(
options.filePath,
context.filePath,
)}" file (title: ${title}, line: ${line}).`,
);
}
Expand All @@ -122,17 +125,17 @@ async function processLinkNode(node: Link, options: PluginOptions) {
return;
}

const assetPath = await getAssetAbsolutePath(parsedUrl.pathname, options);
const assetPath = await getAssetAbsolutePath(parsedUrl.pathname, context);
if (assetPath) {
toAssetRequireNode(node, assetPath, options.filePath);
toAssetRequireNode(node, assetPath, context.filePath);
}
}

const plugin: Plugin<[PluginOptions]> = (options) => {
const transformer: Transformer = async (root) => {
const transformer: Transformer = async (root, vfile) => {
const promises: Promise<void>[] = [];
visit(root, 'link', (node: Link) => {
promises.push(processLinkNode(node, options));
promises.push(processLinkNode(node, {...options, filePath: vfile.path!}));
});
await Promise.all(promises);
};
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@docusaurus/utils": "2.0.0-beta.14",
"@docusaurus/utils-common": "2.0.0-beta.14",
"@docusaurus/utils-validation": "2.0.0-beta.14",
"chalk": "^4.1.2",
"eta": "^1.12.3",
"fs-extra": "^10.0.0",
"lodash": "^4.17.20",
Expand Down
6 changes: 2 additions & 4 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
"@docusaurus/mdx-loader": "2.0.0-beta.14",
"@docusaurus/utils": "2.0.0-beta.14",
"@docusaurus/utils-validation": "2.0.0-beta.14",
"escape-string-regexp": "^4.0.0",
"feed": "^4.2.2",
"fs-extra": "^10.0.0",
"globby": "^11.0.2",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"reading-time": "^1.5.0",
"remark-admonitions": "^1.2.1",
Expand All @@ -36,7 +33,8 @@
"webpack": "^5.61.0"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.14"
"@docusaurus/types": "2.0.0-beta.14",
"escape-string-regexp": "^4.0.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import {truncate, linkify} from './blogUtils';
import {parseQuery} from 'loader-utils';
import type {BlogMarkdownLoaderOptions} from './types';
import type {LoaderContext} from 'webpack';

Expand All @@ -28,7 +27,7 @@ export default function markdownLoader(

// Truncate content if requested (e.g: file.md?truncated=true).
const truncated: boolean | undefined = this.resourceQuery
? !!parseQuery(this.resourceQuery).truncated
? !!new URLSearchParams(this.resourceQuery.slice(1)).get('truncated')
: undefined;

if (truncated) {
Expand Down
4 changes: 1 addition & 3 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
"@docusaurus/utils": "2.0.0-beta.14",
"@docusaurus/utils-validation": "2.0.0-beta.14",
"combine-promises": "^1.1.0",
"escape-string-regexp": "^4.0.0",
"fs-extra": "^10.0.0",
"globby": "^11.0.2",
"import-fresh": "^3.2.2",
"js-yaml": "^4.0.0",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"remark-admonitions": "^1.2.1",
"shelljs": "^0.8.4",
Expand All @@ -47,6 +44,7 @@
"@types/js-yaml": "^4.0.0",
"@types/picomatch": "^2.2.1",
"commander": "^5.1.0",
"escape-string-regexp": "^4.0.0",
"picomatch": "^2.1.1",
"utility-types": "^3.10.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
*/

import {
type ActivePlugin,
getActivePlugin,
getLatestVersion,
getActiveDocContext,
getActiveVersion,
getDocVersionSuggestions,
} from '../docsClientUtils';
import type {GlobalPluginData, GlobalVersion} from '../../types';
import type {
GlobalPluginData,
GlobalVersion,
ActivePlugin,
} from '@docusaurus/plugin-content-docs/client';
import {shuffle} from 'lodash';

describe('docsClientUtils', () => {
Expand Down Expand Up @@ -58,6 +61,34 @@ describe('docsClientUtils', () => {
expect(getActivePlugin(data, '/android')).toEqual(activePluginAndroid);
expect(getActivePlugin(data, '/android/')).toEqual(activePluginAndroid);
expect(getActivePlugin(data, '/android/ijk')).toEqual(activePluginAndroid);

// https://github.com/facebook/docusaurus/issues/6434
const onePluginAtRoot = {
pluginIosId: {
path: '/',
versions: [],
},
pluginAndroidId: {
path: '/android',
versions: [],
},
};
expect(getActivePlugin(onePluginAtRoot, '/android/foo').pluginId).toEqual(
'pluginAndroidId',
);
const onePluginAtRootReversed = {
pluginAndroidId: {
path: '/android',
versions: [],
},
pluginIosId: {
path: '/',
versions: [],
},
};
expect(
getActivePlugin(onePluginAtRootReversed, '/android/foo').pluginId,
).toEqual('pluginAndroidId');
});

test('getLatestVersion', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ export function getActivePlugin(
pathname: string,
options: GetActivePluginOptions = {},
): ActivePlugin | undefined {
const activeEntry = Object.entries(allPluginDatas).find(
([_id, pluginData]) =>
!!matchPath(pathname, {
path: pluginData.path,
exact: false,
strict: false,
}),
);
const activeEntry = Object.entries(allPluginDatas)
// A quick route sorting: '/android/foo' should match '/android' instead of '/'
.sort((a, b) => b[1].path.localeCompare(a[1].path))
.find(
([, pluginData]) =>
!!matchPath(pathname, {
path: pluginData.path,
exact: false,
strict: false,
}),
);

const activePlugin: ActivePlugin | undefined = activeEntry
? {pluginId: activeEntry[0], pluginData: activeEntry[1]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
font-size: clamp(12px, 4vw, 16px);
text-align: center;
border-radius: 4px;
padding: 6px 6px;
padding: 6px;
}

.navlink:hover {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-ideal-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@docusaurus/lqip-loader": "2.0.0-beta.14",
"@docusaurus/utils-validation": "2.0.0-beta.14",
"@docusaurus/responsive-loader": "1.5.0",
"@endiliey/react-ideal-image": "^0.0.11",
"@docusaurus/theme-translations": "2.0.0-beta.14",
"@endiliey/react-ideal-image": "^0.0.11",
"react-waypoint": "^10.1.0",
"sharp": "^0.29.1",
"tslib": "^2.3.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
"@docusaurus/theme-translations": "2.0.0-beta.14",
"@docusaurus/utils": "2.0.0-beta.14",
"@docusaurus/utils-validation": "2.0.0-beta.14",
"@mdx-js/mdx": "^1.6.21",
"@mdx-js/react": "^1.6.21",
"clsx": "^1.1.1",
"copy-text-to-clipboard": "^3.0.1",
"globby": "^11.0.2",
"infima": "0.2.0-alpha.37",
"lodash": "^4.17.20",
"postcss": "^8.3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
transform: scale(0);
}

.backToTopButton:after {
.backToTopButton::after {
content: ' ';
display: inline-block;
mask: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem no-repeat;
Expand Down
Loading

0 comments on commit 302487d

Please sign in to comment.