File tree Expand file tree Collapse file tree 5 files changed +27
-5
lines changed
Expand file tree Collapse file tree 5 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { defineConfig } from "vitepress";
33import request from "sync-request" ;
44import { repositories } from "../../data/repositories" ;
55import { changelog } from "../../data/changelog" ;
6+ import { generateRepoId } from "../../helper/generateRepoId" ;
67
78const require = createRequire ( import . meta. url ) ;
89const 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 } ;
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ import RepoHeader from '../../components/repository/RepoHeader.vue'
1515const { params } = useData ()
1616
1717const 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
2021const data = ref (null );
2122
Original file line number Diff line number Diff line change 11import { repositories } from "../../data/repositories" ;
2+ import { generateRepoId } from "../../helper/generateRepoId" ;
23
34const 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} ) ;
Original file line number Diff line number Diff line change 11import { repositories } from "../../../data/repositories" ;
2+ import { generateRepoId } from "../../../helper/generateRepoId" ;
3+
24
35export 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 } ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments