mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
website: update swizzled items
This commit is contained in:
@ -10,9 +10,10 @@ import {
|
|||||||
useThemeConfig,
|
useThemeConfig,
|
||||||
useAnnouncementBar,
|
useAnnouncementBar,
|
||||||
MobileSecondaryMenuFiller,
|
MobileSecondaryMenuFiller,
|
||||||
|
ThemeClassNames,
|
||||||
|
useScrollPosition,
|
||||||
} from '@docusaurus/theme-common';
|
} from '@docusaurus/theme-common';
|
||||||
import useWindowSize from '@theme/hooks/useWindowSize';
|
import useWindowSize from '@theme/hooks/useWindowSize';
|
||||||
import useScrollPosition from '@theme/hooks/useScrollPosition';
|
|
||||||
import Logo from '@theme/Logo';
|
import Logo from '@theme/Logo';
|
||||||
import IconArrow from '@theme/IconArrow';
|
import IconArrow from '@theme/IconArrow';
|
||||||
import {translate} from '@docusaurus/Translate';
|
import {translate} from '@docusaurus/Translate';
|
||||||
@ -21,14 +22,17 @@ import styles from './styles.module.css';
|
|||||||
import SidebarAd from '../../components/SidebarAd';
|
import SidebarAd from '../../components/SidebarAd';
|
||||||
|
|
||||||
function useShowAnnouncementBar() {
|
function useShowAnnouncementBar() {
|
||||||
const {isClosed} = useAnnouncementBar();
|
const {isActive} = useAnnouncementBar();
|
||||||
const [showAnnouncementBar, setShowAnnouncementBar] = useState(!isClosed);
|
const [showAnnouncementBar, setShowAnnouncementBar] = useState(isActive);
|
||||||
useScrollPosition(({scrollY}) => {
|
useScrollPosition(
|
||||||
if (!isClosed) {
|
({scrollY}) => {
|
||||||
setShowAnnouncementBar(scrollY === 0);
|
if (isActive) {
|
||||||
}
|
setShowAnnouncementBar(scrollY === 0);
|
||||||
});
|
}
|
||||||
return showAnnouncementBar;
|
},
|
||||||
|
[isActive],
|
||||||
|
);
|
||||||
|
return isActive && showAnnouncementBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
function HideableSidebarButton({onClick}) {
|
function HideableSidebarButton({onClick}) {
|
||||||
@ -61,7 +65,6 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
|||||||
navbar: {hideOnScroll},
|
navbar: {hideOnScroll},
|
||||||
hideableSidebar,
|
hideableSidebar,
|
||||||
} = useThemeConfig();
|
} = useThemeConfig();
|
||||||
const {isClosed: isAnnouncementBarClosed} = useAnnouncementBar();
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clsx(styles.sidebar, {
|
className={clsx(styles.sidebar, {
|
||||||
@ -71,11 +74,10 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
|||||||
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
|
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
|
||||||
<nav
|
<nav
|
||||||
className={clsx('menu thin-scrollbar', styles.menu, {
|
className={clsx('menu thin-scrollbar', styles.menu, {
|
||||||
[styles.menuWithAnnouncementBar]:
|
[styles.menuWithAnnouncementBar]: showAnnouncementBar,
|
||||||
!isAnnouncementBarClosed && showAnnouncementBar,
|
|
||||||
})}>
|
})}>
|
||||||
<ul className="menu__list">
|
<ul className={clsx(ThemeClassNames.docs.docSidebarMenu, 'menu__list')}>
|
||||||
<DocSidebarItems items={sidebar} activePath={path} />
|
<DocSidebarItems items={sidebar} activePath={path} level={1} />
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
{hideableSidebar && <HideableSidebarButton onClick={onCollapse} />}
|
{hideableSidebar && <HideableSidebarButton onClick={onCollapse} />}
|
||||||
@ -85,11 +87,12 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
|||||||
|
|
||||||
const DocSidebarMobileSecondaryMenu = ({toggleSidebar, sidebar, path}) => {
|
const DocSidebarMobileSecondaryMenu = ({toggleSidebar, sidebar, path}) => {
|
||||||
return (
|
return (
|
||||||
<ul className="menu__list">
|
<ul className={clsx(ThemeClassNames.docs.docSidebarMenu, 'menu__list')}>
|
||||||
<DocSidebarItems
|
<DocSidebarItems
|
||||||
items={sidebar}
|
items={sidebar}
|
||||||
activePath={path}
|
activePath={path}
|
||||||
onItemClick={() => toggleSidebar()}
|
onItemClick={() => toggleSidebar()}
|
||||||
|
level={1}
|
||||||
/>
|
/>
|
||||||
<div className="margin--md">
|
<div className="margin--md">
|
||||||
<SidebarAd />
|
<SidebarAd />
|
||||||
|
@ -11,7 +11,9 @@ import {
|
|||||||
usePrevious,
|
usePrevious,
|
||||||
Collapsible,
|
Collapsible,
|
||||||
useCollapsible,
|
useCollapsible,
|
||||||
|
ThemeClassNames,
|
||||||
} from '@docusaurus/theme-common';
|
} from '@docusaurus/theme-common';
|
||||||
|
import Link from '@docusaurus/Link';
|
||||||
import isInternalUrl from '@docusaurus/isInternalUrl';
|
import isInternalUrl from '@docusaurus/isInternalUrl';
|
||||||
import IconExternalLink from '@theme/IconExternalLink';
|
import IconExternalLink from '@theme/IconExternalLink';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
@ -74,8 +76,14 @@ function useAutoExpandActiveCategory({isActive, collapsed, setCollapsed}) {
|
|||||||
}, [isActive, wasActive, collapsed]);
|
}, [isActive, wasActive, collapsed]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DocSidebarItemCategory({item, onItemClick, activePath, ...props}) {
|
function DocSidebarItemCategory({
|
||||||
const {items, label, collapsible} = item;
|
item,
|
||||||
|
onItemClick,
|
||||||
|
activePath,
|
||||||
|
level,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
const {items, label, collapsible, className} = item;
|
||||||
const isActive = isActiveSidebarItem(item, activePath);
|
const isActive = isActiveSidebarItem(item, activePath);
|
||||||
const {collapsed, setCollapsed, toggleCollapsed} = useCollapsible({
|
const {collapsed, setCollapsed, toggleCollapsed} = useCollapsible({
|
||||||
// active categories are always initialized as expanded
|
// active categories are always initialized as expanded
|
||||||
@ -95,9 +103,15 @@ function DocSidebarItemCategory({item, onItemClick, activePath, ...props}) {
|
|||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
className={clsx('menu__list-item', {
|
className={clsx(
|
||||||
'menu__list-item--collapsed': collapsed,
|
ThemeClassNames.docs.docSidebarItemCategory,
|
||||||
})}>
|
ThemeClassNames.docs.docSidebarItemCategoryLevel(level),
|
||||||
|
'menu__list-item',
|
||||||
|
{
|
||||||
|
'menu__list-item--collapsed': collapsed,
|
||||||
|
},
|
||||||
|
className,
|
||||||
|
)}>
|
||||||
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
||||||
<a
|
<a
|
||||||
className={clsx('menu__link', {
|
className={clsx('menu__link', {
|
||||||
@ -124,22 +138,34 @@ function DocSidebarItemCategory({item, onItemClick, activePath, ...props}) {
|
|||||||
tabIndex={collapsed ? -1 : 0}
|
tabIndex={collapsed ? -1 : 0}
|
||||||
onItemClick={onItemClick}
|
onItemClick={onItemClick}
|
||||||
activePath={activePath}
|
activePath={activePath}
|
||||||
|
level={level + 1}
|
||||||
/>
|
/>
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DocSidebarItemLink({item, onItemClick, activePath, ...props}) {
|
function DocSidebarItemLink({item, onItemClick, activePath, level, ...props}) {
|
||||||
const {href, label} = item;
|
const {href, label, className} = item;
|
||||||
const isActive = isActiveSidebarItem(item, activePath);
|
const isActive = isActiveSidebarItem(item, activePath);
|
||||||
return (
|
return (
|
||||||
<li className="menu__list-item" key={label}>
|
<li
|
||||||
|
className={clsx(
|
||||||
|
ThemeClassNames.docs.docSidebarItemLink,
|
||||||
|
ThemeClassNames.docs.docSidebarItemLinkLevel(level),
|
||||||
|
'menu__list-item',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
key={label}>
|
||||||
<a
|
<a
|
||||||
className={clsx('menu__link', {
|
className={clsx('menu__link', {
|
||||||
'menu__link--active': isActive,
|
'menu__link--active': isActive,
|
||||||
})}
|
})}
|
||||||
|
aria-current={isActive ? 'page' : undefined}
|
||||||
href={href}
|
href={href}
|
||||||
|
{...(isInternalUrl(href) && {
|
||||||
|
onClick: onItemClick,
|
||||||
|
})}
|
||||||
{...props}>
|
{...props}>
|
||||||
{isInternalUrl(href) ? (
|
{isInternalUrl(href) ? (
|
||||||
label
|
label
|
||||||
|
@ -6,50 +6,25 @@
|
|||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import useTOCHighlight from '@theme/hooks/useTOCHighlight';
|
import TOCItems from '@theme/TOCItems';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css'; // Using a custom className
|
||||||
import SidebarAd from '../../components/SidebarAd';
|
import SidebarAd from '../../components/SidebarAd';
|
||||||
|
// This prevents TOC highlighting to highlight TOCInline/TOCCollapsible by mistake
|
||||||
|
|
||||||
const LINK_CLASS_NAME = 'table-of-contents__link';
|
const LINK_CLASS_NAME = 'table-of-contents__link toc-highlight';
|
||||||
const ACTIVE_LINK_CLASS_NAME = 'table-of-contents__link--active';
|
const LINK_ACTIVE_CLASS_NAME = 'table-of-contents__link--active';
|
||||||
const TOP_OFFSET = 100;
|
|
||||||
/* eslint-disable jsx-a11y/control-has-associated-label */
|
|
||||||
|
|
||||||
export function TOCHeadings({toc, isChild}) {
|
|
||||||
if (!toc.length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function TOC({className, ...props}) {
|
||||||
return (
|
return (
|
||||||
<ul
|
<div className={clsx(styles.tableOfContents, 'thin-scrollbar', className)}>
|
||||||
className={
|
|
||||||
isChild ? '' : 'table-of-contents table-of-contents__left-border'
|
|
||||||
}>
|
|
||||||
{toc.map((heading) => (
|
|
||||||
<li key={heading.id}>
|
|
||||||
<a
|
|
||||||
href={`#${heading.id}`}
|
|
||||||
className={LINK_CLASS_NAME} // Developer provided the HTML, so assume it's safe.
|
|
||||||
// eslint-disable-next-line react/no-danger
|
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: heading.value,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<TOCHeadings isChild toc={heading.children} />
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function TOC({toc}) {
|
|
||||||
useTOCHighlight(LINK_CLASS_NAME, ACTIVE_LINK_CLASS_NAME, TOP_OFFSET);
|
|
||||||
return (
|
|
||||||
<div className={clsx(styles.tableOfContents, 'thin-scrollbar')}>
|
|
||||||
<div className="margin--md">
|
<div className="margin--md">
|
||||||
<SidebarAd />
|
<SidebarAd />
|
||||||
</div>
|
</div>
|
||||||
<TOCHeadings toc={toc} />
|
<TOCItems
|
||||||
|
{...props}
|
||||||
|
linkClassName={LINK_CLASS_NAME}
|
||||||
|
linkActiveClassName={LINK_ACTIVE_CLASS_NAME}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
top: calc(var(--ifm-navbar-height) + 1rem);
|
top: calc(var(--ifm-navbar-height) + 1rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 996px) {
|
@media (max-width: 996px) {
|
||||||
.tableOfContents {
|
.tableOfContents {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user