Skip to content

Commit

Permalink
feat: 超链接统一增加 label 属性
Browse files Browse the repository at this point in the history
  • Loading branch information
wujieli0207 committed May 6, 2024
1 parent 070996c commit 6f3f131
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function Home({ posts }: { posts: CoreContent<Blog>[] }) {
<h2 className="text-2xl font-bold leading-8 tracking-tight">
<Link
href={`/blog/${slug}`}
title={title}
className="text-gray-900 dark:text-gray-100"
>
{title}
Expand All @@ -70,6 +71,7 @@ export default function Home({ posts }: { posts: CoreContent<Blog>[] }) {
href={`/blog/${slug}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Read more: "${title}"`}
title={`Read more: "${title}"`}
>
Read more &rarr;
</Link>
Expand All @@ -88,6 +90,7 @@ export default function Home({ posts }: { posts: CoreContent<Blog>[] }) {
href="/blog"
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label="All posts"
title="All posts"
>
All Posts &rarr;
</Link>
Expand Down
1 change: 1 addition & 0 deletions app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function NotFound() {
<p className="mb-8">But dont worry, you can find plenty of other things on our homepage.</p>
<Link
href="/"
title="Back to homepage"
className="focus:shadow-outline-blue inline rounded-lg border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium leading-5 text-white shadow transition-colors duration-150 hover:bg-blue-700 focus:outline-none dark:hover:bg-blue-500"
>
Back to homepage
Expand Down
5 changes: 3 additions & 2 deletions components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Card = ({ title, description, imgSrc, href }) => (
>
{imgSrc &&
(href ? (
<Link href={href} aria-label={`Link to ${title}`}>
<Link href={href} title={`Link to ${title}`} aria-label={`Link to ${title}`}>
<Image
alt={title}
src={imgSrc}
Expand All @@ -31,7 +31,7 @@ const Card = ({ title, description, imgSrc, href }) => (
<div className="p-6">
<h2 className="mb-3 text-2xl font-bold leading-8 tracking-tight">
{href ? (
<Link href={href} aria-label={`Link to ${title}`}>
<Link href={href} title={title} aria-label={`Link to ${title}`}>
{title}
</Link>
) : (
Expand All @@ -44,6 +44,7 @@ const Card = ({ title, description, imgSrc, href }) => (
href={href}
className="text-base font-medium leading-6 text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Link to ${title}`}
title={`Link to ${title}`}
>
Learn more &rarr;
</Link>
Expand Down
4 changes: 3 additions & 1 deletion components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default function Footer() {
<div>{` • `}</div>
<div>{${new Date().getFullYear()}`}</div>
<div>{` • `}</div>
<Link href="/">{siteMetadata.title}</Link>
<Link href="/" title={siteMetadata.title}>
{siteMetadata.title}
</Link>
</div>
<div className="mb-8 text-sm text-gray-500 dark:text-gray-400">岁月神偷,不忘初心</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Header = () => {
return (
<header className="flex items-center justify-between py-10">
<div>
<Link href="/" aria-label={siteMetadata.headerTitle}>
<Link href="/" aria-label={siteMetadata.headerTitle} title={siteMetadata.headerTitle}>
<div className="flex items-center justify-between">
<div className="mr-3">
<Logo />
Expand All @@ -29,6 +29,7 @@ const Header = () => {
.map((link) => (
<Link
key={link.title}
title={link.title}
href={link.href}
className="hidden font-medium text-gray-900 dark:text-gray-100 sm:block"
>
Expand Down
1 change: 1 addition & 0 deletions components/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const MobileNav = () => {
<div key={link.title} className="px-12 py-4">
<Link
href={link.href}
title={link.title}
className="text-2xl font-bold tracking-widest text-gray-900 dark:text-gray-100"
onClick={onToggleNav}
>
Expand Down
1 change: 1 addition & 0 deletions components/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Tag = ({ text, className }: Props) => {
return (
<Link
href={`/blog/tag/${formatTag(text)}`}
title={text.split(' ').join('-')}
className={`mr-3 text-sm font-medium uppercase text-primary-500 hover:text-primary-600 dark:hover:text-primary-400 ${className}`}
>
{text.split(' ').join('-')}
Expand Down
1 change: 1 addition & 0 deletions components/social-icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const SocialIcon = ({ kind, href, size = 8 }: SocialIconProps) => {
target="_blank"
rel="noopener noreferrer"
href={href}
title={kind}
>
<span className="sr-only">{kind}</span>
<SocialSvg
Expand Down
9 changes: 7 additions & 2 deletions layouts/ListLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function Pagination({ totalPages, currentPage }: PaginationProps) {
{prevPage && (
<Link
href={currentPage - 1 === 1 ? `/${basePath}/` : `/${basePath}/page/${currentPage - 1}`}
title="Previous"
rel="prev"
>
Previous
Expand All @@ -51,7 +52,7 @@ function Pagination({ totalPages, currentPage }: PaginationProps) {
</button>
)}
{nextPage && (
<Link href={`/${basePath}/page/${currentPage + 1}`} rel="next">
<Link href={`/${basePath}/page/${currentPage + 1}`} title="Next" rel="next">
Next
</Link>
)}
Expand Down Expand Up @@ -126,7 +127,11 @@ export default function ListLayout({
<div className="space-y-3 xl:col-span-3">
<div>
<h3 className="text-2xl font-bold leading-8 tracking-tight">
<Link href={`/${path}`} className="text-gray-900 dark:text-gray-100">
<Link
href={`/${path}`}
title={title}
className="text-gray-900 dark:text-gray-100"
>
{title}
</Link>
</h3>
Expand Down
6 changes: 5 additions & 1 deletion layouts/ListLayoutWithTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export default function ListLayoutWithTags({ posts, title, filterTag }: ListLayo
<div className="space-y-3">
<div>
<h2 className="text-2xl font-bold leading-8 tracking-tight">
<Link href={`/${path}`} className="text-gray-900 dark:text-gray-100">
<Link
href={`/${path}`}
title={title}
className="text-gray-900 dark:text-gray-100"
>
{title}
</Link>
</h2>
Expand Down
2 changes: 2 additions & 0 deletions layouts/PostBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function PostMinimal({ content, next, prev, children }: LayoutPro
href={`/${prev.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Previous post: ${prev.title}`}
title={`Previous post: ${prev.title}`}
>
&larr; {prev.title}
</Link>
Expand All @@ -64,6 +65,7 @@ export default function PostMinimal({ content, next, prev, children }: LayoutPro
href={`/${next.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Next post: ${next.title}`}
title={`Next post: ${next.title}`}
>
{next.title} &rarr;
</Link>
Expand Down
15 changes: 11 additions & 4 deletions layouts/PostLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ export default function PostLayout({ content, authorDetails, next, prev, childre
<div className="divide-y divide-gray-200 dark:divide-gray-700 xl:col-span-3 xl:row-span-2 xl:pb-0">
<div className="prose max-w-none pb-8 pt-10 dark:prose-invert">{children}</div>
<div className="pb-6 pt-6 text-sm text-gray-700 dark:text-gray-300">
<Link href={discussUrl(path)} rel="nofollow">
<Link href={discussUrl(path)} title="Discuss on Twitter" rel="nofollow">
Discuss on Twitter
</Link>
{` • `}
<Link href={editUrl(filePath)}>View on GitHub</Link>
<Link href={editUrl(filePath)} title="View on GitHub">
View on GitHub
</Link>
</div>
{siteMetadata.comments && (
<div className="pb-6 pt-6 text-center text-gray-700 dark:text-gray-300" id="comment">
Expand All @@ -117,7 +119,9 @@ export default function PostLayout({ content, authorDetails, next, prev, childre
Previous
</h2>
<div className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400">
<Link href={`/${prev.path}`}>{prev.title}</Link>
<Link href={`/${prev.path}`} title={prev.title}>
{prev.title}
</Link>
</div>
</div>
)}
Expand All @@ -127,7 +131,9 @@ export default function PostLayout({ content, authorDetails, next, prev, childre
Next
</h2>
<div className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400">
<Link href={`/${next.path}`}>{next.title}</Link>
<Link href={`/${next.path}`} title={next.title}>
{next.title}
</Link>
</div>
</div>
)}
Expand All @@ -139,6 +145,7 @@ export default function PostLayout({ content, authorDetails, next, prev, childre
href={`/${basePath}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label="Back to the blog"
title="Back to the blog"
>
&larr; Back to the blog
</Link>
Expand Down
2 changes: 2 additions & 0 deletions layouts/PostSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function PostLayout({ content, next, prev, children }: LayoutProp
href={`/${prev.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Previous post: ${prev.title}`}
title={`Previous post: ${prev.title}`}
>
&larr; {prev.title}
</Link>
Expand All @@ -67,6 +68,7 @@ export default function PostLayout({ content, next, prev, children }: LayoutProp
href={`/${next.path}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Next post: ${next.title}`}
title={`Next post: ${next.title}`}
>
{next.title} &rarr;
</Link>
Expand Down

0 comments on commit 6f3f131

Please sign in to comment.