docs: add ValaxyMain desc for theme, close #69

This commit is contained in:
YunYouJun 2022-10-03 02:34:15 +08:00
parent 7fb9cf456c
commit 72f5d7a1e9
10 changed files with 87 additions and 19 deletions

View File

@ -0,0 +1,22 @@
---
title: Components
title_zh: 组件
categories:
- Guide
end: false
---
Valaxy 内置了几个简单的组件。
你可以在写文章或者创作主题时直接使用。
## 基础组件
> 面向主题开发者,你通常不需要直接使用
- `ValaxyMain`: 页面基础布局
- `ValaxyMd`: Markdown 渲染内容
## 辅助组件
> 面向用户,可直接使用

View File

@ -55,9 +55,37 @@ export interface ValaxyConfig {
} }
``` ```
## ValaxyMain ## 开始编写
你可以从 `ValaxyMain``props` 中获取 `frontmatter``pageData` ### ValaxyMain
你需要自定义一个 `ValaxyMain` 组件来决定主题的文章渲染部分。
> 你可以从 `ValaxyMain``props` 中获取 `frontmatter``pageData`
```vue
<script lang="ts" setup>
import type { PageData, Post } from 'valaxy'
defineProps<{
frontmatter: Post
data?: PageData
}>()
</script>
<template>
<main>
<slot name="main-content">
<ValaxyMd :frontmatter="frontmatter">
<slot name="main-content-md" />
<slot />
</ValaxyMd>
</slot>
</main>
</template>
```
> 示例可参考 [ValaxyMain.vue | valaxy-theme-yun](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy-theme-yun/components/ValaxyMain.vue)
## 样式 ## 样式

View File

@ -3,6 +3,7 @@ title: Use Theme
title_zh: 使用主题 title_zh: 使用主题
categories: categories:
- Theme - Theme
top: 100
--- ---
## 安装主题 ## 安装主题

View File

@ -23,10 +23,10 @@ const isHome = useLayout('home')
<div <div
w="full" flex="~" :class="{ w="full" flex="~" :class="{
'px-6 md:px-8': hasSidebar, 'px-6 md:px-8': hasSidebar,
}" p="t-8" }" p="t-6"
> >
<slot name="main"> <slot name="main">
<div class="content" m="auto y-0" flex="~ col grow" w="full" p="x-12 lt-md:0"> <div class="content" m="y-0" flex="~ col grow" w="full" p="x-12 lt-md:0">
<slot name="main-header" /> <slot name="main-header" />
<slot name="main-header-after" /> <slot name="main-header-after" />

View File

@ -2,17 +2,24 @@
import { capitalize, computed } from 'vue' import { capitalize, computed } from 'vue'
import { useConfig } from 'valaxy' import { useConfig } from 'valaxy'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import pkg from 'valaxy/package.json'
import { useThemeConfig } from '../composables' import { useThemeConfig } from '../composables'
const { t } = useI18n()
const config = useConfig() const config = useConfig()
const themeConfig = useThemeConfig() const themeConfig = useThemeConfig()
const year = new Date().getFullYear() const year = new Date().getFullYear()
const isThisYear = computed(() => { const isThisYear = computed(() => {
return year === themeConfig.value.footer.since return year === themeConfig.value.footer.since
}) })
const { t } = useI18n() const poweredHtml = computed(() => t('footer.powered', [`<a href="${pkg.repository}" target="_blank" rel="noopener">Valaxy</a> v${pkg.version}`]))
const poweredHtml = computed(() => t('footer.powered', [`<a href="${config.value.pkg.repository}" target="_blank" rel="noopener">Valaxy</a> v${config.value.pkg.version}`])) const footerIcon = computed(() => themeConfig.value.footer.icon || {
const footerIcon = computed(() => themeConfig.value.footer.icon || { url: config.value.pkg.repository, name: config.value.pkg.name }) url: pkg.repository,
name: 'i-ri-cloud-line',
title: pkg.name,
})
</script> </script>
<template> <template>

View File

@ -0,0 +1,19 @@
<script lang="ts" setup>
import type { PageData, Post } from '../../types'
defineProps<{
frontmatter: Post
data?: PageData
}>()
</script>
<template>
<main>
<slot name="main-content">
<ValaxyMd :frontmatter="frontmatter">
<slot name="main-content-md" />
<slot />
</ValaxyMd>
</slot>
</main>
</template>

