mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
get team contact information as an option
This commit is contained in:
@@ -19,5 +19,6 @@ coverage
|
||||
.cache-loader
|
||||
|
||||
packages/logos-*/lib/*
|
||||
packages/logos-docusaurus-preset/static/common/data/team.json
|
||||
|
||||
lerna-debug.log
|
||||
|
||||
@@ -11,8 +11,23 @@ export enum BusinessUnits {
|
||||
Waku = 'Waku',
|
||||
}
|
||||
|
||||
export type Contact = {
|
||||
name: string
|
||||
image: string
|
||||
contact?: {
|
||||
email: string | null
|
||||
status: string | null
|
||||
github: string | null
|
||||
discord: string | null
|
||||
gscholar: string | null
|
||||
}
|
||||
}
|
||||
|
||||
export type ContactInfo = Contact[]
|
||||
|
||||
export type PresetConfig = {
|
||||
businessUnit: BusinessUnits
|
||||
contactInfo?: string
|
||||
theme?: {
|
||||
name: ThemeNames.Default
|
||||
options?: DefaultThemeOptions
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { LoadContext } from '@docusaurus/types'
|
||||
import { Joi } from '@docusaurus/utils-validation'
|
||||
import * as fs from 'fs-extra'
|
||||
import * as path from 'path'
|
||||
import { BusinessUnits, PluginOptions, Status } from '../types'
|
||||
@@ -7,10 +8,7 @@ const COMMON_DATA_DIR = path.join(__dirname, '../../static/common/data')
|
||||
|
||||
export const createCommonDataDir = () => void fs.ensureDirSync(COMMON_DATA_DIR)
|
||||
|
||||
export const createTeamFile = (
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
) => {
|
||||
export const findTeamByBusinessUnit = (bu: BusinessUnits) => {
|
||||
const contacts: Status.Contacts.Data = require(path.join(
|
||||
COMMON_DATA_DIR,
|
||||
'../contacts.json',
|
||||
@@ -23,14 +21,62 @@ export const createTeamFile = (
|
||||
Status.Department.WakuProduct,
|
||||
Status.Department.WakuResearch,
|
||||
],
|
||||
}[options.businessUnit] ?? []
|
||||
}[bu] ?? []
|
||||
).map((dep) => dep.toLowerCase())
|
||||
|
||||
const team = Object.values(contacts).filter(
|
||||
return Object.values(contacts).filter(
|
||||
(contact) =>
|
||||
!!contact.department &&
|
||||
departments.includes(contact.department.toLowerCase()),
|
||||
)
|
||||
}
|
||||
|
||||
export const getTeamFromCustomFile = (filename: string) => {
|
||||
const contact = JSON.parse(fs.readFileSync(filename).toString())
|
||||
|
||||
const schema = Joi.array().items(
|
||||
Joi.object({
|
||||
name: Joi.string().min(1).required(),
|
||||
image: Joi.string().example('team/Name.jpg').required(),
|
||||
contact: Joi.object({
|
||||
email: Joi.string().allow(null).optional(),
|
||||
status: Joi.string().allow(null).optional(),
|
||||
github: Joi.string().allow(null).optional(),
|
||||
discord: Joi.string().allow(null).optional(),
|
||||
gscholar: Joi.string().allow(null).optional(),
|
||||
})
|
||||
.optional()
|
||||
.default({}),
|
||||
}),
|
||||
)
|
||||
|
||||
const result = schema.validate(contact, { abortEarly: false })
|
||||
if (result.error) throw result.error
|
||||
|
||||
return contact.map(
|
||||
({ name, image, contact }) =>
|
||||
({
|
||||
'pref-name': name,
|
||||
department: null,
|
||||
'photo-path': image,
|
||||
contact,
|
||||
} as Status.Contacts.Contact),
|
||||
)
|
||||
}
|
||||
|
||||
export const createTeamFile = (
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
) => {
|
||||
const filename = options?.contactInfo
|
||||
? path.isAbsolute(options.contactInfo)
|
||||
? options.contactInfo
|
||||
: path.join(context.siteDir, options.contactInfo)
|
||||
: path.join(COMMON_DATA_DIR, '../contacts.json')
|
||||
|
||||
const team = options.contactInfo
|
||||
? getTeamFromCustomFile(filename)
|
||||
: findTeamByBusinessUnit(options.businessUnit)
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(COMMON_DATA_DIR, 'team.json'),
|
||||
|
||||
@@ -5,7 +5,7 @@ const schema = Joi.object<PluginOptions>({
|
||||
businessUnit: Joi.string()
|
||||
.valid(...Object.values(BusinessUnits))
|
||||
.default(BusinessUnits.Logos),
|
||||
|
||||
contactInfo: Joi.string().optional(),
|
||||
theme: Joi.object()
|
||||
.schema({
|
||||
name: Joi.string()
|
||||
|
||||
Reference in New Issue
Block a user