Skip to content
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
38 changes: 37 additions & 1 deletion packages/nextra-theme/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export {
}

export default function NextraLayout({ children, pageOpts, pageProps }: NextraThemeLayoutProps): ReactElement {
const { frontMatter, filePath, pageMap, headings, title } = pageOpts
const { frontMatter, filePath, pageMap, headings, title, timestamp, readingTime } = pageOpts
const { locale, defaultLocale } = useI18n<any>()
const fsPath = useFSRoute()

Expand Down Expand Up @@ -156,6 +156,8 @@ export default function NextraLayout({ children, pageOpts, pageProps }: NextraTh
seo = merge(seo, frontMatter.seo)
}

const lastUpdated = timestamp ? new Date(timestamp) : null

return (
<NavContext.Provider value={{ filePath: pageProps.remoteFilePath || filePath, ...args }}>
<DocumentContext.Provider value={{ frontMatter, headings, markOutlineItem, highlightedOutlineItemId }}>
Expand Down Expand Up @@ -190,6 +192,40 @@ export default function NextraLayout({ children, pageOpts, pageProps }: NextraTh
</div>
) : null}
{frontMatter.title ? <Heading.H1>{frontMatter.title}</Heading.H1> : null}
{lastUpdated || readingTime ? (
<Paragraph size="14px">
{lastUpdated ? (
<span>
<span sx={{ color: 'White64' }}>Last updated:</span>{' '}
<time dateTime={lastUpdated.toISOString()}>
{lastUpdated.toLocaleDateString(locale, {
month: 'long',
day: 'numeric',
year: 'numeric',
})}
</time>
</span>
) : null}
<span
sx={{
mx: Spacing['16px'],
display: 'inline-block',
verticalAlign: 'top',
width: '1px',
height: '20px',
bg: 'White16',
'&:not(span + span), &:not(:has(+ span))': {
display: 'none',
},
}}
/>
{(readingTime?.minutes ?? 0) > 0 ? (
<span>
<span sx={{ color: 'White64' }}>Reading time:</span> {Math.ceil(readingTime!.minutes)} min
</span>
) : null}
</Paragraph>
) : null}
<MDXProvider components={mdxComponents}>{children}</MDXProvider>
</article>

Expand Down
1 change: 1 addition & 0 deletions website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const withNextra = nextra({
flexsearch: false,
codeHighlight: false,
defaultShowCopyCode: false,
readingTime: true,
transform(result, { route }) {
if (route && !result.includes('getStaticProps')) {
const banner = `
Expand Down