Skip to content

Commit f248605

Browse files
committed
ライセンスページのui調整、url表示の修正
1 parent 0f58816 commit f248605

4 files changed

Lines changed: 79 additions & 35 deletions

File tree

app/about/license/ThirdPartyLicenses.tsx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
22

3+
import { StyledSyntaxHighlighter } from "@/markdown/styledSyntaxHighlighter";
4+
import { langConstants } from "@my-code/runtime/languages";
35
import { useState } from "react";
46

57
export interface LicenseEntry {
@@ -20,44 +22,71 @@ export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
2022
{licenses.map((pkg) => {
2123
const key = `${pkg.name}@${pkg.version}`;
2224
const isOpen = expanded === key;
25+
let repositoryURL: string;
26+
if (pkg.repository?.startsWith("http")) {
27+
repositoryURL = pkg.repository;
28+
} else if (pkg.repository?.startsWith("git+http")) {
29+
repositoryURL = pkg.repository?.slice(4);
30+
} else if (pkg.repository?.startsWith("git@")) {
31+
repositoryURL =
32+
"https://" +
33+
pkg.repository
34+
.slice(4)
35+
.replace(":", "/")
36+
.replace(/\.git$/, "");
37+
} else if (
38+
pkg.repository &&
39+
/github:[\w-]+\/[\w-]+/.test(pkg.repository)
40+
) {
41+
repositoryURL = `https://github.com/${pkg.repository.slice(7)}`;
42+
} else if (pkg.repository && /[\w-]+\/[\w-]+/.test(pkg.repository)) {
43+
// assume github username/repository
44+
repositoryURL = `https://github.com/${pkg.repository}`;
45+
} else {
46+
// fallback to source url
47+
// repositoryURL = pkg.source ?? "";
48+
}
2349
return (
2450
<div key={key} className="collapse collapse-arrow bg-base-200">
2551
<input
2652
type="checkbox"
2753
checked={isOpen}
2854
onChange={() => setExpanded(isOpen ? null : key)}
2955
/>
30-
<div className="collapse-title font-mono text-sm">
56+
<div className="collapse-title font-mono">
3157
<span className="font-bold">{pkg.name}</span>
3258
<span className="opacity-60 ml-2">v{pkg.version}</span>
33-
<span className="badge badge-outline badge-sm ml-3">
59+
<span className="badge badge-primary badge-soft badge-sm ml-3">
3460
{pkg.license}
3561
</span>
3662
</div>
37-
<div className="collapse-content text-sm">
63+
<div className="collapse-content">
3864
{pkg.author && (
3965
<p className="mb-1">
4066
<span className="opacity-60">Author: </span>
4167
{pkg.author}
4268
</p>
4369
)}
44-
{pkg.repository && (
70+
{repositoryURL && (
4571
<p className="mb-1">
4672
<span className="opacity-60">Repository: </span>
4773
<a
48-
className="link link-primary break-all"
49-
href={pkg.repository}
74+
className="link link-info break-all"
75+
href={repositoryURL}
5076
target="_blank"
5177
rel="noopener noreferrer"
5278
>
53-
{pkg.repository}
79+
{repositoryURL}
5480
</a>
5581
</p>
5682
)}
5783
{pkg.licenseText && (
58-
<pre className="mt-2 whitespace-pre-wrap text-xs bg-base-300 p-3 rounded-box overflow-x-auto">
84+
<StyledSyntaxHighlighter
85+
className="text-sm"
86+
language={langConstants(undefined)}
87+
>
5988
{pkg.licenseText}
60-
</pre>
89+
</StyledSyntaxHighlighter>
6190
)}
6291
</div>
6392
</div>

app/about/license/page.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
import { Metadata } from "next";
2-
import { Heading } from "@/markdown/heading";
3-
import licenseText from "../../../LICENSE?raw";
2+
import licenseText from "@/../LICENSE?raw";
43
import { LicenseEntry, ThirdPartyLicenses } from "./ThirdPartyLicenses";
54
import { isCloudflare } from "@/lib/detectCloudflare";
65
import { getCloudflareContext } from "@opennextjs/cloudflare";
76
import { readFile } from "node:fs/promises";
87
import { join } from "node:path";
8+
import { StyledMarkdown } from "@/markdown/markdown";
99

1010
export const metadata: Metadata = {
1111
title: "ライセンス",
1212
description:
1313
"my.code(); のライセンスおよび使用しているサードパーティライブラリのライセンス情報です。",
1414
};
1515

16+
const content = `
17+
# ライセンス
18+
19+
## my.code(); のライセンス
20+
21+
my.code(); のソースコードは MIT ライセンスのもとで公開されています。
22+
23+
\`\`\`
24+
${licenseText}
25+
\`\`\`
26+
27+
## サードパーティライブラリのライセンス
28+
29+
my.code(); は以下のオープンソースライブラリを使用しています。
30+
`;
31+
1632
export default async function LicensePage() {
1733
let licenses: LicenseEntry[];
1834
if (isCloudflare()) {
1935
const cfAssets = getCloudflareContext().env.ASSETS;
2036
const res = await cfAssets!.fetch(
21-
`https://assets.local/_next/static/oss-licenses.json`,
22-
{ cache: "no-cache" }
37+
`https://assets.local/_next/static/oss-licenses.json`
2338
);
2439
licenses = await res.json();
2540
} else {
@@ -38,20 +53,7 @@ export default async function LicensePage() {
3853

3954
return (
4055
<div className="p-4 pb-16 w-full max-w-docs mx-auto">
41-
<Heading level={1}>ライセンス</Heading>
42-
43-
<Heading level={2}>my.code(); のライセンス</Heading>
44-
<p className="my-4 opacity-80">
45-
my.code(); のソースコードは MIT ライセンスのもとで公開されています。
46-
</p>
47-
<pre className="bg-base-200 rounded-box p-4 text-sm whitespace-pre-wrap overflow-x-auto my-4">
48-
{licenseText}
49-
</pre>
50-
51-
<Heading level={2}>サードパーティライブラリのライセンス</Heading>
52-
<p className="my-4 opacity-80">
53-
my.code(); は以下のオープンソースライブラリを使用しています。
54-
</p>
56+
<StyledMarkdown content={content} />
5557
<ThirdPartyLicenses licenses={licenses} />
5658
</div>
5759
);

app/markdown/styledSyntaxHighlighter.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,47 @@ const SyntaxHighlighter = lazy(() => {
2121

2222
export function StyledSyntaxHighlighter(props: {
2323
children: string;
24+
className?: string;
2425
language: LangConstants;
2526
}) {
2627
const theme = useChangeTheme();
2728
const codetheme = theme === "tomorrow" ? tomorrow : tomorrowNight;
2829
const isClient = useIsClient();
2930
return isClient ? (
30-
<Suspense fallback={<FallbackPre>{props.children}</FallbackPre>}>
31+
<Suspense
32+
fallback={
33+
<FallbackPre className={props.className}>{props.children}</FallbackPre>
34+
}
35+
>
3136
<SyntaxHighlighter
32-
language={props.language.rsh}
37+
language={props.language.rsh ?? "text"}
3338
PreTag="div"
34-
className="border-2 border-current/20 mx-2 my-2 rounded-box p-4! bg-base-300! text-base-content!"
39+
className={clsx(
40+
"border-2 border-current/20 mx-2 my-2 rounded-box p-4! bg-base-300! text-base-content!",
41+
props.className
42+
)}
3543
style={codetheme}
3644
>
3745
{props.children}
3846
</SyntaxHighlighter>
3947
</Suspense>
4048
) : (
41-
<FallbackPre>{props.children}</FallbackPre>
49+
<FallbackPre className={props.className}>{props.children}</FallbackPre>
4250
);
4351
}
44-
function FallbackPre({ children }: { children: string }) {
52+
function FallbackPre({
53+
children,
54+
className,
55+
}: {
56+
children: string;
57+
className?: string;
58+
}) {
4559
return (
4660
<pre
4761
className={clsx(
4862
"border-2 border-current/20 mx-2 my-2 rounded-box p-4! bg-base-300! text-base-content!",
49-
"w-full overflow-auto"
63+
"w-full overflow-auto",
64+
className
5065
)}
5166
>
5267
{children}

packages/runtime/src/languages.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
// Markdownで指定される可能性のある言語名を列挙
42
export type MarkdownLang =
53
| "python"

0 commit comments

Comments
 (0)