Skip to content

Commit 54a0b31

Browse files
show user-friendly github.com urls for tabular data resources (#104)
and rewrite them back to raw github user conent url for loading data from github repositories into table view.
1 parent 1854b53 commit 54a0b31

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/commands/listDataResources.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ async function listDataResources(dataPackageUri: Uri): Promise<void> {
4040
const dataResources: Array<QuickPickItem> = [];
4141
dataPackage.resources.forEach((resource: any) => {
4242
if (resource.tabular) { // supportedDataFormats.includes(resource.descriptor.format)) {
43-
const dataRepositoryUrl: string = ''; // `https://github.com/${dataPackage.user}/${dataPackage.repo}`;
4443
dataResources.push({
4544
label: `$(table) ${resource.name}`,
4645
description: dataPackage.title,
47-
detail: resource.source
46+
detail: fileUtils.convertToGitHubRepositoryUrl(resource.source)
4847
});
4948
}
5049
});
@@ -56,7 +55,7 @@ async function listDataResources(dataPackageUri: Uri): Promise<void> {
5655
let dataResourceUrl: string | undefined = selectedDataResource.detail;
5756
if (dataResourceUrl) {
5857
// create tabular data resource Uri and display a table view
59-
const dataResourceUri: Uri = Uri.parse(dataResourceUrl);
58+
const dataResourceUri: Uri = Uri.parse(fileUtils.convertToGitHubContentUrl(dataResourceUrl));
6059
commands.executeCommand(ViewCommands.viewTable, dataResourceUri);
6160
}
6261
}

src/utils/fileUtils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ export function convertToGitHubContentUrl(dataFileUrl: string): string {
3333
return gitHubContentUrl;
3434
}
3535

36+
/**
37+
* Converts github content url to user friendly github repository url for display
38+
* and linking to external public data sources hosted on github.
39+
*
40+
* @param dataFileUrl Github content data file url from a github repository.
41+
* @returns User friendly github data file url for display, linking and copy/paste in a browser.
42+
*/
43+
export function convertToGitHubRepositoryUrl(dataFileUrl: string): string {
44+
let gitHubContentUrl: string = dataFileUrl;
45+
if (dataFileUrl.startsWith('https://raw.githubusercontent.com/')) {
46+
// rewrite github content url to use github repository url for display
47+
gitHubContentUrl = dataFileUrl.replace('https://raw.githubusercontent.com/', 'https://github.com/');
48+
49+
// add blob part
50+
gitHubContentUrl = gitHubContentUrl.replace('/main/', '/blob/main/');
51+
gitHubContentUrl = gitHubContentUrl.replace('/master/', '/blob/master/');
52+
}
53+
return gitHubContentUrl;
54+
}
55+
3656
/**
3757
* Gets file name path token from a document Uri.
3858
*

0 commit comments

Comments
 (0)