Skip to content

Commit

Permalink
feat: init jobs & challenges plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangovil committed Nov 7, 2023
1 parent 6c03faa commit e985be6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
23 changes: 2 additions & 21 deletions packages/docusaurus-playground/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down
7 changes: 3 additions & 4 deletions packages/logos-docusaurus-preset/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
? {
Expand Down Expand Up @@ -124,6 +121,8 @@ export default function logosPreset(
}
}

if (options.generated) plugins.push([generatedDataPlugin, {}])

return {
plugins,
themes,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
})
},
}
}
2 changes: 2 additions & 0 deletions packages/logos-docusaurus-preset/src/types/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -55,4 +56,5 @@ export type PresetConfig = {
pages?: Partial<PagesPluginOptions> | false
localSearch?: LocalSearchConfig
og?: Partial<Omit<OpenGraphPluginOptions, 'imageRenderers'>> | false
generated?: GeneratedDataPluginConfig
}
11 changes: 11 additions & 0 deletions packages/logos-docusaurus-preset/src/validateOptions.ts
Original file line number Diff line number Diff line change
@@ -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<PluginOptions>({
Expand All @@ -17,6 +18,16 @@ const schema = Joi.object<PluginOptions>({
.default({}),
customSiteConfig: Joi.boolean().optional().default(false),
og: Joi.object<PluginOptions['og']>().optional().default(false),
generated: Joi.object<GeneratedDataPluginConfig>({
challenges: Joi.object<GeneratedDataPluginConfig['challenges']>({
githubAccessToken: Joi.string().required(),
owner: Joi.string().required(),
repo: Joi.string().required(),
}).optional(),
jobList: Joi.object<GeneratedDataPluginConfig['jobList']>({
url: Joi.string().uri().required(),
}).optional(),
}).optional(),
})

export const validateOptions = ({
Expand Down

0 comments on commit e985be6

Please sign in to comment.