fix: 修复代码主题build后样式混乱的bug

This commit is contained in:
vita2333 2020-07-06 20:54:24 +08:00
parent c8ee569671
commit d480e0158b
5 changed files with 19 additions and 38 deletions

View File

@ -1,9 +1,25 @@
import postMixin from '@theme/mixins/posts'
import localMixin from '@theme/mixins/locales'
function _registerCodeThemeCss (theme = 'tomorrow') {
const link = document.createElement('link')
link.rel = 'stylesheet'
if (theme === '') {
link.href = `http://prismjs.com/themes/prism.css`
} else {
link.href = `http://prismjs.com/themes/prism-${theme}.css`
}
document.head.append(link)
}
export default ({
Vue
Vue,
siteData,
isServer
}) => {
Vue.mixin(postMixin)
Vue.mixin(localMixin)
if (!isServer) {
_registerCodeThemeCss(siteData.themeConfig.codeTheme)
}
}

View File

@ -45,10 +45,9 @@ import pagination from '@theme/mixins/pagination'
import { sortPostsByStickyAndDate, filterPosts } from '@theme/helpers/postData'
import { getOneColor } from '@theme/helpers/other'
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
import codeTheme from '@theme/mixins/codeTheme'
export default {
mixins: [pagination, moduleTransitonMixin, codeTheme],
mixins: [pagination, moduleTransitonMixin],
components: { Common, NoteAbstract, ModuleTransition },
data () {

View File

@ -13,11 +13,9 @@ import Page from '@theme/components/Page'
import Footer from '@theme/components/Footer'
import Common from '@theme/components/Common'
import { resolveSidebarItems } from '@theme/helpers/utils'
import codeTheme from '@theme/mixins/codeTheme'
export default {
components: { HomeBlog, Home, Page, Common, Footer },
mixins: [codeTheme],
computed: {
sidebarItems () {
return resolveSidebarItems(

View File

@ -39,10 +39,9 @@ import pagination from '@theme/mixins/pagination'
import ModuleTransition from '@theme/components/ModuleTransition'
import { sortPostsByStickyAndDate, filterPosts } from '@theme/helpers/postData'
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
import codeTheme from '@theme/mixins/codeTheme'
export default {
mixins: [pagination, moduleTransitonMixin, codeTheme],
mixins: [pagination, moduleTransitonMixin],
components: { Common, NoteAbstract, TagList, ModuleTransition },
data () {

View File

@ -1,31 +0,0 @@
export default {
created () {
const { codeTheme = 'tomorrow' } = this.$themeConfig
switch (codeTheme) {
case 'coy':
import('prismjs/themes/prism-coy.css')
break
case 'dark':
import('prismjs/themes/prism-dark.css')
break
case 'funky':
import('prismjs/themes/prism-funky.css')
break
case 'okaidia':
import('prismjs/themes/prism-okaidia.css')
break
case 'solarizedlight':
import('prismjs/themes/prism-solarizedlight.css')
break
case 'tomorrow':
import('prismjs/themes/prism-tomorrow.css')
break
case 'twilight':
import('prismjs/themes/prism-twilight.css')
break
default:
import('prismjs/themes/prism.css')
break
}
}
}