-
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
5 changed files
with
187 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
import React, { memo } from 'react' | ||
|
||
import { HighLighter } from '../../ui/code-highlighter' | ||
import { Loading } from '../../ui/loading' | ||
|
||
const ext2FileType = { | ||
'.js': 'javascript', | ||
'.ts': 'typescript', | ||
'.jsx': 'javascript', | ||
'.tsx': 'typescript', | ||
'.md': 'markdown', | ||
'.css': 'css', | ||
'.scss': 'scss', | ||
'.html': 'html', | ||
'.json': 'json', | ||
'.yml': 'yaml', | ||
'.yaml': 'yaml', | ||
'.toml': 'toml', | ||
'.xml': 'xml', | ||
'.sh': 'bash', | ||
'.bash': 'bash', | ||
'.zsh': 'bash', | ||
'.fish': 'bash', | ||
'.ps1': 'powershell', | ||
'.bat': 'batch', | ||
'.cmd': 'batch', | ||
'.go': 'go', | ||
'.py': 'python', | ||
'.rb': 'ruby', | ||
'.java': 'java', | ||
'.c': 'c', | ||
'.cpp': 'cpp', | ||
'.cs': 'csharp', | ||
'.rs': 'rust', | ||
'.swift': 'swift', | ||
'.kt': 'kotlin', | ||
'.clj': 'clojure', | ||
'.lua': 'lua', | ||
'.sql': 'sql', | ||
'.graphql': 'graphql', | ||
'.groovy': 'groovy', | ||
'.scala': 'scala', | ||
'.pl': 'perl', | ||
'.r': 'r', | ||
'.dart': 'dart', | ||
'.elm': 'elm', | ||
'.erl': 'erlang', | ||
'.ex': 'elixir', | ||
'.h': 'c', | ||
'.hpp': 'cpp', | ||
'.hxx': 'cpp', | ||
'.hh': 'cpp', | ||
'.h++': 'cpp', | ||
'.m': 'objectivec', | ||
'.mm': 'objectivec', | ||
'.vue': 'vue', | ||
} | ||
export const EmbedGithubFile = memo( | ||
({ | ||
owner, | ||
path, | ||
repo, | ||
refType, | ||
}: { | ||
owner: string | ||
repo: string | ||
path: string | ||
refType?: string | ||
}) => { | ||
const ext = path.slice(path.lastIndexOf('.')) | ||
const fileType = (ext2FileType as any)[ext] || 'text' | ||
const { data, isLoading, isError } = useQuery<string>({ | ||
queryKey: ['github-preview', owner, repo, path, refType], | ||
queryFn: async () => { | ||
return fetch( | ||
`https://cdn.jsdelivr.net/gh/${owner}/${repo}${ | ||
refType ? `@${refType}` : '' | ||
}/${path}`, | ||
).then(async (res) => { | ||
return res.text() | ||
}) | ||
}, | ||
}) | ||
|
||
if (isLoading) { | ||
return <Loading loadingText="Loading GitHub File Preview..." /> | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<pre className="flex h-[60px] flex-wrap center"> | ||
<code>Loading GitHub File Preview Failed:</code> | ||
<br /> | ||
<code> | ||
{owner}/{repo}/{path} | ||
</code> | ||
</pre> | ||
) | ||
} | ||
|
||
if (!data) return null | ||
|
||
return ( | ||
<div className="h-[50vh] overflow-auto"> | ||
<HighLighter content={data} lang={fileType} /> | ||
</div> | ||
) | ||
}, | ||
) | ||
EmbedGithubFile.displayName = 'EmbedGithubFile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e672da5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shiro – ./
shiro-git-main-innei.vercel.app
shiro-innei.vercel.app
springtide.vercel.app
innei.in