Skip to content

Commit

Permalink
fix: adjust anchor position
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Sep 24, 2022
1 parent 86f63ca commit 2ae34ee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/api/config-theme.md
Expand Up @@ -264,7 +264,7 @@ export default defineConfig({
});
```

> In current version(v0.1.5), the `icon` only supports `github`.
> In current version(v0.1.7), the `icon` only supports `github`.
## outlineTitle

Expand Down
8 changes: 4 additions & 4 deletions src/runtime/sideEffects.ts
Expand Up @@ -51,21 +51,21 @@ if (inBrowser()) {
pathname === currentUrl.pathname &&
search === currentUrl.search &&
hash &&
hash !== currentUrl.hash
hash !== currentUrl.hash &&
link.classList.contains('header-anchor')
) {
e.preventDefault();
history.pushState(null, '', hash);
// use smooth scroll when clicking on header anchor links
scrollTo(link, hash, true);
// still emit the event so we can listen to it in themes
window.dispatchEvent(new Event('hashchange'));
// use smooth scroll when clicking on header anchor links
scrollTo(link, hash, link.classList.contains('header-anchor'));
}
}
}
},
{ capture: true }
);

window.addEventListener('hashchange', (e) => {
e.preventDefault();
});
Expand Down
4 changes: 2 additions & 2 deletions src/shared/types/type.d.ts
Expand Up @@ -23,10 +23,10 @@ declare module 'island:site-data' {


declare module 'island/client' {
import { ComponentType } from 'react';
import { ComponentType, ReactElement } from 'react';
import { PageData, SiteData } from 'shared/types';

export const Content: ComponentType<unknown>;
export const Content: ComponentType<{ fallback?: ReactElement }>;
export const usePageData: () => PageData;
export const DataContext: React.Context<{
data: PageData;
Expand Down
1 change: 0 additions & 1 deletion src/theme-default/logic/useAsideAnchor.ts
Expand Up @@ -104,7 +104,6 @@ export function useAsideAnchor(
() => {
if (markerRef.current) {
markerRef.current.style.opacity = '0';
window.scrollTo(0, 0);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
17 changes: 15 additions & 2 deletions src/theme-default/styles/doc.css
Expand Up @@ -13,6 +13,20 @@
outline: none;
}

.island-doc h1::before,
.island-doc h2::before,
.island-doc h3::before,
.island-doc h4::before,
.island-doc h5::before,
.island-doc h6::before {
display: block;
content: '';
margin-top: -72px;
height: 72px;
visibility: hidden;
pointer-events: none;
}

.island-doc h1 {
letter-spacing: -0.02em;
line-height: 40px;
Expand All @@ -22,8 +36,7 @@

.island-doc h2 {
margin: 48px 0 16px;
border-top: 1px solid var(--island-c-divider-light);
padding-top: 24px;
/* padding-top: 24px; */
letter-spacing: -0.02em;
line-height: 32px;
font-size: 24px;
Expand Down

0 comments on commit 2ae34ee

Please sign in to comment.