diff --git a/themes/example/components/Header.js b/themes/example/components/Header.js index 5331eed2..ca60bf63 100644 --- a/themes/example/components/Header.js +++ b/themes/example/components/Header.js @@ -4,12 +4,13 @@ import { MenuList } from './MenuList' /** * 网站顶部 + * LOGO 和 菜单 * @returns */ export const Header = props => { return (
-
+
diff --git a/themes/example/components/MenuList.js b/themes/example/components/MenuList.js index 90b00c7e..ef0c122a 100644 --- a/themes/example/components/MenuList.js +++ b/themes/example/components/MenuList.js @@ -58,7 +58,7 @@ export const MenuList = props => { return (
+ ) } diff --git a/themes/example/components/TitleBar.js b/themes/example/components/TitleBar.js new file mode 100644 index 00000000..add6901a --- /dev/null +++ b/themes/example/components/TitleBar.js @@ -0,0 +1,48 @@ +import NotionIcon from '@/components/NotionIcon' +import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import CONFIG from '../config' + +/** + * 标题栏 + */ +export default function TitleBar(props) { + const { post } = props + const { fullWidth, siteInfo } = useGlobal() + + const title = post?.title || siteConfig('TITLE') + const description = post?.description || siteConfig('AUTHOR') + const headerImage = post?.pageCoverThumbnail + ? post.pageCoverThumbnail + : siteInfo?.pageCover + + const TITLE_BG = siteConfig('EXAMPLE_TITLE_IMAGE', false, CONFIG) + + return ( + <> + {/* 标题栏 */} + {!fullWidth && ( +
+

+ {siteConfig('POST_TITLE_ICON') && ( + + )} + {title} +

+

+ {description} +

+ {TITLE_BG && ( + <> + {/* eslint-disable-next-line @next/next/no-img-element */} + + + )} +
+ )} + + ) +} diff --git a/themes/example/config.js b/themes/example/config.js index 181d3a93..b1c0af1f 100644 --- a/themes/example/config.js +++ b/themes/example/config.js @@ -8,7 +8,12 @@ const CONFIG = { EXAMPLE_MENU_ARCHIVE: true, // 显示归档 EXAMPLE_MENU_SEARCH: true, // 显示搜索 - EXAMPLE_POST_LIST_COVER: true // 列表显示文章封面 + EXAMPLE_POST_LIST_COVER: true, // 列表显示文章封面 + EXAMPLE_TITLE_IMAGE: false, // 标题栏,是否背景图片 + + // 文章页面布局 + EXAMPLE_ARTICLE_LAYOUT_VERTICAL: false, // 文章详情,左右布局改为上下布局 + EXAMPLE_ARTICLE_HIDDEN_NOTIFICATION: false // 文章详情隐藏公告 } export default CONFIG diff --git a/themes/example/index.js b/themes/example/index.js index b1893935..90580a24 100644 --- a/themes/example/index.js +++ b/themes/example/index.js @@ -2,7 +2,6 @@ import Comment from '@/components/Comment' import replaceSearchResult from '@/components/Mark' -import NotionIcon from '@/components/NotionIcon' import NotionPage from '@/components/NotionPage' import ShareBar from '@/components/ShareBar' import { siteConfig } from '@/lib/config' @@ -21,6 +20,7 @@ import { PostLock } from './components/PostLock' import { PostMeta } from './components/PostMeta' import SearchInput from './components/SearchInput' import { SideBar } from './components/SideBar' +import TitleBar from './components/TitleBar' import CONFIG from './config' import { Style } from './style' @@ -32,36 +32,15 @@ import { Style } from './style' * @constructor */ const LayoutBase = props => { - const { children } = props + const { children, post } = props const { onLoading, fullWidth, locale } = useGlobal() - const router = useRouter() - const { post, category, tag } = props - const title = post?.title || siteConfig('TITLE') - const description = post?.description || siteConfig('AUTHOR') + // 文章详情页左右布局改为上下布局 + const LAYOUT_VERTICAL = + post && siteConfig('EXAMPLE_ARTICLE_LAYOUT_VERTICAL', false, CONFIG) - // 顶部如果是按照分类或标签查看文章列表,列表顶部嵌入一个横幅 - // 如果是搜索,则列表顶部嵌入 搜索框 - let slotTop = null - if (category) { - slotTop = ( -
- - {category} -
- ) - } else if (tag) { - slotTop =
#{tag}
- } else if (props.slotTop) { - slotTop = props.slotTop - } else if (router.route === '/search') { - // 嵌入一个搜索框在顶部 - slotTop = ( -
- -
- ) - } + // 网站左右布局颠倒 + const LAYOUT_SIDEBAR_REVERSE = siteConfig('LAYOUT_SIDEBAR_REVERSE', false) return (
{ {/* 页头 */}
+ {/* 标题栏 */} + {/* 主体 */}
- {/* 标题栏 */} - {!fullWidth && ( -
-

- {siteConfig('POST_TITLE_ICON') && ( - - )} - {title} -

-

{description}

-
- )} -
+ className={`relative mx-auto justify-center md:flex py-8 px-2 + ${LAYOUT_SIDEBAR_REVERSE ? 'flex-row-reverse' : ''} + ${LAYOUT_VERTICAL ? 'items-center flex-col' : 'items-start'} + `}> {/* 内容 */}
+ className={`${fullWidth ? '' : LAYOUT_VERTICAL ? 'max-w-5xl' : 'max-w-3xl'} w-full xl:px-14 lg:px-4`}> { leaveTo='opacity-0 -translate-y-16' unmount={false}> {/* 嵌入模块 */} - {slotTop} + {props.slotTop} {children}
{/* 侧边栏 */} - {!fullWidth && } + {!fullWidth && ( +
+ +
+ )}
@@ -150,8 +125,20 @@ const LayoutIndex = props => { * @returns */ const LayoutPostList = props => { + const { category, tag } = props + return ( <> + {/* 显示分类 */} + {category && ( +
+ + {category} +
+ )} + {/* 显示标签 */} + {tag &&
#{tag}
} + {siteConfig('POST_LIST_STYLE') === 'page' ? ( ) : ( @@ -192,7 +179,7 @@ const LayoutSlug = props => { {lock ? ( ) : ( -
+
@@ -237,7 +224,14 @@ const LayoutSearch = props => { } }, [router]) - return + return ( + <> +
+ +
+ + + ) } /**