1
0
Fork 0
freesewing/sites/shared/components/mdx/meta.mjs

104 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-09-04 08:40:05 +02:00
import { useState, useEffect } from 'react'
2023-07-13 21:15:25 +02:00
import { siteConfig } from 'site/site.config.mjs'
2023-09-04 08:40:05 +02:00
import { horFlexClasses } from 'shared/utils.mjs'
2023-07-13 21:15:25 +02:00
// List of authors
import { authors as allAuthors } from 'config/authors.mjs'
import { docUpdates } from 'site/prebuild/doc-updates.mjs'
// Hooks
import { useTranslation } from 'next-i18next'
2023-07-14 07:58:12 +02:00
import { EditIcon } from 'shared/components/icons.mjs'
2023-09-04 08:40:05 +02:00
import { useAccount } from 'shared/hooks/use-account.mjs'
// Components
import { PageLink } from 'shared/components/link.mjs'
import { TimeAgo, ns as timeagoNs } from 'shared/components/timeago/index.mjs'
2023-09-04 08:40:05 +02:00
import { BookmarkButton } from 'shared/components/bookmarks.mjs'
export const ns = ['account', timeagoNs]
2023-07-13 21:15:25 +02:00
2023-07-17 11:40:45 -05:00
const PersonList = ({ list }) =>
list ? (
<ul>
{list.map((id) => (
<li key={id}>
{allAuthors[id] ? (
<PageLink href={`/users/${allAuthors[id].id}`} txt={allAuthors[id].name} />
) : (
<span className="font-medium">{id}</span>
)}
</li>
))}
</ul>
) : null
2023-07-13 21:15:25 +02:00
const CreditsList = ({ updates, frontmatter, locale, t }) => (
<ul className="list list-inside list-disc">
2023-07-17 11:40:45 -05:00
{updates.a?.length > 0 ? (
2023-07-13 21:15:25 +02:00
<li className="list-none">
<b>{t('authors')}:</b>
<PersonList list={updates.a} />
</li>
) : null}
{frontmatter.maintainers && frontmatter.maintainers.length > 0 ? (
<li className="list-none mt-2">
<b>{t('maintainers')}:</b>
<PersonList list={updates.a} />
</li>
) : null}
{locale !== 'en' && (
<li className="list-none mt-2">
<b className="pr-2">{t('translators')}:</b>
<a href={`https://next.freesewing.org/translation`} className="font-medium">
{t('learnMore')}
</a>
</li>
)}
<li className="list-none mt-2">
2023-08-16 15:54:32 +02:00
<b className="pr-2">{t('lastUpdated')}:</b> <TimeAgo date={updates.u} />
2023-07-13 21:15:25 +02:00
</li>
</ul>
)
export const MdxMetaData = ({ frontmatter, locale, slug }) => {
2023-09-04 08:40:05 +02:00
const { control } = useAccount()
const { t, i18n } = useTranslation('docs')
const [localControl, setLocalControl] = useState(1)
// Prevent hydration issues
useEffect(() => {
setLocalControl(control)
}, [])
2023-07-13 21:15:25 +02:00
const updates = docUpdates[slug] || {}
frontmatter.maintainers = ['joostdecock']
2023-09-04 08:40:05 +02:00
locale = i18n.language
2023-07-13 21:15:25 +02:00
return (
<div className="hidden xl:block mb-4">
2023-09-04 08:40:05 +02:00
{localControl > 2 && (
<div className="flex flex-col gap-2 max-w-xs">
<a
href={`https://github.dev/freesewing/freesewing/blob/develop/markdown/${siteConfig.tld}/${slug}/en.md`}
className={`btn btn-secondary btn-outline ${horFlexClasses}`}
>
<EditIcon />
<span>{t('editThisPage')}</span>
</a>
<BookmarkButton slug={slug} title={frontmatter.title} type="doc" />
</div>
)}
2023-07-13 21:15:25 +02:00
<div
className={`
mdx mdx-toc text-base-content text-base
sticky top-16 max-h-screen overflow-y-auto
border-2 bg-base-200 bg-opacity-30 p-4 rounded-lg border-base-200
`}
>
<h4>{t('contentsBy')}</h4>
<CreditsList {...{ updates, frontmatter, t, locale }} />
</div>
</div>
)
}