mirror of
https://github.com/sendevia/website.git
synced 2026-03-08 00:32:34 +08:00
feat(layout): implement dynamic layout component system
This commit is contained in:
@@ -7,7 +7,7 @@ import Footer from "../components/Footer.vue";
|
|||||||
import Sidebar from "../components/Sidebar.vue";
|
import Sidebar from "../components/Sidebar.vue";
|
||||||
import { argbFromHex } from "@material/material-color-utilities";
|
import { argbFromHex } from "@material/material-color-utilities";
|
||||||
import { generateColorPalette } from "../utils/colorPalette";
|
import { generateColorPalette } from "../utils/colorPalette";
|
||||||
import { onMounted, nextTick } from "vue";
|
import { onMounted, nextTick, computed } from "vue";
|
||||||
import { useRoute } from "vitepress";
|
import { useRoute } from "vitepress";
|
||||||
import { useGlobalData } from "../composables/useGlobalData";
|
import { useGlobalData } from "../composables/useGlobalData";
|
||||||
|
|
||||||
@@ -70,6 +70,21 @@ async function updatePalette() {
|
|||||||
await generateColorPalette(argb ?? argbFromHex(defaultColor));
|
await generateColorPalette(argb ?? argbFromHex(defaultColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const layoutMap = {
|
||||||
|
article: ArticleLayout,
|
||||||
|
posts: AllPostsLayout,
|
||||||
|
search: SearchPostsLayout,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type LayoutKey = keyof typeof layoutMap;
|
||||||
|
|
||||||
|
const currentLayout = computed(() => {
|
||||||
|
if (frontmatter.value.home) return null;
|
||||||
|
if (page.value.isNotFound) return NotFoundLayout;
|
||||||
|
const key = (frontmatter.value.layout ?? "article") as LayoutKey;
|
||||||
|
return layoutMap[key] ?? ArticleLayout;
|
||||||
|
});
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
onMounted(updatePalette);
|
onMounted(updatePalette);
|
||||||
@@ -92,10 +107,7 @@ function onAfterEnter() {
|
|||||||
<p>{{ site.description }}</p>
|
<p>{{ site.description }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<AllPostsLayout v-else-if="frontmatter.layout === 'posts'" />
|
<component v-else :is="currentLayout" />
|
||||||
<SearchPostsLayout v-else-if="frontmatter.layout === 'search'" />
|
|
||||||
<NotFoundLayout v-else-if="page.isNotFound" />
|
|
||||||
<ArticleLayout v-else />
|
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
Reference in New Issue
Block a user