-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split PluginContentReadme, show plugin introduction_urls
- Loading branch information
1 parent
ce0f7ef
commit 1b2bceb
Showing
7 changed files
with
111 additions
and
50 deletions.
There are no files selected for viewing
30 changes: 28 additions & 2 deletions
30
src/app/[locale]/plugin/[pluginId]/introduction/plugin-content-introduction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
import { AllOfAPlugin } from "@/catalogue/meta-types"; | ||
import GfmMarkdown from "@/components/markdown/gfm-markdown"; | ||
import { translateLangDict } from "@/utils/i18n-utils"; | ||
import { getLocale } from "next-intl/server"; | ||
import { getLocale, getTranslations } from "next-intl/server"; | ||
import React from "react"; | ||
import { NaLink } from "@/components/na-link"; | ||
import { rawToRelative } from "@/utils/repos-utils"; | ||
|
||
export async function PluginContentIntroduction({plugin}: { plugin: AllOfAPlugin }) { | ||
const introduction = translateLangDict(await getLocale(), plugin.plugin.introduction, true) || '' | ||
const t = await getTranslations('page.plugin.introduction') | ||
const locale = await getLocale() | ||
|
||
const introduction = translateLangDict(locale, plugin.plugin.introduction, true) || '' | ||
let introductionSrc: React.ReactNode = <span>N/A</span> | ||
const introductionUrl = translateLangDict(locale, plugin.plugin.introduction_urls, false) | ||
if (introductionUrl) { | ||
let ld = rawToRelative(introductionUrl, plugin.plugin.repository, plugin.plugin.branch) | ||
if (ld) { | ||
introductionSrc = <NaLink href={ld.href} hoverUnderline>{ld.display}</NaLink> | ||
} else { | ||
ld = rawToRelative(introductionUrl, 'https://github.com/MCDReforged/PluginCatalogue', 'master') | ||
if (ld) { | ||
introductionSrc = <NaLink href={ld.href} hoverUnderline>{t('plugin_catalogue')} {ld.display.split('/').pop()}</NaLink> | ||
} else { | ||
introductionSrc = <NaLink href={introductionUrl} hoverUnderline>{introductionUrl}</NaLink> | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{/* SSR, no need to use GfmMarkdownDynamic */} | ||
<GfmMarkdown allowEmbedHtml allowAnchor repository={plugin.plugin.repository}> | ||
{introduction} | ||
</GfmMarkdown> | ||
|
||
<p className="mt-5 text-end text-sm text-mantine-dimmed"> | ||
{t('introduction_source')} | ||
{introductionSrc} | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/app/[locale]/plugin/[pluginId]/readme/plugin-content-readme.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { AllOfAPlugin } from "@/catalogue/meta-types"; | ||
import GfmMarkdown from "@/components/markdown/gfm-markdown"; | ||
import { NaLink } from "@/components/na-link"; | ||
import { NoneText } from "@/components/none-text"; | ||
import { getTranslations } from "next-intl/server"; | ||
import React from "react"; | ||
import { rawToRelative } from "@/utils/repos-utils"; | ||
|
||
export async function PluginContentReadme({plugin}: { plugin: AllOfAPlugin }) { | ||
const t = await getTranslations('page.plugin.readme') | ||
|
||
const readme = plugin.repository?.readme | ||
const readmeUrl = plugin.repository?.readme_url | ||
if (!readme || !readmeUrl) { | ||
return <NoneText>{t('no_readme')}</NoneText> | ||
} | ||
|
||
let readmeSrc: React.ReactNode = <span>N/A</span> | ||
if (readmeUrl) { | ||
const ld = rawToRelative(readmeUrl, plugin.plugin.repository, plugin.plugin.branch) | ||
if (ld) { | ||
readmeSrc = <NaLink href={ld.href} hoverUnderline>{ld.display}</NaLink> | ||
} else { | ||
readmeSrc = <NaLink href={readmeUrl} hoverUnderline>{readmeUrl}</NaLink> | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
{/* SSR, no need to use GfmMarkdownDynamic */} | ||
<GfmMarkdown allowEmbedHtml allowAnchor repository={plugin.plugin.repository}> | ||
{readme} | ||
</GfmMarkdown> | ||
|
||
<p className="mt-5 text-end text-sm text-mantine-dimmed"> | ||
{t('readme_source')} | ||
{readmeSrc} | ||
</p> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters