Skip to content

Commit

Permalink
feat: expose $slidev.configs and $slidev.themeConfigs context
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 30, 2021
1 parent 50e45e2 commit edb674a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions demo/composable-vue/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ layout: center
</a>
</div>

---

{{ $slidev.configs }}


---
layout: center
Expand Down
13 changes: 10 additions & 3 deletions packages/client/modules/context.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { App, reactive } from 'vue'
import { App, computed, reactive, readonly } from 'vue'
import { objectKeys } from '@antfu/utils'
import type { UnwrapNestedRefs } from '@vue/reactivity'
import * as nav from '../logic/nav'
import { isDark } from '../logic/dark'
import { configs } from '../env'

declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$slidev: { nav: UnwrapNestedRefs<typeof nav> }
$slidev: {
nav: UnwrapNestedRefs<typeof nav>
configs: typeof configs
themeConfigs: typeof configs['themeConfig']
}
}
}

Expand All @@ -22,8 +27,10 @@ export default function createSlidevContext() {
}
const context = reactive({
nav: navObj,
configs,
themeConfigs: computed(() => configs.themeConfig),
})
app.config.globalProperties.$slidev = context
app.config.globalProperties.$slidev = readonly(context)

// allows controls from postMessages
if (__DEV__) {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import YAML from 'js-yaml'
import { isObject, isTruthy, objectMap, objectPick } from '@antfu/utils'
import { isObject, isTruthy, objectMap } from '@antfu/utils'
import { SlideInfo, SlideInfoBase, SlidevConfig, SlidevFeatureFlags, SlidevMarkdown } from '@slidev/types'
import { parseAspectRatio } from './utils'

Expand Down Expand Up @@ -154,7 +154,7 @@ export function parse(
const config: SlidevConfig = Object.assign(
defaultConfig,
headmatter.config || {},
objectPick(headmatter, Object.keys(defaultConfig)),
headmatter,
)
if (config.colorSchema !== 'dark' && config.colorSchema !== 'light')
config.colorSchema = 'auto'
Expand Down

0 comments on commit edb674a

Please sign in to comment.