Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
nextraConfig.unstable_readingTime
option for blog theme (#684)
- Loading branch information
1 parent
71528f1
commit 64ae4b5
Showing
11 changed files
with
156 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'nextra': patch | ||
'nextra-theme-blog': patch | ||
--- | ||
|
||
add `nextraConfig.unstable_readingTime` option for blog theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,72 @@ | ||
import React, { ReactElement } from 'react' | ||
import Link from 'next/link' | ||
import ThemeSwitch from './theme-switch' | ||
import type { NextraBlogTheme } from './types' | ||
import { split } from './utils/get-tags' | ||
import { useBlogContext } from './blog-context' | ||
import { getParent } from './utils/parent' | ||
|
||
interface MetaProps { | ||
author?: string | ||
date?: string | ||
tag?: string | string[] | ||
back?: string | null | ||
config: NextraBlogTheme | ||
} | ||
|
||
export default function Meta({ | ||
author, | ||
date, | ||
tag, | ||
back, | ||
config | ||
}: MetaProps): ReactElement { | ||
export default function Meta(): ReactElement { | ||
const { opts, config } = useBlogContext() | ||
const { author, date, tag } = opts.frontMatter | ||
const { back } = getParent({ opts, config }) | ||
const tags = tag ? split(tag) : [] | ||
|
||
const tagsEl = tags.map(t => ( | ||
<Link key={t} href="/tags/[tag]" as={`/tags/${t}`}> | ||
<a | ||
className=" | ||
select-none | ||
rounded-md | ||
px-1 | ||
transition-colors | ||
text-sm | ||
text-gray-400 | ||
hover:text-gray-500 | ||
dark:text-gray-300 | ||
dark:hover:text-gray-200 | ||
bg-gray-200 | ||
hover:bg-gray-300 | ||
dark:bg-gray-600 | ||
dark:hover:bg-gray-700 | ||
" | ||
> | ||
{t} | ||
</a> | ||
</Link> | ||
)) | ||
|
||
const readingTime = opts.readingTime?.text | ||
|
||
return ( | ||
<div className="mb-8 flex items-center gap-3"> | ||
<div className="flex flex-1 flex-wrap items-center gap-1 text-gray-400 not-prose"> | ||
{author} | ||
{author && date && ','} | ||
{date && ( | ||
<time dateTime={new Date(date).toISOString()}> | ||
{new Date(date).toDateString()} | ||
</time> | ||
<div | ||
className={ | ||
'mb-8 flex gap-3 ' + (readingTime ? 'items-start' : 'items-center') | ||
} | ||
> | ||
<div className="grow text-gray-400"> | ||
<div className="flex flex-wrap items-center gap-1 not-prose"> | ||
{author} | ||
{author && date && ','} | ||
{date && ( | ||
<time dateTime={new Date(date).toISOString()}> | ||
{new Date(date).toDateString()} | ||
</time> | ||
)} | ||
{(author || date) && tags.length > 0 && ' • '} | ||
{readingTime || tagsEl} | ||
</div> | ||
{readingTime && ( | ||
<div className="flex flex-wrap items-center gap-1 mt-1 not-prose">{tagsEl}</div> | ||
)} | ||
{(author || date) && tags.length > 0 && '•'} | ||
{tags.map(t => ( | ||
<Link key={t} href="/tags/[tag]" as={`/tags/${t}`}> | ||
<a | ||
className=" | ||
select-none | ||
rounded-md | ||
px-1 | ||
transition-colors | ||
text-sm | ||
text-gray-400 | ||
hover:text-gray-500 | ||
dark:text-gray-300 | ||
dark:hover:text-gray-200 | ||
bg-gray-200 | ||
hover:bg-gray-300 | ||
dark:bg-gray-600 | ||
dark:hover:bg-gray-700 | ||
" | ||
> | ||
{t} | ||
</a> | ||
</div> | ||
<div className="flex items-center gap-3"> | ||
{back && ( | ||
<Link href={back} passHref> | ||
<a>Back</a> | ||
</Link> | ||
))} | ||
)} | ||
{config.darkMode && <ThemeSwitch />} | ||
</div> | ||
{back && ( | ||
<Link href={back} passHref> | ||
<a>Back</a> | ||
</Link> | ||
)} | ||
{config.darkMode && <ThemeSwitch />} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.