Skip to content

Commit

Permalink
chore(sync): Sync blog source code to next-theme-coline
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 28, 2024
1 parent f2ca16e commit 5c3ee3a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 49 deletions.
8 changes: 6 additions & 2 deletions src/components/templates/template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export const Template: React.FC<TemplateProps> = async (props) => {
<Main>
{props.before}
<Title title={props.name}>{props.desc}</Title>
<article>{props.children}</article>
<section style={{ position: "relative" }}>
{props.headings && <Toc data={props.headings} />}
<article>
{props.children}
</article>
</section>
{props.after}
{props.headings && <Toc data={props.headings} />}
{(props.pagination?.prev || props.pagination?.next) && (
<TwoPagination prev={props.pagination.prev} next={props.pagination.next} />
)}
Expand Down
46 changes: 21 additions & 25 deletions src/components/ui/link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import React, { AnchorHTMLAttributes, forwardRef } from "react";
import React, { AnchorHTMLAttributes, ReactElement, forwardRef } from "react";
import Tippy, { TippyProps } from "@tippyjs/react";
import NLink, { LinkProps as NLinkProps } from "next/link";
import { cx } from "@syfxlin/reve";
Expand All @@ -11,29 +11,25 @@ export type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & NLinkProps & {
};

export const Link = forwardRef<HTMLAnchorElement, LinkProps>(({ tooltip, unstyled, href, ...props }, ref) => {
if (typeof href === "string" && /^(https?:)?\/\/|^#|\.[\da-z]+$/i.test(href)) {
const element = <a target="_blank" rel="nofollow noopener noreferrer" {...props} className={cx(props.className, !unstyled && styles.link)} href={href} ref={ref} />;
return tooltip ?
(
<Tippy animation="shift-away" content={props["aria-label"]} {...(typeof tooltip === "boolean" ? {} : tooltip)}>
{element}
</Tippy>
) :
(
element
);
} else {
const element = (
<NLink {...props} className={cx(props.className, !unstyled && styles.link)} href={href} ref={ref} />
);
return tooltip ?
(
<Tippy animation="shift-away" content={props["aria-label"]} {...(typeof tooltip === "boolean" ? {} : tooltip)}>
{element}
</Tippy>
) :
(
element
);
let element: ReactElement | undefined;
if (typeof href === "string") {
if (/^(https?:)?\/\/|\.[\da-z]+$/i.test(href)) {
element = <a target="_blank" rel="nofollow noopener noreferrer" {...props} className={cx(props.className, !unstyled && styles.link)} href={href} ref={ref} />;
}
if (/^#/i.test(href)) {
element = <a {...props} className={cx(props.className, !unstyled && styles.link)} href={href} ref={ref} />;
}
}
if (!element) {
element = <NLink {...props} className={cx(props.className, !unstyled && styles.link)} href={href} ref={ref} />;
}
return tooltip ?
(
<Tippy animation="shift-away" content={props["aria-label"]} {...(typeof tooltip === "boolean" ? {} : tooltip)}>
{element}
</Tippy>
) :
(
element
);
});
6 changes: 2 additions & 4 deletions src/components/widgets/toc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use client";
import React, { useState } from "react";
import { cx } from "@syfxlin/reve";
import { TocData } from "@syfxlin/reks";
import { useIntersectionObserver } from "../../../hooks/use-intersection-observer";
import { TocData } from "../../../contents/types";
import { Link } from "../../ui/link";
import { Iconify } from "../../ui/iconify/client";
import * as styles from "./styles.css";

export interface TocProps {
Expand All @@ -21,7 +20,7 @@ const Item: React.FC<TocProps & { active: string }> = ({ data, active }) => {
{data.map(i => (
<li key={`toc-${i.slug}`} id={`toc-${i.slug}`} className={styles.item}>
<Link className={cx(i.slug === active && "active")} href={`#${i.slug}`} aria-label={i.name}>
{i.name}
- {i.name}
</Link>
{i.children && <Item data={i.children} active={active} />}
</li>
Expand All @@ -37,7 +36,6 @@ export const Toc: React.FC<TocProps> = ({ data }) => {

return (
<aside className={styles.container}>
<Iconify icon={styles.icon} />
<Item data={data} active={active} />
</aside>
);
Expand Down
31 changes: 13 additions & 18 deletions src/components/widgets/toc/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ import { theme } from "../../../theme/theme.css";
import { iconify } from "../../ui/iconify/query";

export const container = styled.css`
position: fixed;
top: 80px;
left: ${theme.fontSize.calc(1)};
position: absolute;
top: 0;
right: ${theme.fontSize.calc(-1)};
padding: ${theme.spacing.calc(1)};
width: ${theme.fontSize.calc(18)};
height: calc(100vh - 160px);
height: 100%;
transform: translateX(100%);
@media screen and (max-width: ${theme.fontSize.calc(36 + 45)}) {
display: none;
}
> ul {
position: sticky;
top: 40px;
margin: 0;
padding: 0;
height: 100%;
overflow-y: auto;
opacity: 0;
transition: opacity 0.6s;
}
> span {
opacity: 0.5;
overflow-y: auto;
overflow-x: hidden;
transition: opacity 0.6s;
}
&:hover {
> ul,
> span {
> ul {
opacity: 1;
}
}
Expand Down Expand Up @@ -63,16 +60,14 @@ export const item = styled.css`
font-size: ${theme.fontSize.calc(0.9)};
margin: 0 ${theme.spacing.calc(2.5)};
color: ${theme.color.text.description};
transition:
color 0.3s,
border 0.3s;
border: none;
transition: color 0.3s;
&.active,
&:hover,
&:focus,
&:active {
color: ${theme.color.text.paragraph};
border-bottom-color: ${theme.color.text.paragraph};
color: ${theme.color.text.primary};
}
}
`;

0 comments on commit 5c3ee3a

Please sign in to comment.