Skip to content

Commit

Permalink
refactor(libs): extract getRepositoryUrlByLocale()
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Oct 31, 2024
1 parent 5f37f0c commit 45196cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 4 additions & 6 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
postProcessSmallerHeadingIDs,
} from "./utils.js";
import { addBaseline } from "./web-features.js";
import { getRepositoryByLocale } from "../libs/locale-utils/index.js";
import { getRepositoryUrlByLocale } from "../libs/locale-utils/index.js";

Check failure on line 47 in build/index.ts

View workflow job for this annotation

GitHub Actions / lint

'"../libs/locale-utils/index.js"' has no exported member named 'getRepositoryUrlByLocale'. Did you mean 'getRepositoryByLocale'?
export { default as SearchIndex } from "./search-index.js";
export { gather as gatherGitHistory } from "./git-history.js";
export { buildSPAs } from "./spas.js";
Expand Down Expand Up @@ -132,11 +132,10 @@ function injectNotecardOnWarnings($: cheerio.CheerioAPI) {
/**
* Return the full URL directly to the file in GitHub based on this folder.
* @param {String} folder - the current folder we're processing.
*/
*/ r;

Check failure on line 135 in build/index.ts

View workflow job for this annotation

GitHub Actions / lint

Cannot find name 'r'.
function getGitHubURL(root: string, folder: string, filename: string) {
const [locale] = folder.split("/", 2);
const repo = getRepositoryByLocale(locale);
const baseURL = `https://github.com/mdn/${repo}`;
const baseURL = getRepositoryUrlByLocale(locale);

return `${baseURL}/blob/${getCurrentGitBranch(
root
Expand All @@ -148,8 +147,7 @@ function getGitHubURL(root: string, folder: string, filename: string) {
* @param {String} hash - the full hash to point to.
*/
export function getLastCommitURL(locale: string, hash: string) {
const repo = getRepositoryByLocale(locale);
const baseURL = `https://github.com/mdn/${repo}`;
const baseURL = getRepositoryUrlByLocale(locale);
return `${baseURL}/commit/${hash}`;
}

Expand Down
7 changes: 7 additions & 0 deletions libs/locale-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export function isValidLocale(locale) {
return typeof locale === "string" && VALID_LOCALES.has(locale.toLowerCase());
}

export function getRepositoryUrlByLocale(locale) {
const repo = getRepositoryByLocale(locale);
const url = `https://github.com/mdn/${repo}`;

return url;
}

export function getRepositoryByLocale(locale) {
switch (locale.toLowerCase()) {
case "en-us":
Expand Down

0 comments on commit 45196cb

Please sign in to comment.