Skip to content

Commit

Permalink
fix: #12, #9
Browse files Browse the repository at this point in the history
  • Loading branch information
hehehai committed Jun 10, 2022
1 parent 91eb8fa commit 0df4481
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/DetailList.svelte
@@ -1,7 +1,16 @@
<script lang="ts">
import { CARGO_TOML_FILE } from '~/logic';
export let title = '';
export let repoBlobPath: string | undefined = undefined;
export let workspaces: string[] = [];
const mergeWorkspacePath = (workspacePath: string) => {
return `${repoBlobPath}${
workspacePath === '.' ? '' : workspacePath + '/'
}${CARGO_TOML_FILE}`;
};
$: total = workspaces.length;
</script>

Expand Down Expand Up @@ -29,7 +38,7 @@
d="M8.878.392a1.75 1.75 0 00-1.756 0l-5.25 3.045A1.75 1.75 0 001 4.951v6.098c0 .624.332 1.2.872 1.514l5.25 3.045a1.75 1.75 0 001.756 0l5.25-3.045c.54-.313.872-.89.872-1.514V4.951c0-.624-.332-1.2-.872-1.514L8.878.392zM7.875 1.69a.25.25 0 01.25 0l4.63 2.685L8 7.133 3.245 4.375l4.63-2.685zM2.5 5.677v5.372c0 .09.047.171.125.216l4.625 2.683V8.432L2.5 5.677zm6.25 8.271l4.625-2.683a.25.25 0 00.125-.216V5.677L8.75 8.432v5.516z"
/>
</svg>
<a href={workspace} rel="nofollow">
<a href={mergeWorkspacePath(workspace)} rel="nofollow">
<span class="px-2 text-bold">
{workspace}
</span>
Expand Down
6 changes: 5 additions & 1 deletion src/contentScripts/index.ts
Expand Up @@ -2,11 +2,12 @@ import elementReady from 'element-ready';
import { gitHubInjection } from '~/util/github-injection';
import Deps from './views/Deps.svelte';
import Crate from './views/Crate.svelte';
import { getCargoJson, getCargoTomlURL, hasCargoToml, isCargoToml } from '~/logic/cargo-toml';
import { getCargoJson, getCargoTomlURL, getRepoBlobPath, hasCargoToml, isCargoToml } from '~/logic/cargo-toml';

interface InitProps {
isCargoToml: boolean;
cargoTomlURL?: string;
repoBlobPath?: string;
cargoData?: any;
}

Expand All @@ -30,6 +31,7 @@ const initCrate = async (props: InitProps) => {

new Crate({
props: {
repoBlobPath: props.repoBlobPath,
cargoData: props.cargoData,
},
target
Expand Down Expand Up @@ -60,6 +62,7 @@ const init = async () => {
}

const cargoTomlURL = getCargoTomlURL()
const repoBlobPath = cargoTomlURL ? getRepoBlobPath(cargoTomlURL) : undefined;
const cargoData = await getCargoJson(isCargoTomlVal, cargoTomlURL);

if (!cargoData) {
Expand All @@ -69,6 +72,7 @@ const init = async () => {
const props = {
isCargoToml: isCargoTomlVal,
cargoTomlURL: cargoTomlURL,
repoBlobPath,
cargoData,
}

Expand Down
2 changes: 2 additions & 0 deletions src/contentScripts/views/Crate.svelte
Expand Up @@ -9,6 +9,7 @@
import { sizeFormat } from '~/util/size';
export let cargoData: any;
export let repoBlobPath: string | undefined = undefined
let crateInfo: CrateDetailVO | undefined;
let loading = false;
Expand Down Expand Up @@ -64,6 +65,7 @@
{#if cargoData?.workspace?.members?.length}
<DetailList
title="WorkSpaces"
{repoBlobPath}
workspaces={cargoData?.workspace?.members}
/>
{/if}
Expand Down
5 changes: 5 additions & 0 deletions src/logic/cargo-toml.ts
Expand Up @@ -28,6 +28,11 @@ export function tomlToJson(tomlData: string) {
return toml.parse(tomlData);
}

// https://github.com/zellij-org/zellij/blob/bg-and-fg-color-ansi/Cargo.toml
export function getRepoBlobPath(link: string): string | undefined {
return (link.match(/.+blob\/.+\//) || [])[0];
}

export async function getCargoJson(isCargoToml: boolean, cargoTomlURL?: string) {
const codeDoc = isCargoToml ? document : cargoTomlURL ? await fetchDom(cargoTomlURL) : null;
if (codeDoc) {
Expand Down

0 comments on commit 0df4481

Please sign in to comment.