~repos /website

#astro#js#html#css

git clone https://pyrossh.dev/repos/website.git

木 Personal website of pyrossh. Built with astrojs, shiki, vite.


49c5a070 pyrossh

3 weeks ago
update stuff
src/components/Commit.astro CHANGED
@@ -1,20 +1,27 @@
1
1
  ---
2
2
  import { format } from "timeago.js";
3
+ import type { Commit } from "../utils/files";
3
4
 
5
+ type Props = {
6
+ repoId: string;
7
+ commit: Commit;
8
+ };
9
+
10
+ const { repoId, commit } = Astro.props;
4
- const { title, author_name, hash, date, message, branches, tags } = Astro.props;
11
+ const { author_name, hash, date, message, branches, tags } = commit;
5
12
  ---
6
13
 
7
14
  <div class="event">
8
15
  <div>
9
- <a href={`/repos/${title}/commits/${hash}`} title={hash} rel="nofollow">
16
+ <a href={`/repos/${repoId}/commits/${hash}`} title={hash} rel="nofollow">
10
17
  {hash.substring(0, 8)}
11
18
  </a>
12
-
19
+
13
20
  <strong>{author_name}</strong>
14
21
  <small class="pull-right">
15
22
  <h3>{branches}</h3>
16
23
  <h3>{tags}</h3>
17
- <a href={`/repos/${title}/logs?from=??`} rel="nofollow">
24
+ <a href={`/repos/${repoId}/logs?from=??`} rel="nofollow">
18
25
  <span title={date}>
19
26
  {format(date)}
20
27
  </span>
