Skip to content

Commit d468ead

Browse files
committed
imporve repository
1 parent 22bc0dd commit d468ead

File tree

13 files changed

+358
-204
lines changed

13 files changed

+358
-204
lines changed

docs/.vitepress/config/en.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createRequire } from "module";
22
import { defineConfig } from "vitepress";
33
import request from "sync-request";
4-
import { repositories } from "../../data/repositories";
4+
import { repositories, Repository } from "../../data/repositories";
55
import { changelog } from "../../data/changelog";
6-
import { generateRepoId } from "../../helper/generateRepoId";
76

87
const require = createRequire(import.meta.url);
98
const pkg = require("vitepress/package.json");
@@ -146,19 +145,20 @@ function sidebarLegal() {
146145

147146
function repos() {
148147
return repositories.map((repo) => {
148+
const r = new Repository(repo.url);
149+
149150
const response = request("GET", `${repo.url}json/modules.json`);
150151
const rep = JSON.parse(response.getBody("utf8"));
151-
const repoId = generateRepoId(repo.url);
152152
const modules = rep.modules.map((module) => {
153153
return {
154154
text: module.name,
155-
link: `/repository/${repoId}/${module.id}`,
155+
link: `/repository/${r.id}/${module.id}`,
156156
};
157157
});
158158

159159
return {
160160
text: repo.name,
161-
link: `/repository/${repoId}`,
161+
link: `/repository/${r.id}`,
162162
collapsed: true,
163163
items: modules,
164164
};

docs/.vitepress/config/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import ViteYaml from "@modyfi/vite-plugin-yaml";
33
import { pagefindPlugin } from "vitepress-plugin-pagefind";
44
// Imports
55
import { defineConfig, SiteConfig } from "vitepress";
6-
import { writeFile } from "fs/promises";
6+
import { writeFile, copyFile } from "fs/promises";
77
import { resolve } from "path";
8-
import { repositoriesJSONstringify } from "../../data/repositories";
98
import { blacklistJSONstringify } from "../../data/blacklist";
109
import { changelogJSONstringify } from "../../data/changelog";
1110

11+
1212
export const shared = defineConfig({
1313
vite: {
1414
plugins: [ViteYaml(), pagefindPlugin()],
@@ -54,7 +54,7 @@ export const shared = defineConfig({
5454
const publicBlackList = resolve(publicApi, "blacklist.json");
5555
const publicChangelogList = resolve(publicApi, "changelog.json");
5656

57-
await writeFile(publicRepoList, repositoriesJSONstringify);
57+
await copyFile(resolve(__dirname, "../../../meta/repositories.json"), publicRepoList);
5858
await writeFile(publicBlackList, blacklistJSONstringify);
5959
await writeFile(publicChangelogList, changelogJSONstringify);
6060
},

docs/components/repository/ModuleItem.vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
<script setup>
2+
import { computed } from "vue";
23
import { toFormattedFileSize } from "../../helper/toFormattedFileSize";
4+
import { Repository } from "../../data/repositories";
35
import { useData } from "vitepress";
46
57
import { VPLink } from "vitepress/theme";
68
7-
const props = defineProps(["module", "params"]);
9+
const { lang, params } = useData();
810
9-
const { lang } = useData();
11+
const props = defineProps(["module"]);
12+
const repo = computed(() => new Repository(params.value.url));
1013
11-
const timestamp = props.module.timestamp;
12-
const params = props.params;
13-
const module = props.module;
14+
15+
const timestamp = computed(() => props.module.timestamp);
16+
const module = computed(() => props.module);
1417
1518
const getLastUpdated = () => {
16-
if (!timestamp) {
19+
if (!timestamp.value) {
1720
return "Invalid date";
1821
}
1922
2023
return Intl.DateTimeFormat(lang, {
2124
year: "numeric",
2225
day: "2-digit",
23-
month: "short",
26+
month: "long",
2427
hour12: true,
25-
}).format(new Date(timestamp * 1000));
28+
}).format(new Date(timestamp.value * 1000));
2629
};
2730
</script>
2831

2932
<template>
30-
<VPLink decoration="none" :href="'repository/' + params.name + '/' + module.id">
33+
<VPLink decoration="none" :href="'repository/' + repo.id + '/' + module.id">
3134
<div :class="$style.feature">
3235
<article>
3336
<img v-if="module.cover" :class="$style.moduleCover" :src="module.cover" />

docs/components/repository/RepoHeader.vue

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<script setup>
2-
import { ref } from "vue";
2+
import { ref, computed } from "vue";
33
import Dialog from "../Dialog.vue";
44
import { VPTeamMembers, VPButton } from "vitepress/theme";
5+
import { Repository } from "../../data/repositories";
56
6-
defineProps(["repo", "internalRepo"]);
7+
const props = defineProps(["repo"]);
8+
const internalRepo = computed(() => new Repository(props.repo.url));
9+
10+
console.log(internalRepo.value.members);
711
812
const showModal = ref(false);
913
@@ -20,17 +24,33 @@ const closeModal = () => {
2024

2125
<template>
2226
<div :class="$style.repoMetaContainer">
23-
<img v-if="repo.cover" :class="$style.repoCover" :src="repo.cover" />
24-
<span :class="$style.repoTitle">{{ repo.name }}</span>
25-
<span v-if="repo.description" :class="$style.repoDetails">{{ repo.description }}</span>
26-
<div v-if="repo.submission || repo.support || repo.donate" :class="$style.repoActions">
27-
<VPButton tag="a" v-if="repo.submission" text="Submit Module" size="medium" theme="brand" :href="repo.submission" />
28-
<VPButton tag="a" v-if="repo.support" text="Support" size="medium" theme="alt" :href="repo.support" />
29-
<VPButton v-if="internalRepo.members" text="Team" size="medium" theme="alt" @click="openModal" />
30-
<VPButton tag="a" v-if="repo.donate" text="Donate" size="medium" theme="sponsor" :href="repo.donate" />
27+
<img v-if="props.repo.cover" :class="$style.repoCover" :src="props.repo.cover" />
28+
<span :class="$style.repoTitle">{{ props.repo.name }}</span>
29+
<span v-if="props.repo.description" :class="$style.repoDetails">{{ props.repo.description }}</span>
30+
<div v-if="props.repo.submission || props.repo.support || props.repo.donate || props.repo.memebers" :class="$style.repoActions">
31+
<VPButton tag="a" v-if="props.repo.submission" text="Submit Module" size="medium" theme="brand" :href="props.repo.submission" />
32+
<VPButton tag="a" v-if="props.repo.support" text="Support" size="medium" theme="alt" :href="props.repo.support" />
33+
<VPButton v-if="internalRepo.members.length !== 0" text="Team" size="medium" theme="alt" @click="openModal" />
34+
<VPButton tag="a" v-if="props.repo.donate" text="Donate" size="medium" theme="sponsor" :href="props.repo.donate" />
3135
</div>
36+
<details class="details custom-block">
37+
<summary>Repository URL to add it to MMRL</summary>
38+
39+
<div class="language-text vp-adaptive-theme line-numbers-mode">
40+
<button title="Copy Code" class="copy"></button>
41+
<span class="lang">ts</span>
42+
<pre
43+
class="shiki shiki-themes github-light github-dark vp-code"
44+
tabindex="0"
45+
><code><span class="line">{{ internalRepo.mmrlUrl }}</span></code></pre>
46+
<div class="line-numbers-wrapper" aria-hidden="true">
47+
<span class="line-number">1</span>
48+
<br />
49+
</div>
50+
</div>
51+
</details>
3252
</div>
33-
<Dialog :open="showModal" :onClose="closeModal" :onOpen="openModal" :contentStyle="{ padding: '16px 26px' }" title="Repository Member">
53+
<Dialog :open="showModal" :onClose="closeModal" :onOpen="openModal" :contentStyle="{ padding: '16px 26px' }" title="Repository Members">
3454
<VPTeamMembers size="small" :members="internalRepo.members" />
3555
</Dialog>
3656
</template>

docs/data/repositories.ts

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,88 @@
1-
import { readFileSync } from "fs";
2-
import { join } from "path";
3-
import { parse } from "yaml";
4-
5-
export const fileName = join(__dirname, "../../meta/repositories.yaml");
6-
7-
export const repositories: any = parse(readFileSync(fileName, "utf8"));
8-
export const repositoriesJSONstringify: string = JSON.stringify(
9-
repositories,
10-
null,
11-
4
12-
);
1+
import repositories from "../../meta/repositories.json";
2+
3+
export { repositories };
4+
5+
interface RepositoryMember {
6+
avatar: string;
7+
name: string;
8+
title?: string;
9+
org?: string;
10+
orgLink?: string;
11+
desc?: string;
12+
links?: SocialLink[];
13+
sponsor?: string;
14+
actionText?: string;
15+
}
16+
17+
interface SocialLink {
18+
icon: SocialLinkIcon;
19+
link: string;
20+
ariaLabel?: string;
21+
}
22+
23+
type SocialLinkIcon =
24+
| "discord"
25+
| "facebook"
26+
| "github"
27+
| "instagram"
28+
| "linkedin"
29+
| "mastodon"
30+
| "npm"
31+
| "slack"
32+
| "twitter"
33+
| "x"
34+
| "youtube"
35+
| { svg: string }
36+
| string;
37+
38+
export interface RawRepository {
39+
name: string;
40+
url: string;
41+
members?: RepositoryMember[];
42+
}
43+
44+
export class Repository {
45+
public repository: RawRepository;
46+
47+
public constructor(public url: string) {
48+
const repo = repositories.find((repo) => repo.url === url);
49+
if (!repo) throw new Error(`Repository with URL ${url} not found`);
50+
this.repository = repo;
51+
}
52+
53+
public get id() {
54+
const url = new URL(this.url);
55+
let cleanedText = url.hostname + url.pathname;
56+
cleanedText = cleanedText.replace(/[.:\/\-_]/g, "");
57+
58+
const length = cleanedText.length;
59+
const middleStart = Math.floor((length - 3) / 2);
60+
const middleEnd = middleStart + 3;
61+
62+
const firstThree = cleanedText.substring(0, 3);
63+
const middleThree = cleanedText.substring(middleStart, middleEnd);
64+
const lastThree = cleanedText.substring(length - 3);
65+
66+
return firstThree + middleThree + lastThree;
67+
}
68+
69+
public get name(): string {
70+
return this.repository.name;
71+
}
72+
73+
public get members(): RepositoryMember[] {
74+
return this.repository.members;
75+
}
76+
77+
public get modules(): string {
78+
return `${this.url}json/modules.json`;
79+
}
80+
81+
public get config(): string {
82+
return `${this.url}json/config.json`;
83+
}
84+
85+
public get mmrlUrl(): string {
86+
return this.url.replace(/^\w+:\/\/([^\/]+\/?.*?)\/?$/g, "$1");
87+
}
88+
}

docs/en/repository/[name].md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,44 @@ next: false
55
---
66

77
<script setup>
8-
import { ref, onMounted } from "vue";
8+
import { ref, onMounted, computed } from "vue";
99
import { useData } from 'vitepress'
10-
import repositories from '../../../meta/repositories.yaml'
10+
import { repositories, Repository } from '../../data/repositories'
1111

1212
import ModuleItem from '../../components/repository/ModuleItem.vue'
1313
import RepoHeader from '../../components/repository/RepoHeader.vue'
1414

1515
const { params } = useData()
16-
17-
const name = params.value.name
18-
const url = params.value.url
19-
const repository = repositories.find((repo) => repo.url === url)
16+
const repository = computed(()=> new Repository(params.value.url))
2017

2118
const data = ref(null);
2219

2320
onMounted(async () => {
2421
const response = await fetch(
25-
`${repository.url}json/modules.json`
22+
repository.value.modules
2623
);
2724
data.value = await response.json();
2825
});
2926

27+
const repoHeader = computed(()=> {
28+
const { modules, ...rest } = data.value;
29+
return { url: repository.value.url, ...rest };
30+
})
31+
3032
const openUrl = (url) => {
3133
window.open(url);
3234
};
3335
</script>
3436

3537
<div v-if="data">
36-
<RepoHeader :repo="data" :internalRepo="repository" />
38+
<RepoHeader :repo="repoHeader" />
3739
<div :class="$style.items" v-for="module in data.modules">
3840
<div :class="$style.item">
39-
<ModuleItem :module="module" :params="$params" />
41+
<ModuleItem :module="module" />
4042
</div>
4143
</div>
4244
</div>
4345

44-
4546
<style scoped>
4647
a {
4748
color: inherit !important;

docs/en/repository/[name].paths.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { repositories } from "../../data/repositories";
2-
import { generateRepoId } from "../../helper/generateRepoId";
1+
import { repositories, Repository } from "../../data/repositories";
32

43
const parsedRepos = repositories.map((repo) => {
4+
const myRepo = new Repository(repo.url);
5+
56
return {
67
params: {
7-
title: repo.name,
8-
name: generateRepoId(repo.url),
9-
url: repo.url,
8+
title: myRepo.name,
9+
name: myRepo.id,
10+
url: myRepo.url,
1011
},
1112
};
1213
});

0 commit comments

Comments
 (0)