Merge pull request #212 from vita2333/develop

fix: 修复代码主题build后样式混乱的bug
This commit is contained in:
reco_luan 2020-07-07 00:16:36 +08:00 committed by GitHub
commit 2ab65ff0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 38 deletions

View File

@ -2,8 +2,23 @@ import postMixin from '@theme/mixins/posts'
import localMixin from '@theme/mixins/locales'
export default ({
Vue
Vue,
siteData,
isServer
}) => {
Vue.mixin(postMixin)
Vue.mixin(localMixin)
if (!isServer) {
_registerCodeThemeCss(siteData.themeConfig.codeTheme)
}
}
function _registerCodeThemeCss (theme = 'tomorrow') {
const themeArr = ['tomorrow', 'funky', 'okaidia', 'solarizedlight', 'default']
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = `//prismjs.com/themes/prism${themeArr.indexOf(theme) > -1 ? `-${theme}` : ''}.css`
document.head.append(link)
}

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
}
}
}