mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 20:46:58 +02:00
chore: various internal fixes (#6761)
This commit is contained in:
parent
124511f445
commit
e101acd132
6 changed files with 14 additions and 105 deletions
4
jest/snapshotPathNormalizer.js
vendored
4
jest/snapshotPathNormalizer.js
vendored
|
@ -11,6 +11,7 @@
|
|||
|
||||
const _ = require('lodash');
|
||||
const {escapePath} = require('@docusaurus/utils');
|
||||
const {version} = require('@docusaurus/core/package.json');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
@ -131,6 +132,9 @@ function normalizePaths(value) {
|
|||
.split(`<TEMP_DIR>${path.sep + homeRealRelativeToTemp}`)
|
||||
.join('<HOME_DIR>'), // untested
|
||||
|
||||
// Replace the Docusaurus version with a stub
|
||||
(val) => val.split(version).join('<CURRENT_VERSION>'),
|
||||
|
||||
// In case the CWD is escaped
|
||||
(val) => val.split(escapePath(cwd)).join('<PROJECT_ROOT>'),
|
||||
|
||||
|
|
|
@ -158,8 +158,8 @@ Array [
|
|||
\\"docusaurus\\": \\"docusaurus\\"
|
||||
},
|
||||
\\"dependencies\\": {
|
||||
\\"@docusaurus/core\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/core\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"clsx\\": \\"^1.1.1\\",
|
||||
\\"react\\": \\"^17.0.2\\",
|
||||
\\"react-dom\\": \\"^17.0.2\\"
|
||||
|
@ -350,8 +350,8 @@ Array [
|
|||
\\"docusaurus\\": \\"docusaurus\\"
|
||||
},
|
||||
\\"dependencies\\": {
|
||||
\\"@docusaurus/core\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/core\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"clsx\\": \\"^1.1.1\\",
|
||||
\\"react\\": \\"^17.0.2\\",
|
||||
\\"react-dom\\": \\"^17.0.2\\"
|
||||
|
@ -539,8 +539,8 @@ Array [
|
|||
\\"docusaurus\\": \\"docusaurus\\"
|
||||
},
|
||||
\\"dependencies\\": {
|
||||
\\"@docusaurus/core\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\",
|
||||
\\"@docusaurus/core\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"@docusaurus/preset-classic\\": \\"<CURRENT_VERSION>\\",
|
||||
\\"clsx\\": \\"^1.1.1\\",
|
||||
\\"react\\": \\"^17.0.2\\",
|
||||
\\"react-dom\\": \\"^17.0.2\\"
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
"@docusaurus/utils": "2.0.0-beta.16",
|
||||
"@docusaurus/utils-common": "2.0.0-beta.16",
|
||||
"@popperjs/core": "^2.11.2",
|
||||
"axios": "^0.26.0",
|
||||
"clsx": "^1.1.1",
|
||||
"color": "^4.2.1",
|
||||
"esbuild-loader": "2.18.0",
|
||||
|
|
|
@ -10,7 +10,6 @@ const path = require('path');
|
|||
const fs = require('fs-extra');
|
||||
const pluginContentBlog = require('@docusaurus/plugin-content-blog');
|
||||
const {aliasedSitePath, docuHash, normalizeUrl} = require('@docusaurus/utils');
|
||||
const syncAvatars = require('./syncAvatars');
|
||||
|
||||
/**
|
||||
* Multiple versions may be published on the same day, causing the order to be
|
||||
|
@ -51,7 +50,7 @@ function processSection(section) {
|
|||
.map((author) => ({
|
||||
...author,
|
||||
name: author.name ?? author.alias,
|
||||
imageURL: `./img/${author.alias}.png`,
|
||||
imageURL: `https://github.com/${author.alias}.png`,
|
||||
}))
|
||||
.sort((a, b) => a.url.localeCompare(b.url));
|
||||
|
||||
|
@ -117,7 +116,8 @@ async function ChangelogPlugin(context, options) {
|
|||
),
|
||||
),
|
||||
);
|
||||
await syncAvatars(authorsMap, generateDir);
|
||||
const authorsPath = path.join(generateDir, 'authors.json');
|
||||
await fs.outputFile(authorsPath, JSON.stringify(authorsMap, null, 2));
|
||||
const content = await blogPlugin.loadContent();
|
||||
content.blogPosts.forEach((post, index) => {
|
||||
const pageIndex = Math.floor(index / options.postsPerPage);
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// @ts-check
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
// const axios = require('axios').default;
|
||||
|
||||
// TODO not sure how the syncing should be done at all... for now it always
|
||||
// pretends the limit is reached. We should only fetch a portion of the avatars
|
||||
// at a time. But seems avatars.githubusercontent.com API doesn't like HTTP
|
||||
// requests?
|
||||
/**
|
||||
* @param {string} username
|
||||
* @param {Record<string, number>} lastUpdateCache
|
||||
* @param {Record<string, {imageURL: string; url: string}>} authorsMap
|
||||
* @returns true if saved successfully (including not found); false if limit
|
||||
* reached
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async function fetchImage(username, lastUpdateCache, authorsMap) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to keep track of all committers that are in the changelog, and fetch
|
||||
* their avatars beforehand. This prevents sending too many requests to GitHub
|
||||
* every time one visits a page. Avatar refreshing is done incrementally across
|
||||
* each build.
|
||||
*
|
||||
* This method mutates the authorsMap. If the avatar fails to be fetched, the
|
||||
* imageURL is re-written with the github remote URL. The authors map is then
|
||||
* written to FS.
|
||||
*
|
||||
* @param {Record<string, {name: string, url: string, alias: string, imageURL: string}>} authorsMap
|
||||
* @param {string} generateDir
|
||||
*/
|
||||
async function syncAvatars(authorsMap, generateDir) {
|
||||
const imagePath = path.join(generateDir, 'img');
|
||||
const lastUpdateCachePath = path.join(imagePath, 'lastUpdate.json');
|
||||
const authorsPath = path.join(generateDir, 'authors.json');
|
||||
if (!(await fs.pathExists(lastUpdateCachePath))) {
|
||||
await fs.outputFile(lastUpdateCachePath, '{}');
|
||||
}
|
||||
/**
|
||||
* Records the last time an avatar was successfully updated.
|
||||
* If an entry doesn't exist, the file won't exist either.
|
||||
* @type {Record<string, number>}
|
||||
*/
|
||||
const lastUpdateCache = await fs.readJSON(lastUpdateCachePath);
|
||||
let limitReached = false;
|
||||
for (const username of Object.keys(authorsMap)) {
|
||||
if (!limitReached && !lastUpdateCache[username]) {
|
||||
if (!(await fetchImage(username, lastUpdateCache, authorsMap))) {
|
||||
limitReached = true;
|
||||
}
|
||||
}
|
||||
if (limitReached) {
|
||||
authorsMap[username].imageURL = `https://github.com/${username}.png`;
|
||||
}
|
||||
}
|
||||
const usersByLastUpdate = Object.entries(lastUpdateCache)
|
||||
.sort((a, b) => a[1] - b[1])
|
||||
.map((a) => a[0]);
|
||||
for (const username of usersByLastUpdate) {
|
||||
if (
|
||||
!limitReached &&
|
||||
lastUpdateCache[username] < Date.now() - 24 * 3600 * 1000
|
||||
) {
|
||||
if (!(await fetchImage(username, lastUpdateCache, authorsMap))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
await fs.outputFile(
|
||||
lastUpdateCachePath,
|
||||
JSON.stringify(lastUpdateCache, null, 2),
|
||||
);
|
||||
await fs.outputFile(authorsPath, JSON.stringify(authorsMap, null, 2));
|
||||
}
|
||||
|
||||
module.exports = syncAvatars;
|
|
@ -5326,13 +5326,6 @@ axios@^0.25.0:
|
|||
dependencies:
|
||||
follow-redirects "^1.14.7"
|
||||
|
||||
axios@^0.26.0:
|
||||
version "0.26.0"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928"
|
||||
integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==
|
||||
dependencies:
|
||||
follow-redirects "^1.14.8"
|
||||
|
||||
axobject-query@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
|
||||
|
@ -9351,7 +9344,7 @@ folder-walker@^3.2.0:
|
|||
dependencies:
|
||||
from2 "^2.1.0"
|
||||
|
||||
follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7, follow-redirects@^1.14.8:
|
||||
follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7:
|
||||
version "1.14.9"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
|
||||
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue