-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { LoadContext, Plugin, PluginOptions } from '@docusaurus/types'; | ||
import logger from '@docusaurus/logger'; | ||
import Module from 'module'; | ||
|
||
const createProvidersJsonPlugin = (context: LoadContext, options: PluginOptions): Plugin => { | ||
return { | ||
name: 'docusaurus-plugin-create-providers-json', | ||
|
||
async postBuild({ outDir, routes, plugins }) { | ||
const originalResolveFilename = Module._resolveFilename | ||
|
||
// This is a hack to allow us to import a custom module instead of the normal translation module | ||
Module._resolveFilename = function (request, parent, isMain, options) { | ||
if (request == '@docusaurus/Translate') { | ||
request = path.resolve(__dirname, 'custom_modules', 'translate.ts'); | ||
} | ||
return originalResolveFilename.call(this, request, parent, isMain, options); | ||
}; | ||
|
||
// Import the providers data | ||
const { providersData } = await import('../data/providers'); | ||
|
||
// Restore the original resolve function | ||
Module._resolveFilename = originalResolveFilename | ||
|
||
const providersFilePath = path.join(outDir, 'data/providers.json'); | ||
|
||
fs.mkdirSync(path.dirname(providersFilePath), { recursive: true }); | ||
|
||
fs.writeFileSync(providersFilePath, JSON.stringify(providersData, null, 2), 'utf-8'); | ||
|
||
logger.success(`Created providers.json file at ${providersFilePath}`); | ||
} | ||
}; | ||
}; | ||
|
||
export default createProvidersJsonPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This is a fake module that simulates @docusaurus/Translate | ||
export function translate (data) { | ||
return data.message | ||
} |