View File

@ -33,12 +33,12 @@ export const valaxyContextRef = shallowRef<ValaxyContext>(parse<ValaxyContext>(v
if (import.meta.hot) { if (import.meta.hot) {
// /@valaxyjs/site must be static string // /@valaxyjs/site must be static string
import.meta.hot.accept('/@valaxyjs/site', (m) => { import.meta.hot.accept('/@valaxyjs/site', (m) => {
valaxySiteConfigRef.value = parse<ValaxySiteConfig>(m.default) valaxySiteConfigRef.value = parse<ValaxySiteConfig>(m?.default)
}) })
// context // context
import.meta.hot.accept('/@valaxyjs/context', (m) => { import.meta.hot.accept('/@valaxyjs/context', (m) => {
valaxyContextRef.value = parse<ValaxyContext>(m.default) valaxyContextRef.value = parse<ValaxyContext>(m?.default)
}) })
} }

View File

@ -1,7 +1,6 @@
import type { VitePluginConfig as UnoCssConfig } from 'unocss/vite' import type { VitePluginConfig as UnoCssConfig } from 'unocss/vite'
import type { Awaitable } from '@antfu/utils' import type { Awaitable } from '@antfu/utils'
import type { DefaultThemeConfig, SiteConfig, UserSiteConfig } from '../types' import type { DefaultThemeConfig, SiteConfig, UserSiteConfig } from '../types'
import pkg from '../package.json'
import type { ResolvedValaxyOptions } from './options' import type { ResolvedValaxyOptions } from './options'
import type { UserConfig, ValaxyAddonResolver, ValaxyConfig } from './types' import type { UserConfig, ValaxyAddonResolver, ValaxyConfig } from './types'
@ -44,7 +43,6 @@ export function defineAddon(
} }
export const defaultSiteConfig: SiteConfig = { export const defaultSiteConfig: SiteConfig = {
pkg,
mode: 'auto', mode: 'auto',
url: '/', url: '/',
lang: 'en', lang: 'en',

View File

@ -5,11 +5,10 @@ import type Pages from 'vite-plugin-pages'
import type { UserConfig as ViteUserConfig } from 'vite' import type { UserConfig as ViteUserConfig } from 'vite'
import type { presetAttributify, presetIcons, presetTypography, presetUno } from 'unocss' import type { presetAttributify, presetIcons, presetTypography, presetUno } from 'unocss'
import type { DefaultThemeConfig, UserSiteConfig } from '../types' import type { DefaultThemeConfig, UserSiteConfig } from '../types'
import type ValaxyPackage from '../package.json'
import type { ResolvedValaxyOptions } from './options' import type { ResolvedValaxyOptions } from './options'
import type { MarkdownOptions } from './markdown' import type { MarkdownOptions } from './markdown'
export type ValaxyConfig<ThemeConfig = DefaultThemeConfig> = UserSiteConfig<ThemeConfig> & ValaxyExtendConfig & { pkg: typeof ValaxyPackage } export type ValaxyConfig<ThemeConfig = DefaultThemeConfig> = UserSiteConfig<ThemeConfig> & ValaxyExtendConfig
export type UserConfig<ThemeConfig = DefaultThemeConfig> = ValaxyConfig<ThemeConfig> export type UserConfig<ThemeConfig = DefaultThemeConfig> = ValaxyConfig<ThemeConfig>
/** /**
* fn with options for theme config * fn with options for theme config

View File

@ -1,5 +1,3 @@
import type ValaxyPackage from '../package.json'
export type DefaultThemeConfig = Record<string, any> export type DefaultThemeConfig = Record<string, any>
export interface SocialLink { export interface SocialLink {
@ -29,10 +27,6 @@ export interface AlgoliaSearchOptions {
// shared with valaxy node and client // shared with valaxy node and client
export interface SiteConfig<T = DefaultThemeConfig> { export interface SiteConfig<T = DefaultThemeConfig> {
/**
* valaxy package.json
*/
pkg: typeof ValaxyPackage
/** /**
* enable auto (light/dark mode) * enable auto (light/dark mode)
* @default 'auto' * @default 'auto'