2023-05-15 15:57:46 +02:00
|
|
|
|
// Components that are available in MDX content
|
|
|
|
|
import { components as baseComponents } from 'shared/components/mdx/index.mjs'
|
2023-05-15 20:00:45 +02:00
|
|
|
|
// List of authors
|
|
|
|
|
import { authors as allAuthors } from 'config/authors.mjs'
|
2023-05-17 10:53:41 +02:00
|
|
|
|
import { docUpdates } from 'site/prebuild/doc-updates.mjs'
|
2023-05-15 20:00:45 +02:00
|
|
|
|
// Components
|
|
|
|
|
import { PageLink } from 'shared/components/page-link.mjs'
|
|
|
|
|
import { DateTime, Interval } from 'luxon'
|
|
|
|
|
// Context
|
|
|
|
|
import { useContext } from 'react'
|
|
|
|
|
import { NavigationContext } from 'shared/context/navigation-context.mjs'
|
|
|
|
|
// Hooks
|
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-12-18 15:41:37 +01:00
|
|
|
|
|
2021-12-25 13:43:41 +01:00
|
|
|
|
// Previous-Next navigation
|
2023-05-15 15:57:46 +02:00
|
|
|
|
//import { PrevNext } from '../mdx/prev-next.mjs'
|
2023-05-15 20:00:45 +02:00
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
const TimeAgo = ({ date, t }) => {
|
|
|
|
|
const i = Interval.fromDateTimes(DateTime.fromISO(date), DateTime.now())
|
|
|
|
|
.toDuration(['hours', 'days', 'months', 'years'])
|
|
|
|
|
.toObject()
|
|
|
|
|
let ago = ''
|
2023-05-16 10:34:13 +02:00
|
|
|
|
if (i.years < 1 && i.months < 1) {
|
|
|
|
|
if (Math.floor(i.days) === 1) ago += `${t('oneDay')}`
|
|
|
|
|
else if (Math.floor(i.days) === 0) ago += `${t('lessThanADay')}`
|
|
|
|
|
} else {
|
|
|
|
|
if (i.years === 1) ago += `${i.years} ${t('year')}, `
|
|
|
|
|
else if (i.years > 1) ago += `${i.years} ${t('years')}, `
|
|
|
|
|
if (i.months === 1) ago += `${i.months} ${t('month')}`
|
|
|
|
|
else if (i.months > 1) ago += `${i.months} ${t('months')}`
|
|
|
|
|
}
|
2023-05-15 20:00:45 +02:00
|
|
|
|
|
|
|
|
|
return `${ago} ${t('ago')}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PersonList = ({ list }) =>
|
|
|
|
|
list.map((id, i) => (
|
|
|
|
|
<li key={id} className="list-none">
|
|
|
|
|
{allAuthors[id] ? (
|
|
|
|
|
<PageLink href={`/users/${allAuthors[id].id}`} txt={allAuthors[id].name} />
|
|
|
|
|
) : (
|
|
|
|
|
<span className="font-medium">{id}</span>
|
|
|
|
|
)}
|
|
|
|
|
{i !== list.length - 1 ? ',' : <span className="pl-2 pr-1 font-bold">|</span>}
|
|
|
|
|
</li>
|
|
|
|
|
))
|
|
|
|
|
const Ul = ({ children }) => (
|
|
|
|
|
<ul key="authors" className="flex flex-row flex-wrap gap-1 -ml-3">
|
|
|
|
|
{children}
|
|
|
|
|
</ul>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const MetaData = ({ authors = [], maintainers = [], updated = '20220825', locale, slug, t }) => (
|
2023-05-17 10:56:42 +02:00
|
|
|
|
<div className="py-4 px-4 rounded-lg bg-secondary bg-opacity-10 shadow mb-4">
|
2023-05-15 20:00:45 +02:00
|
|
|
|
{locale === 'en' ? (
|
|
|
|
|
<div className="flex flex-row items-center gap-4 justify-between text-base-content mb-2">
|
|
|
|
|
<span className="font-medium text-lg">{t('helpImproveDocs')}</span>
|
|
|
|
|
<a
|
|
|
|
|
href={`https://github.dev/freesewing/freesewing/blob/develop/markdown/org/${slug}/en.md`}
|
|
|
|
|
className="btn btn-secondary btn-sm flex flex-row gap-2 items-center"
|
|
|
|
|
>
|
|
|
|
|
<span role="img">✏️</span>
|
|
|
|
|
<span className="text-secondary-content">{t('editThisPage')}</span>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-row items-center gap-4 justify-between text-base-content mb-2">
|
|
|
|
|
<span className="font-medium text-lg">{t('helpTranslateDocs')}</span>
|
|
|
|
|
<a
|
|
|
|
|
href={`https://freesewing.dev/guides/translation`}
|
|
|
|
|
className="btn btn-secondary btn-sm flex flex-row gap-2 items-center"
|
|
|
|
|
>
|
|
|
|
|
<span role="img">💡</span>
|
|
|
|
|
<span className="text-secondary-content">{t('learnMore')}</span>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="p-2 text-sm">
|
|
|
|
|
<Ul>
|
|
|
|
|
{authors.length > 0 ? (
|
|
|
|
|
<>
|
|
|
|
|
<li className="list-none font-medium opacity-70 italic">{t('authors')}:</li>
|
2023-05-17 10:53:41 +02:00
|
|
|
|
<PersonList list={authors} slug={slug} />
|
2023-05-15 20:00:45 +02:00
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{maintainers.length > 0 ? (
|
|
|
|
|
<>
|
|
|
|
|
<li className="list-none font-medium opacity-70 italic">{t('maintainers')}:</li>
|
|
|
|
|
<PersonList list={authors} />
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<li className="list-none font-medium opacity-70 italic">{t('lastUpdated')}:</li>
|
|
|
|
|
<li className="list-none font-medium">
|
|
|
|
|
<TimeAgo date={updated} t={t} />
|
|
|
|
|
</li>
|
|
|
|
|
</Ul>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2021-12-18 09:54:53 +01:00
|
|
|
|
|
2023-05-20 13:22:36 +02:00
|
|
|
|
export const MdxWrapper = ({ MDX = false, frontmatter = {}, components = {}, children = [] }) => {
|
2023-05-15 20:00:45 +02:00
|
|
|
|
const { t } = useTranslation('docs')
|
2023-05-15 15:57:46 +02:00
|
|
|
|
const allComponents = { ...baseComponents, ...components }
|
2023-05-15 20:00:45 +02:00
|
|
|
|
const { locale, slug } = useContext(NavigationContext)
|
|
|
|
|
|
2023-05-17 10:53:41 +02:00
|
|
|
|
const updates = docUpdates[slug] || {}
|
2021-12-18 09:54:53 +01:00
|
|
|
|
|
2023-05-15 15:57:46 +02:00
|
|
|
|
return (
|
2022-12-26 17:10:14 +01:00
|
|
|
|
<div className="text-primary mdx max-w-prose text-base-content max-w-prose text-base">
|
2023-05-17 10:53:41 +02:00
|
|
|
|
<MetaData
|
|
|
|
|
maintainers={frontmatter?.maintainers || []}
|
2023-05-19 18:15:06 +02:00
|
|
|
|
authors={updates.authors || []}
|
|
|
|
|
lastUpdated={updates.lastUpdates}
|
2023-05-17 10:53:41 +02:00
|
|
|
|
{...{ locale, slug, t }}
|
|
|
|
|
/>
|
2023-05-20 13:22:36 +02:00
|
|
|
|
{MDX ? <MDX components={allComponents} /> : children}
|
2022-12-04 15:04:56 +01:00
|
|
|
|
</div>
|
|
|
|
|
)
|
2021-12-18 09:54:53 +01:00
|
|
|
|
}
|