#424 一時コミット
このコミットが含まれているのは:
@@ -0,0 +1,75 @@
|
||||
import { parse } from 'yaml'
|
||||
|
||||
import type { ComponentType } from 'react'
|
||||
|
||||
type ArticleLanguage = {
|
||||
title: string
|
||||
currentEdition: string }
|
||||
|
||||
type ArticleMeta = {
|
||||
identifier: string
|
||||
canonicalLanguage: string
|
||||
languages: Record<string, ArticleLanguage> }
|
||||
|
||||
type MdxModule = { default: ComponentType }
|
||||
|
||||
|
||||
const articleFiles = import.meta.glob<string> (
|
||||
'../../help/*/article.yml',
|
||||
{ query: '?raw', import: 'default', eager: true, })
|
||||
|
||||
const editionFiles = import.meta.glob<MdxModule> ('../../help/*/editions/*/*.mdx')
|
||||
|
||||
|
||||
const cameliseArticle = (value: {
|
||||
identifier: string
|
||||
canonical_language: string
|
||||
languages: Record<string, {
|
||||
title: string
|
||||
current_edition: string }> }): ArticleMeta => (
|
||||
{ identifier: value.identifier,
|
||||
canonicalLanguage: value.canonical_language,
|
||||
languages: Object.fromEntries (
|
||||
Object.entries (value.languages).map (([language, data]) => [
|
||||
language,
|
||||
{ title: data.title,
|
||||
currentEdition: data.current_edition, }])) })
|
||||
|
||||
|
||||
export const getHelpArticle = (identifier: string): ArticleMeta | undefined => {
|
||||
const path = `../../help/${identifier}/article.yml`
|
||||
const source = articleFiles[path]
|
||||
|
||||
if (!(source))
|
||||
return undefined
|
||||
|
||||
return cameliseArticle (parse (source))
|
||||
}
|
||||
|
||||
|
||||
export const getHelpEditions = (
|
||||
identifier: string,
|
||||
language: string,
|
||||
): string[] => {
|
||||
const prefix = `../../help/${identifier}/editions/${language}/`
|
||||
|
||||
return (Object.keys (editionFiles)
|
||||
.filter (path => path.startsWith (prefix))
|
||||
.map (path => path.slice (prefix.length, -'.mdx'.length))
|
||||
.sort ())
|
||||
}
|
||||
|
||||
|
||||
export const getHelpEdition = async (
|
||||
identifier: string,
|
||||
language: string,
|
||||
edition: string,
|
||||
): Promise<ComponentType | undefined> => {
|
||||
const path = `../../help/${identifier}/editions/${language}/${edition}.mdx`
|
||||
const loader = editionFiles[path]
|
||||
|
||||
if (!(loader))
|
||||
return undefined
|
||||
|
||||
return (await loader ()).default
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする