Skip to content

Commit

Permalink
Releasing v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RDIL committed Nov 20, 2023
1 parent c5789fb commit b3d8786
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 72 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Breaking changes:

- Dropped support for Docusaurus `<2.0.0`.
- Dropped support for Node.js `<16.14` (what Docusaurus requires now).
- Update axios to `^1.6.0`.

New features:

- Add explicit support for Docusaurus v3.

## v3.1.0 - 4/12/2022

Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
"tabWidth": 4
},
"devDependencies": {
"@docusaurus/types": "^3.0.0",
"@docusaurus/types": "3.0.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/react-helmet": "^6.1.9",
"commander": "^11.1.0",
"prettier": "^2.7.1",
"typescript": "^5.2.2"
"prettier": "^3.1.0",
"typescript": "^5.3.2"
},
"peerDependencies": {
"@docusaurus/core": "2.x || 3.x"
Expand Down Expand Up @@ -54,7 +52,7 @@
"content"
],
"engines": {
"node": ">=16.14"
"node": ">=18"
},
"workspaces": [
"testsite"
Expand Down
56 changes: 30 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import type { LoadContext, Plugin } from "@docusaurus/types"
import axios from "axios"
import axios, { AxiosRequestConfig } from "axios"
import { existsSync, writeFileSync, mkdirSync } from "fs"
import { join } from "path"
import { sync as delFile } from "rimraf"
import { timeIt } from "./utils"
import { Fetchable, RemoteContentPluginOptions } from "./types"
import { Fetchable, ModifyContentFunction, RemoteContentPluginOptions } from "./types"

async function runModifications(sourceBaseUrl: string, id: string, requestConfig: AxiosRequestConfig, modifyContent: ModifyContentFunction | undefined) {
let content = (
await axios({
baseURL: sourceBaseUrl,
url: id,
...requestConfig
})
).data
let newIdent = id

const called = modifyContent?.(newIdent, content)

let cont = called?.content
if (cont && typeof cont === "string") {
content = cont
}

let fn
if ((fn = called?.filename) && typeof fn === "string") {
newIdent = fn
}

return { content, newIdent }
}

// noinspection JSUnusedGlobalSymbols
export default async function pluginRemoteContent(
Expand All @@ -19,7 +44,7 @@ export default async function pluginRemoteContent(
noRuntimeDownloads = false,
performCleanup = true,
requestConfig = {},
modifyContent = () => undefined,
modifyContent = () => undefined
} = options

if (!name) {
Expand Down Expand Up @@ -75,28 +100,7 @@ export default async function pluginRemoteContent(
const c = await findRemoteItems()

for (const { id } of c) {
//#region Run modifyContent (and fetch the data)
let content = (
await axios({
baseURL: sourceBaseUrl,
url: id,
...requestConfig,
})
).data
let newIdent = id

const called = modifyContent?.(newIdent, content)

let cont = called?.content
if (cont && typeof cont === "string") {
content = cont
}

let fn
if ((fn = called?.filename) && typeof fn === "string") {
newIdent = fn
}
//#endregion
let { content, newIdent } = await runModifications(sourceBaseUrl, id, requestConfig, modifyContent)

const checkIdent = newIdent.split("/").filter((seg) => seg !== "")
checkIdent.pop()
Expand Down Expand Up @@ -145,7 +149,7 @@ export default async function pluginRemoteContent(
`Removes the local copy of the remote ${name} data.`
)
.action(async () => await timeIt(`clear ${name}`, cleanContent))
},
}
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { AxiosRequestConfig } from "axios"

/**
* An optional function that modifies the file name and content of a downloaded file.
*
* @param filename The file's name.
* @param content The file's content.
* @returns undefined to leave the content/name as is, or an object containing the filename and the content.
*/
export type ModifyContentFunction = (
filename: string,
content: string
) => { filename?: string; content?: string } | undefined

/**
* The plugin's options.
*/
Expand Down Expand Up @@ -49,10 +61,7 @@ export interface RemoteContentPluginOptions {
* @param content The file's content.
* @returns undefined to leave the content/name as is, or an object containing the filename and the content.
*/
modifyContent?(
filename: string,
content: string
): { filename?: string; content?: string } | undefined
modifyContent?: ModifyContentFunction
}

// noinspection SpellCheckingInspection
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"incremental": true,
"target": "ES2020",
"target": "ES2021",
"module": "commonjs",
"lib": ["ESNext"],
"jsx": "react",
"skipLibCheck": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand Down
52 changes: 17 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ __metadata:
languageName: node
linkType: hard

"@docusaurus/types@npm:3.0.0, @docusaurus/types@npm:^3.0.0":
"@docusaurus/types@npm:3.0.0":
version: 3.0.0
resolution: "@docusaurus/types@npm:3.0.0"
dependencies:
Expand Down Expand Up @@ -3020,15 +3020,6 @@ __metadata:
languageName: node
linkType: hard

"@types/react-helmet@npm:^6.1.9":
version: 6.1.9
resolution: "@types/react-helmet@npm:6.1.9"
dependencies:
"@types/react": "npm:*"
checksum: 4f96b338b6500042a1dde6e7af0e109df91f5ec52a1200dd9511748f85cd659b22e84b51677f86fb1c319dd9e0da56c6947b7130cb1f8989a8ff8e5c2cc26007
languageName: node
linkType: hard

"@types/react-router-config@npm:*, @types/react-router-config@npm:^5.0.7":
version: 5.0.10
resolution: "@types/react-router-config@npm:5.0.10"
Expand Down Expand Up @@ -4334,13 +4325,6 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^11.1.0":
version: 11.1.0
resolution: "commander@npm:11.1.0"
checksum: 66bd2d8a0547f6cb1d34022efb25f348e433b0e04ad76a65279b1b09da108f59a4d3001ca539c60a7a46ea38bcf399fc17d91adad76a8cf43845d8dcbaf5cda1
languageName: node
linkType: hard

"commander@npm:^2.20.0":
version: 2.20.3
resolution: "commander@npm:2.20.3"
Expand Down Expand Up @@ -5049,17 +5033,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "docusaurus-plugin-remote-content@workspace:."
dependencies:
"@docusaurus/types": "npm:^3.0.0"
"@docusaurus/types": "npm:3.0.0"
"@types/react": "npm:^18.2.37"
"@types/react-dom": "npm:^18.2.15"
"@types/react-helmet": "npm:^6.1.9"
axios: "npm:^1.6.0"
commander: "npm:^11.1.0"
picocolors: "npm:^1.0.0"
prettier: "npm:^2.7.1"
prettier: "npm:^3.1.0"
pretty-ms: "npm:^7.0.1"
rimraf: "npm:^5.0.5"
typescript: "npm:^5.2.2"
typescript: "npm:^5.3.2"
peerDependencies:
"@docusaurus/core": 2.x || 3.x
languageName: unknown
Expand Down Expand Up @@ -9597,12 +9579,12 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^2.7.1":
version: 2.7.1
resolution: "prettier@npm:2.7.1"
"prettier@npm:^3.1.0":
version: 3.1.0
resolution: "prettier@npm:3.1.0"
bin:
prettier: bin-prettier.js
checksum: 9d29f81c1a470efca6851cd926a3e132a8d9c9d290c3d084c917c1c5aad5c392551406cf6012c724a136bd15911ede5eadc255d121c2761813b33a541a9c34c6
prettier: bin/prettier.cjs
checksum: e95e8f93c6b9aea2ac1e86bebe329bee90c8c50d9a23d1f593eba8d7f39b33b3641eb28785001505b6723c47895a5322ad12a2fb855b289cb7bae450ffc34425
languageName: node
linkType: hard

Expand Down Expand Up @@ -11355,23 +11337,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.2.2":
version: 5.2.2
resolution: "typescript@npm:5.2.2"
"typescript@npm:^5.3.2":
version: 5.3.2
resolution: "typescript@npm:5.3.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: d65e50eb849bd21ff8677e5b9447f9c6e74777e346afd67754934264dcbf4bd59e7d2473f6062d9a015d66bd573311166357e3eb07fea0b52859cf9bb2b58555
checksum: 415e5fb6611f5713e460bad48039f00bcfdbde53a2f911727862d5aa9c5d5edd250059a419df382d8f031709e15a169c41eb62b6a401da5eec7ac0f4e359d6ac
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.2.2#optional!builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>::version=5.2.2&hash=f3b441"
"typescript@patch:typescript@npm%3A^5.3.2#optional!builtin<compat/typescript>":
version: 5.3.2
resolution: "typescript@patch:typescript@npm%3A5.3.2#optional!builtin<compat/typescript>::version=5.3.2&hash=e012d7"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: f79cc2ba802c94c2b78dbb00d767a10adb67368ae764709737dc277273ec148aa4558033a03ce901406b35fddf4eac46dabc94a1e1d12d2587e2b9cfe5707b4a
checksum: 1b45cdfb577a78ae7a9a9d0b77a7b772142cb98ba05e4e5aefba7044a028ded885bcecef63166407a5986645cea816fe4986894336aacd5e791796ea79a6a7ed
languageName: node
linkType: hard

Expand Down

0 comments on commit b3d8786

Please sign in to comment.