Skip to content

Commit

Permalink
😅 code highlight modified
Browse files Browse the repository at this point in the history
  • Loading branch information
yuancong-liu committed May 9, 2024
1 parent 6156ca6 commit 0b41f81
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/components/pages/blog/postContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { PostPre } from '../postParts/postPre';
import { PostTable } from '../postParts/postTable';
import { PostToc } from '../postParts/postToc';

import 'highlight.js/styles/github-dark-dimmed.min.css';
import styles from './index.module.scss';

type Props = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/pages/blog/postParts/postToc/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
height: 24px;
}

> svg > path {
fill: var(--color-tmp-name-5);
}

@include pc {
display: none;
}
Expand Down
14 changes: 13 additions & 1 deletion src/components/pages/blog/postParts/postToc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ import { useGSAP } from '@gsap/react';
import classNames from 'classnames';
import gsap from 'gsap';

import { useColorSchemeContext } from '~/contexts/colorSchemeContext';
import { useDeviceDetect } from '~/hooks';

import styles from './index.module.scss';

type Props = ComponentProps<'nav'>;

export const PostToc = ({ className, children }: Props) => {
// I have nowhere to put this code, so I'll just leave it here.
const { colorScheme } = useColorSchemeContext();

useEffect(() => {
if (colorScheme === 'dark') {
import('highlight.js/styles/github-dark-dimmed.min.css'!);
} else {
import('highlight.js/styles/github.min.css'!);
}
}, [colorScheme]);

const [tocOpen, setTocOpen] = useState(false);
const tocRef = useRef<HTMLDivElement>(null);
const { isPc } = useDeviceDetect();
Expand Down Expand Up @@ -49,7 +61,7 @@ export const PostToc = ({ className, children }: Props) => {
}, [isPc]);

const toggleToc = contextSafe(() => {
if (tocOpen) {
if (tocOpen && !isPc) {
gsap.to('.top', { rotate: 0, translateY: 0, scale: 1 });
gsap.to('.middle', { opacity: 1 });
gsap.to('.bottom', { rotate: 0, translateY: 0, scale: 1 });
Expand Down

0 comments on commit 0b41f81

Please sign in to comment.