Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes july #198

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,14 @@ html[data-theme="dark"] .dropdown-version .navbar__item--version:before {

/* hash link */
.hash-link::before {
content: none !important;
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='size-6'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244' /%3E%3C/svg%3E%0A") !important;
width: 1.5rem;
height: 1.5rem;
display: inline-block;
opacity: 0.5;
}
.hash-link:hover::before {
opacity: 1;
}

/* doc search */
Expand Down
18 changes: 10 additions & 8 deletions src/theme/EditThisPage/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React from 'react';
import Translate from '@docusaurus/Translate';
import {ThemeClassNames} from '@docusaurus/theme-common';
import IconEdit from '@theme/Icon/Edit';
export default function EditThisPage({editUrl}) {
import React from "react";
import Translate from "@docusaurus/Translate";
import { ThemeClassNames } from "@docusaurus/theme-common";
import IconEdit from "@theme/Icon/Edit";
export default function EditThisPage({ editUrl }) {
return (
<a
href={editUrl}
target="_blank"
rel="noreferrer noopener"
className={ThemeClassNames.common.editThisPage}>
className={ThemeClassNames.common.editThisPage}
>
<IconEdit />
<Translate
id="theme.common.editThisPage"
description="The link label to edit the current page">
Edit this page
description="The link label to edit the current page"
>
Report an error
</Translate>
</a>
);
Expand Down
63 changes: 63 additions & 0 deletions src/theme/Heading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react";
import clsx from "clsx";
import { translate } from "@docusaurus/Translate";
import { useThemeConfig } from "@docusaurus/theme-common";
import Link from "@docusaurus/Link";
import styles from "./styles.module.css";
export default function Heading({ as: As, id, ...props }) {
const {
navbar: { hideOnScroll },
} = useThemeConfig();
// H1 headings do not need an id because they don't appear in the TOC.
if (As === "h1" || !id) {
return <As {...props} id={undefined} />;
}
const anchorTitle = translate(
{
id: "theme.common.headingLinkTitle",
message: "Direct link to {heading}",
description: "Title for link to heading",
},
{
heading: typeof props.children === "string" ? props.children : id,
}
);

const copyToClipboard = (e) => {
e.preventDefault();
navigator.clipboard.writeText(e.target.href);
};

const onClick = (e) => {
e.preventDefault();
console.log("click");
copyToClipboard(e);
};

return (
<>
<As
{...props}
className={clsx(
"anchor",
hideOnScroll
? styles.anchorWithHideOnScrollNavbar
: styles.anchorWithStickyNavbar,
props.className
)}
id={id}
>
{props.children}
<Link
className="hash-link"
to={`#${id}`}
aria-label={anchorTitle}
title={anchorTitle}
onClick={onClick}
>
&#8203;
</Link>
</As>
</>
);
}
28 changes: 28 additions & 0 deletions src/theme/Heading/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
When the navbar is sticky, ensure that on anchor click,
the browser does not scroll that anchor behind the navbar
See https://twitter.com/JoshWComeau/status/1332015868725891076
*/
.anchorWithStickyNavbar {
scroll-margin-top: calc(var(--ifm-navbar-height) + 0.5rem);
}

.anchorWithHideOnScrollNavbar {
scroll-margin-top: 0.5rem;
}

:global(.hash-link) {
opacity: 0;
padding-left: 0.5rem;
transition: opacity var(--ifm-transition-fast);
user-select: none;
}

:global(.hash-link::before) {
content: '#';
}

:global(.hash-link:focus),
:global(*:hover > .hash-link) {
opacity: 1;
}
Loading