src/components/RecursiveList.astro CHANGED
@@ -14,11 +14,11 @@ interface FileNode {
14
14
 
15
15
  interface Props {
16
16
  items: FileNode[];
17
- repoTitle: string;
17
+ repoId: string;
18
18
  depth?: number;
19
19
  }
20
20
 
21
- const { items, repoTitle, depth = 0 } = Astro.props;
21
+ const { items, repoId, depth = 0 } = Astro.props;
22
22
  ---
23
23
 
24
24
  {
@@ -38,7 +38,7 @@ const { items, repoTitle, depth = 0 } = Astro.props;
38
38
  <ul>
39
39
  <Astro.self
40
40
  items={item.children}
41
- repoTitle={repoTitle}
41
+ repoId={repoId}
42
42
  depth={depth + 1}
43
43
  />
44
44
  </ul>
@@ -51,7 +51,7 @@ const { items, repoTitle, depth = 0 } = Astro.props;
51
51
  <div class="file-content">
52
52
  <div class="file-name">
53
53
  <Icon name="mdi:file" size="24px" color="hsl(0deg 75% 75%)" />
54
- <a href={`/repos/${repoTitle}/files/${item.path}`} rel="nofollow">
54
+ <a href={`/repos/${repoId}/files/${item.path}`} rel="nofollow">
55
55
  {item.name}
56
56
  </a>
57
57
  </div>
src/layouts/FileLayout.astro CHANGED
@@ -18,7 +18,7 @@ const { repo, file } = Astro.props;
18
18
  const { pathname } = Astro.url;
19
19
  ---
20
20
 
21
- <RepoLayout data={repo.data}>
21
+ <RepoLayout repo={repo}>
22
22
  {
23
23
  (
24
24
  <div>
src/layouts/RepoLayout.astro CHANGED
@@ -3,11 +3,13 @@ import { type CollectionEntry } from "astro:content";
3
3
  import { Icon } from "astro-icon/components";
4
4
  import Layout from "@/layouts/BaseLayout.astro";
5
5
 
6
+ type Props = {
6
- type Props = Pick<CollectionEntry<"repos">, "data">;
7
+ repo: CollectionEntry<"repos">;
8
+ }
7
9
 
8
10
  const {
9
11
  data: { title, description, tags, badges },
10
- } = Astro.props;
12
+ } = Astro.props.repo;
11
13
  const { pathname } = Astro.url;
12
14
  ---
13
15
 
src/pages/posts/{[...slug].astro → [...postId]/index.astro} RENAMED
@@ -7,7 +7,7 @@ import FormattedDate from "@/components/FormattedDate.astro";
7
7
  export async function getStaticPaths() {
8
8
  const posts = await getCollection("content");
9
9
  return posts.map((post) => ({
10
- params: { slug: post.id },
10
+ params: { postId: post.id },
11
11
  props: post,
12
12
  }));
13
13
  }
src/pages/repos/[...repoId]/commits/[...hash]/index.astro ADDED
@@ -0,0 +1,31 @@
1
+ ---
2
+ import { type CollectionEntry, getCollection } from "astro:content";
3
+ import RepoLayout from "@/layouts/RepoLayout.astro";
4
+ import Commit from "@/components/Commit.astro";
5
+ import type { Commit as CommitType } from "../../../../../utils/files";
6
+
7
+ export async function getStaticPaths() {
8
+ const repos = await getCollection("repos");
9
+ return repos.flatMap((repo) => {
10
+ return repo.data.commits.map((commit) => ({
11
+ params: { repoId: repo.id, hash: commit.hash },
12
+ props: {
13
+ repo: repo,
14
+ commit: commit,
15
+ },
16
+ }));
17
+ });
18
+ }
19
+
20
+ type Props = {
21
+ repo: CollectionEntry<"repos">;
22
+ commit: CommitType;
23
+ };
24
+
25
+ const { repo, commit } = Astro.props;
26
+ ---
27
+
28
+ <RepoLayout repo={repo}>
29
+ <Commit repoId={repo.id} commit={commit} />
30
+ <p>WIP: Show Diff summary</p>
31
+ </RepoLayout>
src/pages/repos/{[...slug] → [...repoId]}/commits/index.astro RENAMED
@@ -6,16 +6,21 @@ import Commit from "@/components/Commit.astro";
6
6
  export async function getStaticPaths() {
7
7
  const repos = await getCollection("repos");
8
8
  return repos.map((repo) => ({
9
- params: { slug: repo.id },
9
+ params: { repoId: repo.id },
10
+ props: {
10
- props: repo,
11
+ repo: repo,
12
+ }
11
13
  }));
12
14
  }
15
+ type Props = {
13
- type Props = CollectionEntry<"repos">;
16
+ repo: CollectionEntry<"repos">;
17
+ }
18
+ const { repo } = Astro.props;
14
19
  const {
15
20
  data: { commits },
16
- } = Astro.props;
21
+ } = repo;
17
22
  ---
18
23
 
19
- <RepoLayout data={Astro.props.data}>
24
+ <RepoLayout repo={repo}>
20
- {commits.map((commit) => <Commit {...commit} message={commit.body} />)}
25
+ {commits.map((commit) => <Commit repoId={repo.id} commit={commit} />)}
21
26
  </RepoLayout>
src/pages/repos/{[...slug] → [...repoId]}/files/[...file]/blame/index.astro RENAMED
@@ -8,7 +8,7 @@ export async function getStaticPaths() {
8
8
  return repos.flatMap((repo) => {
9
9
  const allFiles = collectFiles(repo.data.files);
10
10
  return allFiles.map((file) => ({
11
- params: { slug: repo.id, file: file.path },
11
+ params: { repoId: repo.id, file: file.path },
12
12
  props: {
13
13
  repo: repo,
14
14
  file: file,
@@ -17,7 +17,7 @@ export async function getStaticPaths() {
17
17
  });
18
18
  }
19
19
  type Props = {
20
- repo: CollectionEntry<"repos">;
20
+ repoId: CollectionEntry<"repos">;
21
21
  file: {
22
22
  name: string;
23
23
  path: string;
src/pages/repos/{[...slug] → [...repoId]}/files/[...file]/history/index.astro RENAMED
@@ -2,6 +2,7 @@
2
2
  import { type CollectionEntry, getCollection } from "astro:content";
3
3
  import FileLayout from "@/layouts/FileLayout.astro";
4
4
  import Commit from "@/components/Commit.astro";
5
+ import type { Commit as CommitType } from "../../../../../../utils/files";
5
6
  import { collectFiles } from "@/utils/files";
6
7
 
7
8
  export async function getStaticPaths() {
@@ -9,7 +10,7 @@ export async function getStaticPaths() {
9
10
  return repos.flatMap((repo) => {
10
11
  const allFiles = collectFiles(repo.data.files);
11
12
  return allFiles.map((file) => ({
12
- params: { slug: repo.id, file: file.path },
13
+ params: { repoId: repo.id, file: file.path },
13
14
  props: {
14
15
  repo: repo,
15
16
  file: file,
@@ -25,13 +26,7 @@ type Props = {
25
26
  size: number;
26
27
  isDirectory: boolean;
27
28
  absolutePath: string;
28
- history: {
29
- hash: string;
30
- message: string;
31
- body: string;
32
- branches: string[];
33
- tags: string[];
29
+ history: CommitType[];
34
- }[];
35
30
  };
36
31
  };
37
32
 
@@ -39,5 +34,5 @@ const { repo, file } = Astro.props;
39
34
  ---
40
35
 
41
36
  <FileLayout repo={repo} file={file}>
42
- {file.history.map((commit) => <Commit {...commit} message={commit.body} />)}
37
+ {file.history.map((commit) => <Commit repoId={repo.id} commit={commit} />)}
43
38
  </FileLayout>
src/pages/repos/{[...slug] → [...repoId]}/files/[...file]/index.astro RENAMED
@@ -11,7 +11,7 @@ export async function getStaticPaths() {
11
11
  return repos.flatMap((repo) => {
12
12
  const allFiles = collectFiles(repo.data.files);
13
13
  return allFiles.map((file) => ({
14
- params: { slug: repo.id, file: file.path },
14
+ params: { repoId: repo.id, file: file.path },
15
15
  props: {
16
16
  repo: repo,
17
17
  file: file,
@@ -20,7 +20,7 @@ export async function getStaticPaths() {
20
20
  });
21
21
  }
22
22
  type Props = {
23
- repo: CollectionEntry<"repos">;
23
+ repoId: CollectionEntry<"repos">;
24
24
  file: {
25
25
  name: string;
26
26
  path: string;
src/pages/repos/{[...slug] → [...repoId]}/files/index.astro RENAMED
@@ -6,20 +6,22 @@ import RecursiveList from "@/components/RecursiveList.astro";
6
6
  export async function getStaticPaths() {
7
7
  const repos = await getCollection("repos");
8
8
  return repos.map((repo) => ({
9
- params: { slug: repo.id },
9
+ params: { repoId: repo.id },
10
- props: repo,
10
+ props: {
11
+ repo,
12
+ },
11
13
  }));
12
14
  }
15
+ type Props = {
13
- type Props = CollectionEntry<"repos">;
16
+ repo: CollectionEntry<"repos">;
14
- const {
17
+ };
15
- data: { title, files },
16
- } = Astro.props;
18
+ const { repo } = Astro.props;
17
19
  ---
18
20
 
19
- <RepoLayout data={Astro.props.data}>
21
+ <RepoLayout repo={repo}>
20
22
  <div class="container">
21
23
  <ul class="file-tree">
22
- <RecursiveList items={files} repoTitle={title} />
24
+ <RecursiveList items={repo.data.files} repoId={repo.id} />
23
25
  </ul>
24
26
  </div>
25
27
  </RepoLayout>
src/pages/repos/{[...slug] → [...repoId]}/index.astro RENAMED
@@ -8,22 +8,27 @@ import styles from "./index.module.css";
8
8
  export async function getStaticPaths() {
9
9
  const repos = await getCollection("repos");
10
10
  return repos.map((repo) => ({
11
- params: { slug: repo.id },
11
+ params: { repoId: repo.id },
12
+ props: {
12
- props: repo,
13
+ repo: repo,
14
+ },
13
15
  }));
14
16
  }
17
+ type Props = {
15
- type Props = CollectionEntry<"repos">;
18
+ repo: CollectionEntry<"repos">;
19
+ };
16
20
 
21
+ const { repo } = Astro.props;
17
22
  const {
18
- data: { title, commits },
23
+ data: { commits },
19
- } = Astro.props;
24
+ } = repo;
20
25
  const latestCommits = commits.slice(0, 3);
21
- const { Content } = await render(Astro.props);
26
+ const { Content } = await render(repo);
22
27
  ---
23
28
 
24
- <RepoLayout data={Astro.props.data}>
29
+ <RepoLayout repo={repo}>
25
30
  <div class={styles.summary}>
26
- {latestCommits.map((commit) => <Commit title={title} {...commit} />)}
31
+ {latestCommits.map((commit) => <Commit repoId={repo.id} commit={commit} />)}
27
32
  </div>
28
33
  <hr />
29
34
  <article>
src/pages/repos/{[...slug] → [...repoId]}/index.module.css RENAMED
File without changes
src/utils/files.ts CHANGED
@@ -16,7 +16,7 @@ export interface Commit {
16
16
  date: string;
17
17
  branches: string[];
18
18
  tags: string[];
19
- diff: DiffSummary;
19
+ diff?: string;
20
20
  }
21
21
 
22
22
  export interface FileNode {
@@ -39,7 +39,7 @@ export const CommitSchema = z.object({
39
39
  date: z.string(),
40
40
  branches: z.array(z.string()),
41
41
  tags: z.array(z.string()),
42
- // diff: z.string(),
42
+ diff: z.string().optional(),
43
43
  });
44
44
 
45
45
  export const FileNodeSchema: z.ZodType<FileNode> = z.lazy(() =>