Skip to content

Commit 22bc0dd

Browse files
committed
generate repo ids
1 parent 53c34ce commit 22bc0dd

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

docs/.vitepress/config/en.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig } from "vitepress";
33
import request from "sync-request";
44
import { repositories } from "../../data/repositories";
55
import { changelog } from "../../data/changelog";
6+
import { generateRepoId } from "../../helper/generateRepoId";
67

78
const require = createRequire(import.meta.url);
89
const pkg = require("vitepress/package.json");
@@ -147,16 +148,17 @@ function repos() {
147148
return repositories.map((repo) => {
148149
const response = request("GET", `${repo.url}json/modules.json`);
149150
const rep = JSON.parse(response.getBody("utf8"));
151+
const repoId = generateRepoId(repo.url);
150152
const modules = rep.modules.map((module) => {
151153
return {
152154
text: module.name,
153-
link: `/repository/${repo.id}/${module.id}`,
155+
link: `/repository/${repoId}/${module.id}`,
154156
};
155157
});
156158

157159
return {
158160
text: repo.name,
159-
link: `/repository/${repo.id}`,
161+
link: `/repository/${repoId}`,
160162
collapsed: true,
161163
items: modules,
162164
};

docs/en/repository/[name].md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import RepoHeader from '../../components/repository/RepoHeader.vue'
1515
const { params } = useData()
1616

1717
const name = params.value.name
18-
const repository = repositories.find((repo) => repo.id === name)
18+
const url = params.value.url
19+
const repository = repositories.find((repo) => repo.url === url)
1920

2021
const data = ref(null);
2122

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { repositories } from "../../data/repositories";
2+
import { generateRepoId } from "../../helper/generateRepoId";
23

34
const parsedRepos = repositories.map((repo) => {
45
return {
56
params: {
67
title: repo.name,
7-
name: repo.id,
8+
name: generateRepoId(repo.url),
9+
url: repo.url,
810
},
911
};
1012
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { repositories } from "../../../data/repositories";
2+
import { generateRepoId } from "../../../helper/generateRepoId";
3+
24

35
export default {
46
async paths() {
@@ -13,7 +15,7 @@ export default {
1315
title: module.name,
1416
description: module.description,
1517
module: module,
16-
name: repo.id,
18+
name: generateRepoId(repo.url),
1719
id: module.id,
1820
},
1921
};

docs/helper/generateRepoId.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function generateRepoId(url: string): string {
2+
const _url = new URL(url);
3+
let cleanedText = _url.hostname + _url.pathname;
4+
cleanedText = cleanedText.replace(/[.:\/\-_]/g, '');
5+
6+
const length = cleanedText.length;
7+
const middleStart = Math.floor((length - 3) / 2);
8+
const middleEnd = middleStart + 3;
9+
10+
const firstThree = cleanedText.substring(0, 3);
11+
const middleThree = cleanedText.substring(middleStart, middleEnd);
12+
const lastThree = cleanedText.substring(length - 3);
13+
14+
return firstThree + middleThree + lastThree;
15+
}

0 commit comments

Comments
 (0)