Skip to content

Commit

Permalink
🐞 fix(i18n, Link): path.sep & link path
Browse files Browse the repository at this point in the history
1. fix meta_generator cann't read doc type by path.sep.
2. fix Link components cann't use in i18n langurage.
  • Loading branch information
yang-lile committed Nov 19, 2023
1 parent 717e89b commit 2957a31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 9 additions & 9 deletions website/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function decodeDocuments(documents) {
let id = parsedDoc.data.id;
if (!id) {
let pathSplit;
if (docFile.startsWith("docs/")) {
pathSplit = docFile.split("/").slice(1);
} else if (docFile.startsWith("i18n/")) {
pathSplit = docFile.split("/").slice(4);
if (docFile.startsWith(`docs${path.sep}`)) {
pathSplit = docFile.split(path.sep).slice(1);
} else if (docFile.startsWith(`i18n${path.sep}`)) {
pathSplit = docFile.split(path.sep).slice(4);
} else {
throw new Error(`Unknown document type ${docFile}`);
}
Expand Down Expand Up @@ -130,14 +130,14 @@ function decodeDocuments(documents) {
return result;
}

function getCountryCodeForPath(path) {
if (path.startsWith("docs/")) return "en";
function getCountryCodeForPath(docFile) {
if (docFile.startsWith(`docs${path.sep}`)) return "en";

if (!path.startsWith("i18n/")) {
throw new Error(`Unknown path ${path}`);
if (!docFile.startsWith(`i18n${path.sep}`)) {
throw new Error(`Unknown docFile ${docFile}`);
}

return path.split("/")[1];
return docFile.split(path.sep)[1];
}

class OutdatedTranslation {
Expand Down
6 changes: 5 additions & 1 deletion website/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function Link(props: LinkProps) {
? doc.metadata.source.split("/")[2]
: "en";

const prefix = countryCode === "en"
? ""
: `/${countryCode}`;

const docTitle = documentTitles[countryCode][props.documentID];

if (!docTitle) {
Expand All @@ -24,5 +28,5 @@ export function Link(props: LinkProps) {

const trailing = props.hash ? `#${props.hash}` : "";

return <a href={`/docs/${props.documentID}${trailing}`}>{docTitle}</a>;
return <a href={`${prefix}/docs/${props.documentID}${trailing}`}>{docTitle}</a>;
}

0 comments on commit 2957a31

Please sign in to comment.