Skip to content

Commit

Permalink
ファイル名の表示機能を作成
Browse files Browse the repository at this point in the history
  • Loading branch information
nemog9 committed Apr 14, 2023
1 parent 6a62e73 commit ebfedfe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 14 additions & 9 deletions components/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const Code: CodeComponent = ({
...props
}) => {
const match = /language-(\w+)/.exec(className || '');
const matchFileName =
className && className.includes(':') ? className.split(':') : null;
if (match && match.length > 0 && match[1] === 'youtube') {
return (
<div className="youtube-wrap">
Expand All @@ -18,15 +20,18 @@ export const Code: CodeComponent = ({
);
}
return !inline && match ? (
<SyntaxHighlighter
// TODO: ここのエラーを消したい
style={okaidia as any}
language={match[1]}
PreTag="div"
{...props}
w={100}>
{String(children).replace(/\n$/, '')}
</SyntaxHighlighter>
<>
{matchFileName && <span className="file-name">{matchFileName[1]}</span>}
<SyntaxHighlighter
// TODO: ここのエラーを消したい
style={okaidia as any}
language={match[1]}
PreTag="div"
{...props}
w={100}>
{String(children).replace(/\n$/, '')}
</SyntaxHighlighter>
</>
) : (
<code className={className} {...props}>
{children}
Expand Down
11 changes: 11 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ code {
max-width: 680px;
height: auto;
}

.file-name {
background: #167ac6;
color: #fff;
font-size: 1rem;
border-radius: 0.25rem;
padding: 0.5rem;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
margin-bottom: -0.8rem;
display: table;
}

1 comment on commit ebfedfe

@vercel
Copy link

@vercel vercel bot commented on ebfedfe Apr 14, 2023

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:

next-blog – ./

next-blog-git-main-g-nemo9.vercel.app
next-blog-ruby-delta.vercel.app
next-blog-g-nemo9.vercel.app

Please sign in to comment.