Skip to content

Commit

Permalink
Relative links
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-bodnar committed Jul 21, 2023
1 parent b861b92 commit df0aa46
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
11 changes: 9 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import AdmZip from 'adm-zip';
import axios from 'axios';
import {toPlatformPath} from '@actions/core';
Expand All @@ -19,8 +20,12 @@ const downloadZipAndUnzip = async (zipUrl: string, destination: string): Promise
return entries;
};

const generateRelativeFileLink = (currentFilePath: string, destinationFilePath: string): string => {
return path.relative(path.dirname(currentFilePath), destinationFilePath);
};

const baseName = (filePath: string): string => {
return filePath.split('/').pop() || filePath;
};

export {downloadZipAndUnzip, baseName};
export {downloadZipAndUnzip, generateRelativeFileLink, baseName};
5 changes: 4 additions & 1 deletion src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Logger} from './logger';
import {Config, CredentialsConfig} from './config';
import {toPlatformPath} from '@actions/core';
import {LanguagesModel} from '@crowdin/crowdin-api-client/out/languages';
import {generateRelativeFileLink} from './utils';

export class Writer {
private placeholderStart = '<!-- README-TRANSLATE-LANGUAGES-START -->';
Expand Down Expand Up @@ -61,7 +62,9 @@ export class Writer {
let languages: string[] = [];

this.projectLanguages.map(language => {
languages.push(`[${language.name}](${this.config.destination}/README.${language.locale}.md)`);
const link = `${this.config.destination}/README.${language.locale}.md`;

languages.push(`[${language.name}](${generateRelativeFileLink(this.config.file, link)}))}`);
});

return languages.join(' | ');
Expand Down

0 comments on commit df0aa46

Please sign in to comment.