Skip to content

Commit

Permalink
fix: composables re-exporting breaks vite
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCampionJr committed Apr 22, 2023
1 parent 7982554 commit c35192e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/theme/composables/authors.data.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createContentLoader } from 'vitepress'
import { type SiteConfig, createContentLoader } from 'vitepress'
import type { VPBThemeConfig } from '..'

const config = globalThis.VITEPRESS_CONFIG
// @ts-expect-error globalThis is not typed
const config = globalThis.VITEPRESS_CONFIG as SiteConfig<VPBThemeConfig>
const blogConfig = config.site.themeConfig.blog

const pattern = `${blogConfig?.authorsPath ?? '/blog/authors'}/**/*.md`
Expand Down
4 changes: 0 additions & 4 deletions src/theme/composables/posts.data.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createContentLoader } from 'vitepress'
import { formatDistance } from 'date-fns'

const config = globalThis.VITEPRESS_CONFIG
// @ts-expect-error globalThis is not typed
const config = globalThis.VITEPRESS_CONFIG as SiteConfig<VPBThemeConfig>
const blogConfig = config.site.themeConfig.blog

const pattern = `${blogConfig?.postsPath ?? '/blog/posts'}/**/*.md`
Expand All @@ -24,7 +25,7 @@ export default createContentLoader(pattern, {
},
})

function formatDate(raw) {
function formatDate(raw: string) {
const date = new Date(raw)
date.setUTCHours(12)
return {
Expand All @@ -39,7 +40,7 @@ function formatDate(raw) {
}
}

function formatTags(raw) {
function formatTags(raw: string | string[]) {
if (typeof raw === 'string') {
if (raw.includes(',')) {
return raw.split(',').map((value) => value.trim())
Expand Down
14 changes: 10 additions & 4 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import type { Awaitable } from 'vitepress'
import type { EnhanceAppContext, Theme } from 'vitepress/client'
import DefaultTheme from 'vitepress/theme'
import './style.css'
import { useArchives } from './composables/useArchives'
import { useAuthors } from './composables/useAuthors'
import { usePosts } from './composables/usePosts'
import { useTags } from './composables/useTags'

import VPBHome from './components/VPBHome.vue'
import VPBLayout from './components/VPBLayout.vue'
Expand Down Expand Up @@ -33,10 +37,12 @@ export { default as VPBTags } from './components/VPBTags.vue'
export { default as VPBTestComponent } from './components/VPBTestComponent.vue'

// composables
export { useArchives } from './composables/useArchives'
export { useAuthors } from './composables/useAuthors'
export { usePosts } from './composables/usePosts'
export { useTags } from './composables/useTags'
// using these outside the package will break Vite/VitePress
// https://github.com/vuejs/vitepress/issues/2242
export { useArchives }
export { useAuthors }
export { usePosts }
export { useTags }

interface VPBTheme {
Layout: Component
Expand Down

0 comments on commit c35192e

Please sign in to comment.