diff --git a/packages/docusaurus-playground/docusaurus.config.js b/packages/docusaurus-playground/docusaurus.config.js index d92de82a..ec516ca3 100644 --- a/packages/docusaurus-playground/docusaurus.config.js +++ b/packages/docusaurus-playground/docusaurus.config.js @@ -42,33 +42,14 @@ const config = { }, }, docs: { - routeBasePath: '/about', - versions: { - current: { - label: 'current', - }, - }, - lastVersion: 'current', + routeBasePath: '/', + path: 'docs', }, }), ], ], plugins: [ - [ - '@docusaurus/plugin-content-blog', - /** @type {import('@docusaurus/plugin-content-blog').PluginOptions} */ - ({ - id: 'blog', - routeBasePath: '/rlog', - path: 'rlog', - blogTitle: 'Rlog - Vac Research Log', - blogDescription: - 'Vac builds public good protocols for the decentralized web.', - blogSidebarCount: 0, - authorsMapPath: 'authors.yml', - }), - ], [ '@acid-info/docusaurus-fathom', { diff --git a/packages/logos-docusaurus-preset/src/index.ts b/packages/logos-docusaurus-preset/src/index.ts index 0f5eccab..6fc1eb46 100644 --- a/packages/logos-docusaurus-preset/src/index.ts +++ b/packages/logos-docusaurus-preset/src/index.ts @@ -2,10 +2,10 @@ import { PluginOptions as SearchPluginOptions } from '@acid-info/logos-docusauru import classicPreset from '@docusaurus/preset-classic' import type { LoadContext, PluginConfig, Preset } from '@docusaurus/types' import * as path from 'path' +import { generatedDataPlugin } from './plugins/generatedData.plugin' import { siteConfigs } from './site-config/index' import { themeConfigs } from './theme-config/index' import { PluginOptions, ThemeNames } from './types' -import { createCommonDataDir, createTeamFile } from './utils/data.utils' import { findDocInstances, validateDocPluginOptions } from './utils/docs.utils' import { defaultsDeep } from './utils/object.utils' @@ -68,9 +68,6 @@ export default function logosPreset( ([key, value]) => (context.siteConfig[key] = value), ) - createCommonDataDir() - createTeamFile(context, options) - const { plugins = [], themes = [] } = classicPreset(context, { docs: docsEnabled ? { @@ -124,6 +121,8 @@ export default function logosPreset( } } + if (options.generated) plugins.push([generatedDataPlugin, {}]) + return { plugins, themes, diff --git a/packages/logos-docusaurus-preset/src/plugins/generatedData.plugin.ts b/packages/logos-docusaurus-preset/src/plugins/generatedData.plugin.ts new file mode 100644 index 00000000..0390fad0 --- /dev/null +++ b/packages/logos-docusaurus-preset/src/plugins/generatedData.plugin.ts @@ -0,0 +1,67 @@ +import { PluginModule } from '@docusaurus/types' +import * as fsp from 'fs/promises' +import * as fs from 'fs' +import path from 'path' + +type JobListConfig = { + url: string +} + +type ChallengeConfig = { + repo: string + owner: string + githubAccessToken: string +} + +export type GeneratedDataPluginConfig = { + jobList?: JobListConfig + challenges?: ChallengeConfig +} + +const fetchJobList = async ({ url, out }: { out: string } & JobListConfig) => { + const list = [] + + await fsp.writeFile(out, JSON.stringify(list)) +} + +const fetchChallenges = async ({ + owner, + repo, + out, + githubAccessToken, +}: { + out: string +} & ChallengeConfig) => { + const list = [] + + await fsp.writeFile(out, JSON.stringify(list)) +} + +export const generatedDataPlugin: PluginModule = (context, options) => { + const { challenges, jobList } = options as GeneratedDataPluginConfig + + const outDir = path.join(context.siteDir, './static/generated') + + if (fs.existsSync(outDir)) fs.rmSync(outDir, { recursive: true, force: true }) + + fs.mkdirSync(outDir, { recursive: true }) + + return { + name: 'logos-data-plugin', + loadContent: async () => { + if (jobList) + await fetchJobList({ + url: jobList.url, + out: path.join(outDir, 'jobs.json'), + }) + + if (challenges) + await fetchChallenges({ + repo: challenges.repo, + owner: challenges.owner, + githubAccessToken: challenges.githubAccessToken, + out: path.join(outDir, 'challenges.json'), + }) + }, + } +} diff --git a/packages/logos-docusaurus-preset/src/types/preset.ts b/packages/logos-docusaurus-preset/src/types/preset.ts index b324cf2e..b2fc1f74 100644 --- a/packages/logos-docusaurus-preset/src/types/preset.ts +++ b/packages/logos-docusaurus-preset/src/types/preset.ts @@ -2,6 +2,7 @@ import { PluginOptions as OpenGraphPluginOptions } from '@acid-info/docusaurus-o import { PluginOptions as BlogPluginOptions } from '@docusaurus/plugin-content-blog' import { PluginOptions as DocPluginOptions } from '@docusaurus/plugin-content-docs' import { PluginOptions as PagesPluginOptions } from '@docusaurus/plugin-content-pages' +import { GeneratedDataPluginConfig } from '../plugins/generatedData.plugin' import { DefaultThemeOptions } from './themes' export enum ThemeNames { @@ -55,4 +56,5 @@ export type PresetConfig = { pages?: Partial | false localSearch?: LocalSearchConfig og?: Partial> | false + generated?: GeneratedDataPluginConfig } diff --git a/packages/logos-docusaurus-preset/src/validateOptions.ts b/packages/logos-docusaurus-preset/src/validateOptions.ts index 5a8b78de..0916f091 100644 --- a/packages/logos-docusaurus-preset/src/validateOptions.ts +++ b/packages/logos-docusaurus-preset/src/validateOptions.ts @@ -1,4 +1,5 @@ import { Joi } from '@docusaurus/utils-validation' +import { GeneratedDataPluginConfig } from './plugins/generatedData.plugin' import { BusinessUnits, PluginOptions, ThemeNames } from './types' const schema = Joi.object({ @@ -17,6 +18,16 @@ const schema = Joi.object({ .default({}), customSiteConfig: Joi.boolean().optional().default(false), og: Joi.object().optional().default(false), + generated: Joi.object({ + challenges: Joi.object({ + githubAccessToken: Joi.string().required(), + owner: Joi.string().required(), + repo: Joi.string().required(), + }).optional(), + jobList: Joi.object({ + url: Joi.string().uri().required(), + }).optional(), + }).optional(), }) export const validateOptions = ({