Skip to content

Commit d5930fa

Browse files
authored
Merge pull request #520 from limzykenneth/main
Fix contributor docs script importing Astro dependencies
2 parents 59b8b7a + ec5a439 commit d5930fa

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ pnpm-debug.log*
2222

2323
temp/*
2424
in/
25-
out/
25+
out/
26+
translator/

src/pages/_utils-node.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,43 @@ export const getExampleCode = async (exampleId: string): Promise<string> => {
4242
};
4343

4444
export const removeNestedReferencePaths = (route: string): string =>
45-
route.replace(/constants\/|types\//, "")
45+
route.replace(/constants\/|types\//, "")
46+
47+
export const rewriteRelativeLink = (url: string): string => {
48+
let updatedUrl: string;
49+
50+
if (/^((https?:\/)?)\//.exec(url) || url.startsWith('mailto:')) {
51+
// Leave absolute paths alone
52+
updatedUrl = url;
53+
} else if (url.startsWith('#')) {
54+
// Leave links to headings alone
55+
updatedUrl = url;
56+
} else {
57+
// Convert relative paths to '../' (because pages that started as files in the same directory
58+
// get turned into directories themselves, we need to go up a directory in the link)
59+
if (url.startsWith('./')) {
60+
updatedUrl = `.${url}`;
61+
} else if (!url.startsWith('../')) {
62+
updatedUrl = `../${url}`;
63+
} else {
64+
updatedUrl = url;
65+
}
66+
67+
// Relative links to md files should be turned into pages
68+
if (updatedUrl.endsWith('.md')) {
69+
updatedUrl = updatedUrl.replace(/\.md$/, '');
70+
}
71+
}
72+
73+
// Add a trailing / if the link isn't to a file and does not have query params or a hash reference
74+
if (
75+
!updatedUrl.endsWith('/') &&
76+
!/(\.\w+)$/.exec(updatedUrl) &&
77+
!updatedUrl.includes('?') &&
78+
!/#([\w\-]+)$/.exec(updatedUrl)
79+
) {
80+
updatedUrl += '/';
81+
}
82+
83+
return updatedUrl;
84+
};

src/pages/_utils.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -428,42 +428,3 @@ const getUrl = (
428428
return "";
429429
}
430430
};
431-
432-
export const rewriteRelativeLink = (url: string): string => {
433-
let updatedUrl: string;
434-
435-
if (/^((https?:\/)?)\//.exec(url) || url.startsWith('mailto:')) {
436-
// Leave absolute paths alone
437-
updatedUrl = url;
438-
} else if (url.startsWith('#')) {
439-
// Leave links to headings alone
440-
updatedUrl = url;
441-
} else {
442-
// Convert relative paths to '../' (because pages that started as files in the same directory
443-
// get turned into directories themselves, we need to go up a directory in the link)
444-
if (url.startsWith('./')) {
445-
updatedUrl = `.${url}`;
446-
} else if (!url.startsWith('../')) {
447-
updatedUrl = `../${url}`;
448-
} else {
449-
updatedUrl = url;
450-
}
451-
452-
// Relative links to md files should be turned into pages
453-
if (updatedUrl.endsWith('.md')) {
454-
updatedUrl = updatedUrl.replace(/\.md$/, '');
455-
}
456-
}
457-
458-
// Add a trailing / if the link isn't to a file and does not have query params or a hash reference
459-
if (
460-
!updatedUrl.endsWith('/') &&
461-
!/(\.\w+)$/.exec(updatedUrl) &&
462-
!updatedUrl.includes('?') &&
463-
!/#([\w\-]+)$/.exec(updatedUrl)
464-
) {
465-
updatedUrl += '/';
466-
}
467-
468-
return updatedUrl;
469-
};

0 commit comments

Comments
 (0)