Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addon-bangumi): customCss not work #441

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/yun/valaxy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default defineValaxyConfig<ThemeConfig>({
api: 'https://yi_xiao_jiu-bangumi.web.val.run',
bilibiliUid: '1579790',
bgmEnabled: false,
customCss: '.bbc-bangumi-title a { color: red; }',
}),
addonComponents(),

Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy-addon-bangumi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

关联 issue [[功能建议] 追番列表](https://github.com/YunYouJun/valaxy/issues/296)

依赖 [bilibili-bangumi-component](https://github.com/yixiaojiu/bilibili-bangumi-component),需要部署后端服务,可参考 [bilibili-bangumi 使用](https://github.com/yixiaojiu/bilibili-bangumi-component?tab=readme-ov-file#%E4%BD%BF%E7%94%A8)进行搭建
依赖 [bilibili-bangumi-component](https://github.com/yixiaojiu/bilibili-bangumi-component),需要部署后端服务,可参考 [bilibili-bangumi 使用](https://github.com/yixiaojiu/bilibili-bangumi-component/blob/main/docs/backend.md)进行搭建,也可以先用这个 `https://yi_xiao_jiu-bangumi.web.val.run`,可能会挂。

## 如何集成

Expand Down
31 changes: 21 additions & 10 deletions packages/valaxy-addon-bangumi/components/ValaxyBangumi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@ import { onMounted, ref } from 'vue'
import { isClient } from '@vueuse/core'
import { useAddonBangumi } from '../client'

(async () => {
if (!isClient)
return
const { defineCustomElements } = await import('bilibili-bangumi-component/loader')
defineCustomElements()
})()

const bangumiRef = ref<HTMLElement>()
const customCssInjected = ref(false)

const bangumiOptions = useAddonBangumi()

const { api, bgmEnabled, bgmUid, bilibiliEnabled, bilibiliUid, customCss, customEnabled, customLabel, pageSize } = bangumiOptions.value

onMounted(() => {
if (!customCss)
function injectCustomCss() {
if (!customCss || customCssInjected.value)
return

const sheet = new CSSStyleSheet()
sheet.replaceSync(customCss)
bangumiRef.value?.shadowRoot?.adoptedStyleSheets.push(sheet)
})

if (bangumiRef.value?.shadowRoot)
customCssInjected.value = true
}

;(async () => {
if (!isClient)
return
const { defineCustomElements } = await import('bilibili-bangumi-component/loader')
defineCustomElements()

// Web Component may not define when vue component mount
injectCustomCss()
})()

onMounted(() =>
injectCustomCss(),
)
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions packages/valaxy-addon-bangumi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "valaxy-addon-bangumi",
"type": "module",
"version": "0.2.0",
"version": "0.2.1",
"description": "Bangumi addon for Valaxy",
"repository": {
"type": "git",
Expand All @@ -18,6 +18,6 @@
"valaxy": "latest"
},
"dependencies": {
"bilibili-bangumi-component": "^0.3.0"
"bilibili-bangumi-component": "^0.3.1"
}
}
19 changes: 14 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading